Skip to content

Commit

Permalink
refactor(credentials): modify GetCredential to return pointer for in-…
Browse files Browse the repository at this point in the history
…place updates

- Change GetCredential signature to return *secrets.SourceMap instead of value
- Update loadCredentials to use Keys() iterator for credential lookup
- Add explicit error handling for missing credentials
- Fix credential value updates to modify original values via pointers

Signed-off-by: Kim Christensen <kimworking@gmail.com>
  • Loading branch information
kichristensen committed Dec 31, 2024
1 parent c24aadc commit 359c98a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions pkg/cnab/provider/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ func (r *Runtime) loadCredentials(ctx context.Context, b cnab.ExtendedBundle, ru
return span.Error(err)
}

for i, cred := range run.Credentials.Credentials {
run.Credentials.Credentials[i].ResolvedValue = resolvedCredentials[cred.Name]
for key := range run.Credentials.Keys() {
cred, ok := run.Credentials.GetCredential(key)
if !ok {
return span.Errorf("credential %s not found", key)
}
cred.ResolvedValue = resolvedCredentials[key]
}

err = run.Credentials.ValidateBundle(b.Credentials, run.Action)
Expand Down
6 changes: 3 additions & 3 deletions pkg/storage/credentialset.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ func (s CredentialSet) Keys() iter.Seq[string] {
}

// GetCredential returns the credential with the given name, and a boolean indicating if it was found.
func (s CredentialSet) GetCredential(name string) (secrets.SourceMap, bool) {
func (s CredentialSet) GetCredential(name string) (*secrets.SourceMap, bool) {
for _, cred := range s.Credentials {
if cred.Name == name {
return cred, true
return &cred, true
}
}
return secrets.SourceMap{}, false
return nil, false
}

0 comments on commit 359c98a

Please sign in to comment.