Skip to content

Commit

Permalink
Fix(Provider/Matrix): CertSecretRef
Browse files Browse the repository at this point in the history
Signed-off-by: Gerrit Pannek <nold@gnu.one>
  • Loading branch information
nold committed Jan 26, 2022
1 parent ea37642 commit 9f824f0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
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

0 comments on commit 9f824f0

Please sign in to comment.