From 6f4441aa4a231e39aaf77a4862eed2ac22679897 Mon Sep 17 00:00:00 2001 From: shreddedbacon Date: Fri, 24 May 2024 14:45:44 +1000 Subject: [PATCH] fix: insecure skip verify check for harbor with invalid --- internal/harbor/harbor.go | 6 ++++++ main.go | 9 +-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/internal/harbor/harbor.go b/internal/harbor/harbor.go index d2e698d3..f26bc62c 100644 --- a/internal/harbor/harbor.go +++ b/internal/harbor/harbor.go @@ -1,6 +1,8 @@ package harbor import ( + "crypto/tls" + "net/http" "time" "github.com/go-logr/logr" @@ -35,11 +37,15 @@ type Harbor struct { WebhookEventTypes []string LagoonTargetName string Config *config.Options + TLSSkipVerify bool } // New create a new harbor connection. func New(harbor Harbor) (*Harbor, error) { harbor.Log = ctrl.Log.WithName("controllers").WithName("HarborIntegration") + if harbor.TLSSkipVerify { + http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + } c, err := harborclientv3.NewRESTClientForHost(harbor.API, harbor.Username, harbor.Password) if err != nil { return nil, err diff --git a/main.go b/main.go index 60f4463b..6049d025 100644 --- a/main.go +++ b/main.go @@ -17,10 +17,8 @@ package main import ( "context" - "crypto/tls" "flag" "fmt" - "net/http" "net/url" "os" "strings" @@ -631,6 +629,7 @@ func main() { WebhookURL: harborLagoonWebhook, LagoonTargetName: lagoonTargetName, WebhookEventTypes: strings.Split(harborWebhookEventTypes, ","), + TLSSkipVerify: tlsSkipVerify, } deletion := deletions.New(mgr.GetClient(), @@ -887,9 +886,3 @@ func main() { os.Exit(1) } } - -func init() { - if tlsSkipVerify { - http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true} - } -}