From 6ab62cc16c8690f72b23954fc28b704a6158153e Mon Sep 17 00:00:00 2001 From: Antoine Jouve Date: Tue, 12 Sep 2023 23:31:26 +0200 Subject: [PATCH] fix: Gitlab scm_provider - don't create transport from scratch (#15424) (#15425) * fix : don't create transport from scratch, clone it instead Signed-off-by: Antoine Jouve * feat: clone http.transport for gitea and gitlab providers Signed-off-by: Antoine Jouve * chore: properly format gitea providers with gofmt Signed-off-by: Antoine Jouve --------- Signed-off-by: Antoine Jouve --- applicationset/services/pull_request/gitea.go | 10 ++++++---- applicationset/services/pull_request/gitlab.go | 6 +++--- applicationset/services/scm_provider/gitea.go | 10 ++++++---- applicationset/services/scm_provider/gitlab.go | 6 +++--- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/applicationset/services/pull_request/gitea.go b/applicationset/services/pull_request/gitea.go index 435a0b57117e6..ff385ff281c6d 100644 --- a/applicationset/services/pull_request/gitea.go +++ b/applicationset/services/pull_request/gitea.go @@ -26,11 +26,13 @@ func NewGiteaService(ctx context.Context, token, url, owner, repo string, insecu if insecure { cookieJar, _ := cookiejar.New(nil) + tr := http.DefaultTransport.(*http.Transport).Clone() + tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + httpClient = &http.Client{ - Jar: cookieJar, - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }} + Jar: cookieJar, + Transport: tr, + } } client, err := gitea.NewClient(url, gitea.SetToken(token), gitea.SetHTTPClient(httpClient)) if err != nil { diff --git a/applicationset/services/pull_request/gitlab.go b/applicationset/services/pull_request/gitlab.go index 9732991c76fcf..04a4f3464f6f0 100644 --- a/applicationset/services/pull_request/gitlab.go +++ b/applicationset/services/pull_request/gitlab.go @@ -32,9 +32,9 @@ func NewGitLabService(ctx context.Context, token, url, project string, labels [] token = os.Getenv("GITLAB_TOKEN") } - tr := &http.Transport{ - TLSClientConfig: utils.GetTlsConfig(scmRootCAPath, insecure), - } + tr := http.DefaultTransport.(*http.Transport).Clone() + tr.TLSClientConfig = utils.GetTlsConfig(scmRootCAPath, insecure) + retryClient := retryablehttp.NewClient() retryClient.HTTPClient.Transport = tr diff --git a/applicationset/services/scm_provider/gitea.go b/applicationset/services/scm_provider/gitea.go index 9e24abdcabb43..25554d52af85f 100644 --- a/applicationset/services/scm_provider/gitea.go +++ b/applicationset/services/scm_provider/gitea.go @@ -27,11 +27,13 @@ func NewGiteaProvider(ctx context.Context, owner, token, url string, allBranches if insecure { cookieJar, _ := cookiejar.New(nil) + tr := http.DefaultTransport.(*http.Transport).Clone() + tr.TLSClientConfig = &tls.Config{InsecureSkipVerify: true} + httpClient = &http.Client{ - Jar: cookieJar, - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, - }} + Jar: cookieJar, + Transport: tr, + } } client, err := gitea.NewClient(url, gitea.SetToken(token), gitea.SetHTTPClient(httpClient)) if err != nil { diff --git a/applicationset/services/scm_provider/gitlab.go b/applicationset/services/scm_provider/gitlab.go index d132de2b8fc9a..f4b92b3ed9e5f 100644 --- a/applicationset/services/scm_provider/gitlab.go +++ b/applicationset/services/scm_provider/gitlab.go @@ -30,9 +30,9 @@ func NewGitlabProvider(ctx context.Context, organization string, token string, u } var client *gitlab.Client - tr := &http.Transport{ - TLSClientConfig: utils.GetTlsConfig(scmRootCAPath, insecure), - } + tr := http.DefaultTransport.(*http.Transport).Clone() + tr.TLSClientConfig = utils.GetTlsConfig(scmRootCAPath, insecure) + retryClient := retryablehttp.NewClient() retryClient.HTTPClient.Transport = tr