Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Commit

Permalink
fix(injector): fix issue nil interface conversion (#141)
Browse files Browse the repository at this point in the history
* fix(injector): fix issue nil interface conversion

Signed-off-by: Bence Csati <[email protected]>

* fix(injector): minor fix

Signed-off-by: Bence Csati <[email protected]>

---------

Signed-off-by: Bence Csati <[email protected]>
  • Loading branch information
csatib02 authored Jan 30, 2024
1 parent 3fb8021 commit 67fc632
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions injector/injector.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,22 @@ func (i *SecretInjector) readVaultPath(path, versionOrData string, update bool)
if ok {
secretData = cast.ToStringMap(v2Data)

// Handle the case where "metadata" key is not present or is nil.
metadataRaw, ok := secret.Data["metadata"]
if metadataRaw == nil || !ok {
return nil, errors.New("metadata key not found or is nil in secret")
}

// Handle the case where the type assertion fails.
metadata, ok := metadataRaw.(map[string]interface{})
if !ok {
return nil, errors.New("metadata has an unexpected type")
}

// Check if a given version of a path is destroyed
metadata := secret.Data["metadata"].(map[string]interface{}) //nolint:forcetypeassert
if metadata["destroyed"].(bool) {
// Handle the case where "destroyed" key is not present or has an unexpected type.
destroyed, _ := metadata["destroyed"].(bool)
if destroyed {
i.logger.Warn("version of secret has been permanently destroyed", slog.String("path", path), slog.String("version", versionOrData))
}

Expand Down

0 comments on commit 67fc632

Please sign in to comment.