Skip to content

Commit

Permalink
Merge pull request #33000 from vespa-engine/retrieve_versions_with_state
Browse files Browse the repository at this point in the history
Allow multiple staging labels for a retrieved version
  • Loading branch information
gjoranv authored Dec 5, 2024
2 parents c929476 + 69bf107 commit de61821
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.HashSet;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand Down Expand Up @@ -124,16 +125,14 @@ private Secret retrieveSecret(Key key, SecretVersionId version) {
}

private static SecretVersionState toSecretVersionState(List<String> versionStages) {
if (versionStages.size() != 1) {
throw new IllegalArgumentException("Expected exactly one version stage, got: " + versionStages);
var stages = new HashSet<>(versionStages);
if (stages.contains(AWSCURRENT)) {
return SecretVersionState.CURRENT;
} else if (stages.contains(AWSPENDING)) {
return SecretVersionState.PENDING;
} else {
return SecretVersionState.DEPRECATED;
}
var state = versionStages.get(0);
return switch (state) {
case "AWSCURRENT" -> SecretVersionState.CURRENT;
case "AWSPENDING" -> SecretVersionState.PENDING;
case "AWSPREVIOUS" -> SecretVersionState.PREVIOUS;
default -> throw new IllegalArgumentException("Unknown secret version state: " + state);
};
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public GetSecretValueResponse getSecretValue(GetSecretValueRequest request) {
.name(request.secretId())
.secretString(secret.value())
.versionId(secret.version())
.versionStages(List.of(toAwsStage(secret.state())))
.versionStages(toAwsStages(secret.state()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public ListSecretVersionIdsResponse listSecretVersionIds(ListSecretVersionIdsReq
.versions(secrets.getOrDefault(request.secretId(), List.of()).stream()
.map(version -> SecretVersionsListEntry.builder()
.versionId(version.version())
.versionStages(List.of(toAwsStage(version.state())))
.versionStages(toAwsStages(version.state()))
.build())
.toList())
.build();
Expand All @@ -85,12 +85,11 @@ public void close() {
isClosed = true;
}

protected String toAwsStage(SecretVersionState state) {
protected List<String> toAwsStages(SecretVersionState state) {
return switch (state) {
case CURRENT -> "AWSCURRENT";
case PENDING -> "AWSPENDING";
case PREVIOUS -> "AWSPREVIOUS";
default -> throw new IllegalArgumentException("Unknown state: " + state);
case CURRENT -> List.of("AWSCURRENT");
case PENDING -> List.of("AWSPENDING");
case PREVIOUS, DEPRECATED -> List.of();
};
}

Expand Down

0 comments on commit de61821

Please sign in to comment.