Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Grant Linville <grant@acorn.io>
  • Loading branch information
g-linville committed Sep 17, 2024
1 parent d2442f4 commit 12999ac
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/credentials/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,12 @@ func (s Store) Get(ctx context.Context, toolName string) (*Credential, bool, err
}

func (s Store) Add(ctx context.Context, cred Credential) error {
if first(s.credCtxs) == AllCredentialContexts {
first := first(s.credCtxs)
if first == AllCredentialContexts {
return fmt.Errorf("cannot add a credential with context %q", AllCredentialContexts)
}
cred.Context = first(s.credCtxs)
cred.Context = first

store, err := s.getStore(ctx)
if err != nil {
return err
Expand All @@ -112,7 +114,8 @@ func (s Store) Add(ctx context.Context, cred Credential) error {
}

func (s Store) Remove(ctx context.Context, toolName string) error {
if len(s.credCtxs) > 1 || first(s.credCtxs) == AllCredentialContexts {
first := first(s.credCtxs)
if len(s.credCtxs) > 1 || first == AllCredentialContexts {
return fmt.Errorf("error: credential deletion is not supported when multiple credential contexts are provided")
}

Expand All @@ -121,7 +124,7 @@ func (s Store) Remove(ctx context.Context, toolName string) error {
return err
}

return store.Erase(toolNameWithCtx(toolName, first(s.credCtxs)))
return store.Erase(toolNameWithCtx(toolName, first))
}

func (s Store) List(ctx context.Context) ([]Credential, error) {
Expand Down

0 comments on commit 12999ac

Please sign in to comment.