Skip to content

Commit 47fa3e4

Browse files
authored
fix: apply fixes found by linter (#43)
1 parent a126c37 commit 47fa3e4

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

pkg/cmd/cleanupdeployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,5 +144,5 @@ func askForConfirmation(question string) (response bool, err error) {
144144
case "no":
145145
return false, nil
146146
}
147-
return false, fmt.Errorf("Invalid answer, aborting.")
147+
return false, fmt.Errorf("invalid answer, aborting")
148148
}

pkg/helm/release.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ type helmListOutput struct {
3030

3131
func (cli *HelmCLI) UninstallReleases(ctx context.Context, namespace string, releases []string) error {
3232
args := []string{"uninstall", "--wait", "--namespace", namespace}
33-
for _, release := range releases {
34-
args = append(args, release)
35-
}
33+
args = append(args, releases...)
3634

3735
out, err := cli.RunCmd(ctx, args...)
3836
if err != nil {

pkg/k8s/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func GetClientset() (*kubernetes.Clientset, error) {
1414
home := homedir.HomeDir()
1515
if home == "" {
16-
return nil, fmt.Errorf("Could not determine home directory")
16+
return nil, fmt.Errorf("could not determine home directory")
1717
}
1818

1919
kubeconfig := filepath.Join(home, ".kube", "config")
@@ -28,7 +28,7 @@ func GetClientset() (*kubernetes.Clientset, error) {
2828
func GetDynamicClient() (client *dynamic.DynamicClient, err error) {
2929
home := homedir.HomeDir()
3030
if home == "" {
31-
return nil, fmt.Errorf("Could not determine home directory")
31+
return nil, fmt.Errorf("could not determine home directory")
3232
}
3333

3434
kubeconfig := filepath.Join(home, ".kube", "config")

pkg/keycloak/admin.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (client *KeycloakClient) FindUser(ctx context.Context, realm string, email
3030
}
3131
}
3232

33-
return "", fmt.Errorf("Could not find user '%s' in Keycloak", email)
33+
return "", fmt.Errorf("could not find user '%s' in Keycloak", email)
3434
}
3535

3636
func (client *KeycloakClient) GetAdminUsersURL(realm string) *url.URL {
@@ -75,11 +75,14 @@ func (client *KeycloakClient) findRenkuAdminRole(ctx context.Context, realm stri
7575
return role, err
7676
}
7777
}
78-
return roleMapping{}, fmt.Errorf("Could not find role '%s' in Keycloak", renkuAdminRole)
78+
return roleMapping{}, fmt.Errorf("could not find role '%s' in Keycloak", renkuAdminRole)
7979
}
8080

8181
func (client *KeycloakClient) AddRenkuAdminRoleToUser(ctx context.Context, realm string, userID string) error {
8282
role, err := client.findRenkuAdminRole(ctx, realm, userID)
83+
if err != nil {
84+
return err
85+
}
8386

8487
postURL := client.GetAdminRolesURL(realm, userID)
8588

pkg/keycloak/rest.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func (client *KeycloakClient) GetJSON(ctx context.Context, url string, result an
3030
if resp.Header.Get("Content-Type") == jsonContentType {
3131
parseErr = tryParseResponse(resp, result)
3232
} else {
33-
return resp, fmt.Errorf("Expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
33+
return resp, fmt.Errorf("expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
3434
}
3535
if resp.StatusCode >= 200 && resp.StatusCode < 300 && parseErr != nil {
3636
return resp, parseErr
@@ -67,7 +67,7 @@ func (client *KeycloakClient) PostJSON(ctx context.Context, url string, body any
6767
// No content
6868
return resp, nil
6969
} else {
70-
return resp, fmt.Errorf("Expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
70+
return resp, fmt.Errorf("expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
7171
}
7272
if resp.StatusCode >= 200 && resp.StatusCode < 300 && parseErr != nil {
7373
return resp, parseErr
@@ -95,7 +95,7 @@ func (client *KeycloakClient) PostForm(ctx context.Context, url string, data url
9595
if resp.Header.Get("Content-Type") == jsonContentType {
9696
parseErr = tryParseResponse(resp, result)
9797
} else {
98-
return resp, fmt.Errorf("Expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
98+
return resp, fmt.Errorf("expected '%s' but got response with content type '%s'", jsonContentType, resp.Header.Get("Content-Type"))
9999
}
100100
if resp.StatusCode >= 200 && resp.StatusCode < 300 && parseErr != nil {
101101
return resp, parseErr
@@ -105,7 +105,11 @@ func (client *KeycloakClient) PostForm(ctx context.Context, url string, data url
105105
}
106106

107107
func tryParseResponse(resp *http.Response, result any) error {
108-
defer resp.Body.Close()
108+
defer func() {
109+
if err := resp.Body.Close(); err != nil {
110+
fmt.Printf("Warning, could not close HTTP response: %s", err.Error())
111+
}
112+
}()
109113

110114
outBuf := new(bytes.Buffer)
111115
_, err := outBuf.ReadFrom(resp.Body)

pkg/renkuapi/auth.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,11 @@ func (auth *RenkuApiAuth) postForm(ctx context.Context, url string, data url.Val
370370
}
371371

372372
func tryParseResponse(resp *http.Response, result any) error {
373-
defer resp.Body.Close()
373+
defer func() {
374+
if err := resp.Body.Close(); err != nil {
375+
fmt.Printf("Warning, could not close HTTP response: %s", err.Error())
376+
}
377+
}()
374378

375379
outBuf := new(bytes.Buffer)
376380
_, err := outBuf.ReadFrom(resp.Body)

0 commit comments

Comments
 (0)