Skip to content

Commit

Permalink
Merge pull request #257 from fluxcd/feature/msteams-cert-pool
Browse files Browse the repository at this point in the history
Fix MSTeams certificates
  • Loading branch information
Philip Laine authored Oct 22, 2021
2 parents 71dc13e + 77f4038 commit 3a43759
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/notifier/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (f Factory) Notifier(provider string) (Interface, error) {
case v1beta1.RocketProvider:
n, err = NewRocket(f.URL, f.ProxyURL, f.CertPool, f.Username, f.Channel)
case v1beta1.MSTeamsProvider:
n, err = NewMSTeams(f.URL, f.ProxyURL)
n, err = NewMSTeams(f.URL, f.ProxyURL, f.CertPool)
case v1beta1.GitHubProvider:
n, err = NewGitHub(f.URL, f.Token, f.CertPool)
case v1beta1.GitLabProvider:
Expand Down
7 changes: 5 additions & 2 deletions internal/notifier/teams.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"
"fmt"
"net/url"
"strings"
Expand All @@ -28,6 +29,7 @@ import (
type MSTeams struct {
URL string
ProxyURL string
CertPool *x509.CertPool
}

// MSTeamsPayload holds the message card data
Expand All @@ -52,7 +54,7 @@ type MSTeamsField struct {
}

// NewMSTeams validates the MS Teams URL and returns a MSTeams object
func NewMSTeams(hookURL string, proxyURL string) (*MSTeams, error) {
func NewMSTeams(hookURL string, proxyURL string, certPool *x509.CertPool) (*MSTeams, error) {
_, err := url.ParseRequestURI(hookURL)
if err != nil {
return nil, fmt.Errorf("invalid MS Teams webhook URL %s", hookURL)
Expand All @@ -61,6 +63,7 @@ func NewMSTeams(hookURL string, proxyURL string) (*MSTeams, error) {
return &MSTeams{
URL: hookURL,
ProxyURL: proxyURL,
CertPool: certPool,
}, nil
}

Expand Down Expand Up @@ -98,7 +101,7 @@ func (s *MSTeams) Post(event events.Event) error {
payload.ThemeColor = "FF0000"
}

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
2 changes: 1 addition & 1 deletion internal/notifier/teams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestTeams_Post(t *testing.T) {
}))
defer ts.Close()

teams, err := NewMSTeams(ts.URL, "")
teams, err := NewMSTeams(ts.URL, "", nil)
require.NoError(t, err)

err = teams.Post(testEvent())
Expand Down

0 comments on commit 3a43759

Please sign in to comment.