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

fix(injector): fix issue nil interface conversion #141

Merged
merged 2 commits into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading