Skip to content

Commit

Permalink
Add cert pool to Slack provider requests
Browse files Browse the repository at this point in the history
Signed-off-by: Philip Laine <[email protected]>
  • Loading branch information
Philip Laine committed Jun 4, 2021
1 parent f1cc790 commit 11736a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/notifier/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (f Factory) Notifier(provider string) (Interface, error) {
case v1beta1.GenericProvider:
n, err = NewForwarder(f.URL, f.ProxyURL, f.CertPool)
case v1beta1.SlackProvider:
n, err = NewSlack(f.URL, f.ProxyURL, f.Username, f.Channel)
n, err = NewSlack(f.URL, f.ProxyURL, f.CertPool, f.Username, f.Channel)
case v1beta1.DiscordProvider:
n, err = NewDiscord(f.URL, f.ProxyURL, f.Username, f.Channel)
case v1beta1.RocketProvider:
Expand Down
7 changes: 5 additions & 2 deletions internal/notifier/slack.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package notifier

import (
"crypto/x509"
"errors"
"fmt"
"net/url"
Expand All @@ -31,6 +32,7 @@ type Slack struct {
ProxyURL string
Username string
Channel string
CertPool *x509.CertPool
}

// SlackPayload holds the channel and attachments
Expand Down Expand Up @@ -59,7 +61,7 @@ type SlackField struct {
}

// NewSlack validates the Slack URL and returns a Slack object
func NewSlack(hookURL string, proxyURL string, username string, channel string) (*Slack, error) {
func NewSlack(hookURL string, proxyURL string, certPool *x509.CertPool, username string, channel string) (*Slack, error) {
_, err := url.ParseRequestURI(hookURL)
if err != nil {
return nil, fmt.Errorf("invalid Slack hook URL %s", hookURL)
Expand All @@ -74,6 +76,7 @@ func NewSlack(hookURL string, proxyURL string, username string, channel string)
Username: username,
URL: hookURL,
ProxyURL: proxyURL,
CertPool: certPool,
}, nil
}

Expand Down Expand Up @@ -112,7 +115,7 @@ func (s *Slack) Post(event events.Event) error {

payload.Attachments = []SlackAttachment{a}

err := postMessage(s.URL, s.ProxyURL, nil, payload)
err := postMessage(s.URL, s.ProxyURL, s.CertPool, payload)
if err != nil {
return fmt.Errorf("postMessage failed: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/notifier/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func TestSlack_Post(t *testing.T) {
}))
defer ts.Close()

slack, err := NewSlack(ts.URL, "", "", "test")
slack, err := NewSlack(ts.URL, "", nil, "", "test")
require.NoError(t, err)

err = slack.Post(testEvent())
require.NoError(t, err)
}

func TestSlack_PostUpdate(t *testing.T) {
slack, err := NewSlack("http://localhost", "", "", "test")
slack, err := NewSlack("http://localhost", "", nil, "", "test")
require.NoError(t, err)

event := testEvent()
Expand Down

0 comments on commit 11736a3

Please sign in to comment.