Skip to content

Commit

Permalink
Merge pull request #33033 from vespa-engine/emulate-aws-behaviour
Browse files Browse the repository at this point in the history
Emulate aws behaviour
  • Loading branch information
tokle authored Dec 13, 2024
2 parents 9228c9e + 04cfd16 commit 661cdd5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest;
import software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse;
import software.amazon.awssdk.services.secretsmanager.model.ListSecretVersionIdsRequest;
import software.amazon.awssdk.services.secretsmanager.model.ListSecretVersionIdsResponse;
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;

import javax.net.ssl.SSLContext;
import java.net.URI;
Expand Down Expand Up @@ -163,19 +163,19 @@ public Secret getSecret(Key key) {
@Override
public List<Secret> listSecretVersions(Key key) {
var client = getClient(key.vaultName());

try {
ListSecretVersionIdsResponse response = client.listSecretVersionIds(
ListSecretVersionIdsRequest.builder()
.secretId(awsSecretId(key)).build());

var response = client.listSecretVersionIds(ListSecretVersionIdsRequest.builder()
.secretId(awsSecretId(key))
.build());
var secretVersions = response.versions().stream()
.map(version -> getSecret(key, SecretVersionId.of(version.versionId())))
.sorted().toList();

secretVersions.forEach(secret -> cache.put(new VersionKey(key, secret.version()), secret));

return secretVersions;
} catch (ResourceNotFoundException e) {
return List.of();
} catch (Exception e) {
throw new IllegalArgumentException("Failed to list secret versions for %s:\n%s".formatted(key, e.getMessage()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import software.amazon.awssdk.services.secretsmanager.model.ListSecretVersionIdsResponse;
import software.amazon.awssdk.services.secretsmanager.model.ListSecretsRequest;
import software.amazon.awssdk.services.secretsmanager.model.ListSecretsResponse;
import software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException;
import software.amazon.awssdk.services.secretsmanager.model.SecretListEntry;
import software.amazon.awssdk.services.secretsmanager.model.SecretVersionsListEntry;

Expand Down Expand Up @@ -75,9 +76,13 @@ public ListSecretsResponse listSecrets(Consumer<ListSecretsRequest.Builder> list
// Used by both reader and writer testers
@Override
public ListSecretVersionIdsResponse listSecretVersionIds(ListSecretVersionIdsRequest request) {
if (! secrets.containsKey(request.secretId())) {
// Emulate AWS behavior
throw ResourceNotFoundException.builder().message("Secret not found: " + request.secretId()).build();
}
return ListSecretVersionIdsResponse.builder()
.name(request.secretId())
.versions(secrets.getOrDefault(request.secretId(), List.of()).stream()
.versions(secrets.get(request.secretId()).stream()
.map(version -> SecretVersionsListEntry.builder()
.versionId(version.version())
.versionStages(toAwsStages(version.state()))
Expand Down

0 comments on commit 661cdd5

Please sign in to comment.