Skip to content

Commit

Permalink
fix: Gitlab scm_provider - don't create transport from scratch (argop…
Browse files Browse the repository at this point in the history
…roj#15424) (argoproj#15425)

* fix : don't create transport from scratch, clone it instead

Signed-off-by: Antoine Jouve <[email protected]>

* feat: clone http.transport for gitea and gitlab providers

Signed-off-by: Antoine Jouve <[email protected]>

* chore: properly format gitea providers with gofmt

Signed-off-by: Antoine Jouve <[email protected]>

---------

Signed-off-by: Antoine Jouve <[email protected]>
  • Loading branch information
an-toine authored and vladfr committed Dec 13, 2023
1 parent 1c461b1 commit 6ab62cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
10 changes: 6 additions & 4 deletions applicationset/services/pull_request/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions applicationset/services/pull_request/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 6 additions & 4 deletions applicationset/services/scm_provider/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions applicationset/services/scm_provider/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 6ab62cc

Please sign in to comment.