Fix(Provider/Matrix): CertSecretRef

Signed-off-by: nold <nold@gnu.one>
This commit is contained in:
nold 2022-01-26 10:59:11 +01:00 committed by Gerrit Pannek
parent ea37642f1c
commit 3b86de61a0
3 changed files with 13 additions and 10 deletions

View File

@ -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:

View File

@ -2,6 +2,7 @@ package notifier
import (
"crypto/sha1"
"crypto/x509"
"encoding/json"
"fmt"
"net/http"
@ -13,9 +14,10 @@ import (
)
type Matrix struct {
Token string
URL string
RoomId string
Token string
URL string
RoomId string
CertPool *x509.CertPool
}
type MatrixPayload struct {
@ -23,16 +25,17 @@ type MatrixPayload struct {
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
}
@ -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)
})

View File

@ -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
}