-
-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 994 malformed hostnames #1004
Conversation
20fdec2
to
41167a9
Compare
Pull Request Test Coverage Report for Build 1919ce1dbDetails
💛 - Coveralls |
41167a9
to
55fa52d
Compare
55fa52d
to
e38590a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you for all the cleanup. It is good to get some of the magic values into constants.
I took some time to test this out and seems to function as advertised. Look forward to it's commit bit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. some nice cleanup. 👍
cmd/tegola_lambda/main.go
Outdated
@@ -91,7 +91,12 @@ func init() { | |||
// set our server version | |||
server.Version = build.Version | |||
if conf.Webserver.HostName != "" { | |||
server.HostName = string(conf.Webserver.HostName) | |||
hostname, err := url.Parse(string(conf.Webserver.HostName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is redundant. If you validate the hostname in config.validate()
already it will throw early.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iwpnd you're right it is redundant. I just went back and looked at the code to determine why I did it this way and I think I'm hitting a weird issue that could probably be solved more elegantly:
- The
config
package has aValidateAndRegisterParams
routine which calls theurl.Parse()
method on the Hostname and throws an error if the Parse fails. It does not set the value ofWebserver.Hostname
, which is of typeenv.String
.
Lines 337 to 345 in e38590a
if string(c.Webserver.HostName) != "" { | |
_, err := url.Parse(string(c.Webserver.HostName)) | |
if err != nil { | |
return ErrInvalidHostName{ | |
HostName: string(c.Webserver.HostName), | |
Err: err, | |
} | |
} | |
} |
- The
server.Hostname
value is now of typeurl.URL
and sinceconfig.Webserver.Hostname
is of typeenv.String
we need to parse again.
I think I opted for the double Parse approach as this code path only gets hit during start up. A more elegant way to solve this would be to add a new type to the internal/env
package called URL
. This should be pretty straight forward to do so I will give it a shot.
Good call out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iwpnd I added a new commit addressing this comment. LMK what you think.
cmd/tegola/cmd/server.go
Outdated
@@ -38,9 +39,17 @@ var serverCmd = &cobra.Command{ | |||
serverPort = string(conf.Webserver.Port) | |||
} | |||
|
|||
if conf.Webserver.HostName != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this would have been caught in config.validate()
already, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iwpnd I added a new commit addressing this comment. LMK what you think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Added url.Parse() validation to the webserver.hostname. * Use stricter formatting strings in config package.
Introduced the type TileURLTemplate for handling forming up tile template URLs. This adds more structure and type safety when handling the creation of tile template URLs. closes #994
This type was added for better error handling of the Webserver.HostName config property.
1919ce1
to
287545e
Compare
Though this PR has a lot of code changes, a lot of them are clean up, adding consts, and formatting. The material changes are as follows:
buildCapabilitiesURL
from the server package. This function was handling too many cases and brittle./{z}/{x}/{y}.pbf
uri template suffix will now use this type.hostname
attribute does not support a protocol, but sometimes the protocol was configured and it would result in malformed URLs (putting "https://....." in hostname config directive results in a malformed URL #994). The validation and use of the url.URL package helps work with user supplied URLs.Overall, it's a lot of code, but I got frustrated with the state of things and deemed a refactor necessary.