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(Provider/Matrix): Load CA from CertSecretRef #318

Merged
merged 1 commit into from
Jan 26, 2022
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 @@ -82,7 +82,7 @@ func (f Factory) Notifier(provider string) (Interface, error) {
case v1beta1.LarkProvider:
n, err = NewLark(f.URL)
case v1beta1.Matrix:
n, err = NewMatrix(f.URL, f.Token, f.Channel)
n, err = NewMatrix(f.URL, f.Token, f.Channel, f.CertPool)
case v1beta1.OpsgenieProvider:
n, err = NewOpsgenie(f.URL, f.ProxyURL, f.CertPool, f.Token)
case v1beta1.AlertManagerProvider:
Expand Down
19 changes: 11 additions & 8 deletions internal/notifier/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package notifier

import (
"crypto/sha1"
"crypto/x509"
"encoding/json"
"fmt"
"net/http"
Expand All @@ -13,26 +14,28 @@ import (
)

type Matrix struct {
Token string
URL string
RoomId string
Token string
URL string
RoomId string
CertPool *x509.CertPool
}

type MatrixPayload struct {
Body string `json:"body"`
MsgType string `json:"msgtype"`
}

func NewMatrix(serverURL, token, roomId string) (*Matrix, error) {
func NewMatrix(serverURL, token, roomId string, certPool *x509.CertPool) (*Matrix, error) {
_, err := url.ParseRequestURI(serverURL)
if err != nil {
return nil, fmt.Errorf("invalid Matrix homeserver URL %s", serverURL)
}

return &Matrix{
URL: serverURL,
RoomId: roomId,
Token: token,
URL: serverURL,
RoomId: roomId,
Token: token,
CertPool: certPool,
}, nil
}

Expand Down Expand Up @@ -61,7 +64,7 @@ func (m *Matrix) Post(event events.Event) error {
MsgType: "m.text",
}

err = postMessage(fullURL, "", nil, payload, func(request *retryablehttp.Request) {
err = postMessage(fullURL, "", m.CertPool, payload, func(request *retryablehttp.Request) {
request.Method = http.MethodPut
request.Header.Add("Authorization", "Bearer "+m.Token)
})
Expand Down
2 changes: 1 addition & 1 deletion tests/fuzz/matrix_fuzzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func FuzzMatrix(data []byte) int {
return 0
}

matrix, err := NewMatrix(ts.URL, "", token)
matrix, err := NewMatrix(ts.URL, "", token, nil)
if err != nil {
return 0
}
Expand Down