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

Fix MSTeams certificates #257

Merged
merged 2 commits into from
Oct 22, 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 @@ -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