From 5830b22420ac55e85ee633f504038fdbcbf05105 Mon Sep 17 00:00:00 2001 From: cmoulliard Date: Wed, 11 Dec 2024 15:59:30 +0100 Subject: [PATCH] Improve code and variables Signed-off-by: cmoulliard --- pkg/controllers/localbuild/controller.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pkg/controllers/localbuild/controller.go b/pkg/controllers/localbuild/controller.go index d2dd0cf0..c4989093 100644 --- a/pkg/controllers/localbuild/controller.go +++ b/pkg/controllers/localbuild/controller.go @@ -707,14 +707,14 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi } req.Header.Set("Content-Type", "application/json") - // Create an HTTP client and disable TLS verification - client := &http.Client{} + // Create an HTTP httpClient and disable TLS verification + httpClient := &http.Client{} transport := http.DefaultTransport.(*http.Transport).Clone() transport.TLSClientConfig.InsecureSkipVerify = true - client.Transport = transport + httpClient.Transport = transport // Send the request - resp, err := client.Do(req) + resp, err := httpClient.Do(req) if err != nil { return fmt.Errorf("Error sending request: %v\n", err), "failed" } @@ -747,10 +747,12 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi } req, err := http.NewRequest("PUT", argocdEndpoint+"/account/password", bytes.NewBuffer(payloadBytes)) - req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", argocdSession.Token)) - req.Header.Set("Content-Type", "application/json") + if req != nil { + req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", argocdSession.Token)) + req.Header.Set("Content-Type", "application/json") + } - resp, err := client.Do(req) + resp, err := httpClient.Do(req) if err != nil { return fmt.Errorf("Error sending request: %v\n", err), "failed" } @@ -774,7 +776,7 @@ func (r *LocalbuildReconciler) updateArgocdDevPassword(ctx context.Context, admi req.Header.Set("Content-Type", "application/json") // Send the request - resp, err = client.Do(req) + resp, err = httpClient.Do(req) if err != nil { return fmt.Errorf("Error sending request: %v\n", err), "failed" }