Skip to content

Commit

Permalink
fix: get latest versions of secrets instead of oldest
Browse files Browse the repository at this point in the history
  • Loading branch information
duffney committed Nov 26, 2024
1 parent 935681c commit aadd7f0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/keymanagementprovider/azurekeyvault/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ func (s *akvKMProvider) GetCertificates(ctx context.Context) (map[keymanagementp
versionHistory = append(versionHistory, cert.ID.Version())
}
}
//TODO: check if versionHistory not greater than versionHistoryLimit to avoid runtime error

for _, version := range versionHistory[:keyVaultCert.VersionHistoryLimit] {
// get the latest version of the certificate up to the limit
for _, version := range versionHistory[len(versionHistory)-keyVaultCert.VersionHistoryLimit:] {
secretReponse, err := s.secretKVClient.GetSecret(ctx, keyVaultCert.Name, version)
if err != nil {
if isSecretDisabledError(err) {
Expand Down Expand Up @@ -277,7 +279,7 @@ func (s *akvKMProvider) GetKeys(ctx context.Context) (map[keymanagementprovider.
}
}

for _, version := range versionHistory[:keyVaultKey.VersionHistoryLimit] {
for _, version := range versionHistory[len(versionHistory)-keyVaultKey.VersionHistoryLimit:] {
keyResponse, err := s.keyKVClient.GetKey(ctx, keyVaultKey.Name, version)
if err != nil {
return nil, nil, fmt.Errorf("failed to get key objectName:%s, objectVersion:%s, error: %w", keyVaultKey.Name, version, err)
Expand Down

0 comments on commit aadd7f0

Please sign in to comment.