feat: allow insecure connections on deployment to some self-hosted services

This commit is contained in:
Fu Diwei
2025-03-07 21:04:32 +08:00
parent 29dda4ec66
commit 1e2e88e299
33 changed files with 250 additions and 81 deletions

View File

@@ -2,8 +2,10 @@
import (
"context"
"crypto/tls"
"net/http"
"github.com/nikoksr/notify/service/http"
webhook "github.com/nikoksr/notify/service/http"
"github.com/usual2970/certimate/internal/pkg/core/notifier"
)
@@ -11,6 +13,8 @@ import (
type NotifierConfig struct {
// Webhook URL。
Url string `json:"url"`
// 是否允许不安全的连接。
AllowInsecureConnections bool `json:"allowInsecureConnections,omitempty"`
}
type NotifierProvider struct {
@@ -30,10 +34,16 @@ func NewNotifier(config *NotifierConfig) (*NotifierProvider, error) {
}
func (n *NotifierProvider) Notify(ctx context.Context, subject string, message string) (res *notifier.NotifyResult, err error) {
srv := http.New()
srv := webhook.New()
srv.AddReceiversURLs(n.config.Url)
if n.config.AllowInsecureConnections {
tlsConfig := &tls.Config{InsecureSkipVerify: true}
transport := &http.Transport{TLSClientConfig: tlsConfig}
client := &http.Client{Transport: transport}
srv.WithClient(client)
}
err = srv.Send(ctx, subject, message)
if err != nil {
return nil, err

View File

@@ -39,7 +39,8 @@ func TestNotify(t *testing.T) {
}, "\n"))
notifier, err := provider.NewNotifier(&provider.NotifierConfig{
Url: fUrl,
Url: fUrl,
AllowInsecureConnections: true,
})
if err != nil {
t.Errorf("err: %+v", err)