Skip to content

Commit 558f7d5

Browse files
committed
address PR comments
1 parent d1fe8d4 commit 558f7d5

2 files changed

Lines changed: 20 additions & 21 deletions

File tree

internal/pkg/auth/storage.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package auth
33
import (
44
"encoding/base64"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"os"
89
"path/filepath"
@@ -45,20 +46,18 @@ const (
4546
)
4647

4748
// Returns all auth field keys managed by the auth storage
48-
func getAllAuthFieldKeys() []authFieldKey {
49-
return []authFieldKey{
50-
SESSION_EXPIRES_AT_UNIX,
51-
ACCESS_TOKEN,
52-
REFRESH_TOKEN,
53-
SERVICE_ACCOUNT_TOKEN,
54-
SERVICE_ACCOUNT_EMAIL,
55-
USER_EMAIL,
56-
SERVICE_ACCOUNT_KEY,
57-
PRIVATE_KEY,
58-
TOKEN_CUSTOM_ENDPOINT,
59-
JWKS_CUSTOM_ENDPOINT,
60-
authFlowType,
61-
}
49+
var authFieldKeys = []authFieldKey{
50+
SESSION_EXPIRES_AT_UNIX,
51+
ACCESS_TOKEN,
52+
REFRESH_TOKEN,
53+
SERVICE_ACCOUNT_TOKEN,
54+
SERVICE_ACCOUNT_EMAIL,
55+
USER_EMAIL,
56+
SERVICE_ACCOUNT_KEY,
57+
PRIVATE_KEY,
58+
TOKEN_CUSTOM_ENDPOINT,
59+
JWKS_CUSTOM_ENDPOINT,
60+
authFlowType,
6261
}
6362

6463
func SetAuthFlow(value AuthFlow) error {
@@ -273,18 +272,18 @@ func GetProfileEmail(profile string) string {
273272
}
274273

275274
func DeleteProfileFromKeyring(profile string) error {
276-
allKeys := getAllAuthFieldKeys()
277-
278275
err := config.ValidateProfile(profile)
279276
if err != nil {
280277
return fmt.Errorf("validate profile: %w", err)
281278
}
282279

283-
for _, key := range allKeys {
280+
for _, key := range authFieldKeys {
284281
err := deleteAuthFieldInKeyring(profile, key)
285282
if err != nil {
286-
// If the key doesn't exist, continue
287-
continue
283+
// if the key is not found, we can ignore the error
284+
if !errors.Is(err, keyring.ErrNotFound) {
285+
return fmt.Errorf("delete auth field \"%s\" from keyring: %w", key, err)
286+
}
288287
}
289288
}
290289

internal/pkg/auth/storage_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ func TestDeleteProfileFromKeyring(t *testing.T) {
553553
}{
554554
{
555555
description: "base, default profile",
556-
keys: getAllAuthFieldKeys(),
556+
keys: authFieldKeys,
557557
activeProfile: config.DefaultProfileName,
558558
isValid: true,
559559
},
@@ -568,7 +568,7 @@ func TestDeleteProfileFromKeyring(t *testing.T) {
568568
},
569569
{
570570
description: "base, custom profile",
571-
keys: getAllAuthFieldKeys(),
571+
keys: authFieldKeys,
572572
activeProfile: "test-profile",
573573
isValid: true,
574574
},

0 commit comments

Comments
 (0)