Skip to content

Commit

Permalink
notifier: copy url struct
Browse files Browse the repository at this point in the history
previous to this commit a reference to the callback url structure was
being mutated.

this commit ensures a copy of the url structure is made and the original
reference is no longer mutated.

Signed-off-by: ldelossa <ldelossa@redhat.com>
  • Loading branch information
ldelossa authored and ldelossa committed Oct 8, 2020
1 parent 3b60292 commit a2d5f9b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions notifier/webhook/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
)

// Config provides configuration for an Webhook deliverer.
Expand Down Expand Up @@ -33,6 +34,12 @@ func (c *Config) Validate() (Config, error) {
}
conf.target = target

// require trailing slash so url.Parse() can easily
// append notification id.
if !strings.HasSuffix(c.Callback, "/") {
c.Callback = c.Callback + "/"
}

callback, err := url.Parse(c.Callback)
if err != nil {
return conf, fmt.Errorf("failed to parse callback url")
Expand Down
7 changes: 4 additions & 3 deletions notifier/webhook/deliverer.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"fmt"
"io/ioutil"
"net/http"
"path"
"time"

"github.com/google/uuid"
Expand Down Expand Up @@ -83,8 +82,10 @@ func (d *Deliverer) Deliver(ctx context.Context, nID uuid.UUID) error {
Str("notification_id", nID.String()).
Logger()

callback := d.conf.callback
callback.Path = path.Join(callback.Path, nID.String())
callback, err := d.conf.callback.Parse(nID.String())
if err != nil {
return err
}

wh := notifier.Callback{
NotificationID: nID,
Expand Down

0 comments on commit a2d5f9b

Please sign in to comment.