Skip to content
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

Merged
merged 5 commits into from
Jul 26, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions notify/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member Author

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.

)
url.Path += fmt.Sprintf("v2/room/%s/notification?auth_token=%s", roomid, n.conf.AuthToken)

Expand Down Expand Up @@ -924,8 +923,7 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
return false, fmt.Errorf("templating error: %s", err)
}

// n.conf.APIURL is already checked at configuration load time.
u, _ := url.Parse(n.conf.APIURL.String())
u := *n.conf.APIURL
u.Path += "gettoken"
u.RawQuery = parameters.Encode()

Expand Down Expand Up @@ -976,8 +974,7 @@ func (n *Wechat) Notify(ctx context.Context, as ...*types.Alert) (bool, error) {
return false, err
}

// n.conf.APIURL is already checked at configuration load time.
postMessageURL, _ := url.Parse(n.conf.APIURL.String())
postMessageURL := *n.conf.APIURL
postMessageURL.Path += "message/send?access_token=" + n.accessToken

req, err := http.NewRequest(http.MethodPost, postMessageURL.String(), &buf)
Expand Down Expand Up @@ -1098,11 +1095,10 @@ func (n *OpsGenie) createRequest(ctx context.Context, as ...*types.Alert) (*http
}

var (
msg interface{}
// n.conf.APIURL is already checked at configuration load time.
apiURL, _ = url.Parse(n.conf.APIURL.String())
alias = hashKey(key)
alerts = types.Alerts(as...)
msg interface{}
apiURL = *n.conf.APIURL
alias = hashKey(key)
alerts = types.Alerts(as...)
)
switch alerts.Status() {
case model.AlertResolved:
Expand Down Expand Up @@ -1208,11 +1204,10 @@ func (n *VictorOps) Notify(ctx context.Context, as ...*types.Alert) (bool, error

var err error
var (
alerts = types.Alerts(as...)
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...)
tmpl = tmplText(n.tmpl, data, &err)
// n.conf.APIURL is already checked at configuration load time.
apiURL, _ = url.Parse(n.conf.APIURL.String())
alerts = types.Alerts(as...)
data = n.tmpl.Data(receiverName(ctx, n.logger), groupLabels(ctx, n.logger), as...)
tmpl = tmplText(n.tmpl, data, &err)
apiURL = *n.conf.APIURL
messageType = tmpl(n.conf.MessageType)
stateMessage = tmpl(n.conf.StateMessage)
)
Expand Down