-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
config: validate URLs at config load time #1468
Conversation
config/config_test.go
Outdated
if err != nil { | ||
t.Fatal(err) | ||
} | ||
require.Equal(t, "<secret>\n", string(c), "SecretURL not properly elidedin YAML.") |
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.
missing space
notify/impl.go
Outdated
alias = hashKey(key) | ||
alerts = types.Alerts(as...) | ||
msg interface{} | ||
apiURL, _ = url.Parse(n.conf.APIURL.String()) |
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.
For consistency and clarity for future readers we could use same comment here about checking at conf load time
notify/impl.go
Outdated
@@ -759,8 +763,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...) | |||
tmplText = tmplText(n.tmpl, data, &err) | |||
tmplHTML = tmplHTML(n.tmpl, data, &err) | |||
url = fmt.Sprintf("%sv2/room/%s/notification?auth_token=%s", n.conf.APIURL, n.conf.RoomID, n.conf.AuthToken) | |||
// n.conf.APIURL is already checked at configuration load time. | |||
url, _ = url.Parse(n.conf.APIURL.String()) |
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.
I am a bit confused here, why not just n.conf.APIURL
is this not already a URL?
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.
n.conf.APIURL
is a pointer so I didn't want to modify it.
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.
you could also do
u := *c.conf.APIURL
u.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", n.conf.RoomID, n.conf.AuthToken)
// ...
resp, err := ctxhttp.Post(ctx, c, u.String(), contentTypeJSON, &buf)
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.
since we've assigned something to variable name url
, we've shadowed the reference to the package net/url
in this scope. Having url's named u
is annoying, but at some point someone will want to use net/url
later in this package..
@simonpasquier There are a couple more |
@mxinden absolutely! Not sure how I managed to miss them... |
The pushover url is a template, not a url. |
@brian-brazil yep, I replied too fast. This isn't the Pushover API URL... |
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.
couple relatively unimportant comments
notify/impl.go
Outdated
@@ -759,8 +763,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...) | |||
tmplText = tmplText(n.tmpl, data, &err) | |||
tmplHTML = tmplHTML(n.tmpl, data, &err) | |||
url = fmt.Sprintf("%sv2/room/%s/notification?auth_token=%s", n.conf.APIURL, n.conf.RoomID, n.conf.AuthToken) | |||
// n.conf.APIURL is already checked at configuration load time. | |||
url, _ = url.Parse(n.conf.APIURL.String()) |
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.
you could also do
u := *c.conf.APIURL
u.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", n.conf.RoomID, n.conf.AuthToken)
// ...
resp, err := ctxhttp.Post(ctx, c, u.String(), contentTypeJSON, &buf)
notify/impl.go
Outdated
@@ -759,8 +763,10 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...) | |||
tmplText = tmplText(n.tmpl, data, &err) | |||
tmplHTML = tmplHTML(n.tmpl, data, &err) | |||
url = fmt.Sprintf("%sv2/room/%s/notification?auth_token=%s", n.conf.APIURL, n.conf.RoomID, n.conf.AuthToken) | |||
// n.conf.APIURL is already checked at configuration load time. | |||
url, _ = url.Parse(n.conf.APIURL.String()) |
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.
since we've assigned something to variable name url
, we've shadowed the reference to the package net/url
in this scope. Having url's named u
is annoying, but at some point someone will want to use net/url
later in this package..
Signed-off-by: Simon Pasquier <[email protected]>
Signed-off-by: Simon Pasquier <[email protected]>
Signed-off-by: Simon Pasquier <[email protected]>
6570755
to
b5001b3
Compare
Signed-off-by: Simon Pasquier <[email protected]>
b5001b3
to
353e2b9
Compare
notify/impl.go
Outdated
@@ -802,8 +802,7 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
tmplText = tmplText(n.tmpl, data, &err) | |||
tmplHTML = tmplHTML(n.tmpl, data, &err) | |||
roomid = tmplText(n.conf.RoomID) | |||
// n.conf.APIURL is already checked at configuration load time. | |||
url, _ = url.Parse(n.conf.APIURL.String()) | |||
url = *n.conf.APIURL |
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 isn't a deep copy, needs to be fixed.
notify/impl.go
Outdated
@@ -798,8 +802,9 @@ func (n *Hipchat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) | |||
tmplText = tmplText(n.tmpl, data, &err) | |||
tmplHTML = tmplHTML(n.tmpl, data, &err) | |||
roomid = tmplText(n.conf.RoomID) | |||
url = fmt.Sprintf("%sv2/room/%s/notification?auth_token=%s", n.conf.APIURL, roomid, n.conf.AuthToken) | |||
apiURL = *n.conf.APIURL |
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 isn't a deep copy, needs to be fixed.
Signed-off-by: Simon Pasquier <[email protected]>
* config: validate URLs at config load time Signed-off-by: Simon Pasquier <[email protected]> * Address Brian and Lucas comments Signed-off-by: Simon Pasquier <[email protected]> * Shallow copy of URL instead of reparsing it Signed-off-by: Simon Pasquier <[email protected]> * Unshadow net/url package Signed-off-by: Simon Pasquier <[email protected]> * Make a deep-copy of URL struct Signed-off-by: Simon Pasquier <[email protected]>
* config: validate URLs at config load time Signed-off-by: Simon Pasquier <[email protected]> * Address Brian and Lucas comments Signed-off-by: Simon Pasquier <[email protected]> * Shallow copy of URL instead of reparsing it Signed-off-by: Simon Pasquier <[email protected]> * Unshadow net/url package Signed-off-by: Simon Pasquier <[email protected]> * Make a deep-copy of URL struct Signed-off-by: Simon Pasquier <[email protected]>
Closes #1460