Skip to content

Commit

Permalink
Fix empty tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pfus committed Mar 7, 2025
1 parent c37d811 commit 506100d
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions secure_storage_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,13 @@ func buildCredCacheDirPath(confs []cacheDirConf) (string, error) {

func (ssm *fileBasedSecureStorageManager) getTokens(data map[string]any) map[string]interface{} {
val, ok := data["tokens"]
emptyMap := map[string]interface{}{}
if !ok {
data["tokens"] = emptyMap
return emptyMap
return map[string]interface{}{}
}

tokens, ok := val.(map[string]interface{})
if !ok {
data["tokens"] = emptyMap
return emptyMap
return map[string]interface{}{}

Check warning on line 169 in secure_storage_manager.go

View check run for this annotation

Codecov / codecov/patch

secure_storage_manager.go#L169

Added line #L169 was not covered by tests
}

return tokens
Expand All @@ -189,8 +186,9 @@ func (ssm *fileBasedSecureStorageManager) setCredential(tokenSpec *secureTokenSp
defer ssm.unlockFile()

credCache := ssm.readTemporaryCacheFile()
ssm.getTokens(credCache)[credentialsKey] = value

tokens := ssm.getTokens(credCache)
tokens[credentialsKey] = value
credCache["tokens"] = tokens
err = ssm.writeTemporaryCacheFile(credCache)
if err != nil {
logger.Warnf("Set credential failed. Unable to write cache. %v", err)
Expand Down Expand Up @@ -297,7 +295,6 @@ func (ssm *fileBasedSecureStorageManager) ensurePermissions() error {

if fileInfo.Mode().Perm() != 0o600&os.ModePerm {
return fmt.Errorf("incorrect permissions(%v, expected 600) for credential file", fileInfo.Mode().Perm())

}

return nil
Expand Down

0 comments on commit 506100d

Please sign in to comment.