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

Add cert pool to Slack provider requests #207

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
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