Skip to content

Commit a3217c3

Browse files
committed
refactor(credentials): modify GetCredential to return pointer for in-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 <[email protected]>
1 parent 2e900fd commit a3217c3

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

pkg/cnab/provider/credentials.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ func (r *Runtime) loadCredentials(ctx context.Context, b cnab.ExtendedBundle, ru
1717
return span.Error(err)
1818
}
1919

20-
for i, cred := range run.Credentials.Credentials {
21-
run.Credentials.Credentials[i].ResolvedValue = resolvedCredentials[cred.Name]
20+
for _, key := range run.Credentials.Keys() {
21+
cred, ok := run.Credentials.GetCredential(key)
22+
if !ok {
23+
return span.Errorf("credential %s not found", key)
24+
}
25+
cred.ResolvedValue = resolvedCredentials[key]
2226
}
2327

2428
err = run.Credentials.ValidateBundle(b.Credentials, run.Action)

pkg/storage/credentialset.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ func (s CredentialSet) Keys() []string {
196196
}
197197

198198
// GetCredential returns the credential with the given name, and a boolean indicating if it was found.
199-
func (s CredentialSet) GetCredential(name string) (secrets.SourceMap, bool) {
199+
func (s CredentialSet) GetCredential(name string) (*secrets.SourceMap, bool) {
200200
for _, cred := range s.Credentials {
201201
if cred.Name == name {
202-
return cred, true
202+
return &cred, true
203203
}
204204
}
205-
return secrets.SourceMap{}, false
205+
return nil, false
206206
}

0 commit comments

Comments
 (0)