mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
This commit is contained in:
1 parent
0ef6f87cba
commit
37026b75f1
5 files changed
+178
No files matched your search
+43
@@ -44,6 +44,7 @@ public class SecretsManagerJsonHandler {
|
||||
case "ListSecretVersionIds" -> handleListSecretVersionIds(request, region);
|
||||
case "GetResourcePolicy" -> handleGetResourcePolicy(request, region);
|
||||
case "GetRandomPassword" -> handleGetRandomPassword(request, region);
|
||||
case "BatchGetSecretValue" -> handleBatchGetSecretValue(request, region);
|
||||
case "DeleteResourcePolicy" -> Response.ok(objectMapper.createObjectNode()).build();
|
||||
case "PutResourcePolicy" -> Response.ok(objectMapper.createObjectNode()).build();
|
||||
default -> Response.status(400)
|
||||
@@ -52,6 +53,48 @@ public class SecretsManagerJsonHandler {
|
||||
};
|
||||
}
|
||||
|
||||
private Response handleBatchGetSecretValue(JsonNode request, String region) {
|
||||
if (!request.has("SecretIdList") && !request.has("Filters")) {
|
||||
return Response.status(400)
|
||||
.entity(new AwsErrorResponse("InvalidParameterException", "You must specify either SecretIdList or Filters."))
|
||||
.build();
|
||||
}
|
||||
|
||||
List<String> secretIdList = new ArrayList<>();
|
||||
if (request.has("SecretIdList")) {
|
||||
request.path("SecretIdList").forEach(id -> secretIdList.add(id.asText()));
|
||||
}
|
||||
|
||||
// Filters are not fully implemented yet, but for now we only support SecretIdList
|
||||
List<SecretsManagerService.BatchSecretValue> values = service.batchGetSecretValue(secretIdList, region);
|
||||
|
||||
ObjectNode response = objectMapper.createObjectNode();
|
||||
ArrayNode secretValues = objectMapper.createArrayNode();
|
||||
for (SecretsManagerService.BatchSecretValue value : values) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("ARN", value.arn());
|
||||
node.put("Name", value.name());
|
||||
node.put("VersionId", value.versionId());
|
||||
if (value.secretString() != null) {
|
||||
node.put("SecretString", value.secretString());
|
||||
}
|
||||
if (value.secretBinary() != null) {
|
||||
node.put("SecretBinary", value.secretBinary());
|
||||
}
|
||||
if (value.createdDate() != null) {
|
||||
node.put("CreatedDate", value.createdDate().toEpochMilli() / 1000.0);
|
||||
}
|
||||
ArrayNode stages = objectMapper.createArrayNode();
|
||||
if (value.versionStages() != null) {
|
||||
value.versionStages().forEach(stages::add);
|
||||
}
|
||||
node.set("VersionStages", stages);
|
||||
secretValues.add(node);
|
||||
}
|
||||
response.set("SecretValues", secretValues);
|
||||
return Response.ok(response).build();
|
||||
}
|
||||
|
||||
private Response handleCreateSecret(JsonNode request, String region) {
|
||||
String name = request.path("Name").asText();
|
||||
String secretString = request.has("SecretString") ? request.path("SecretString").asText() : null;
|
||||
|
||||
+46
@@ -263,6 +263,52 @@ public class SecretsManagerService {
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<BatchSecretValue> batchGetSecretValue(List<String> secretIdList, String region) {
|
||||
List<BatchSecretValue> result = new ArrayList<>();
|
||||
if (secretIdList == null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
for (String secretId : secretIdList) {
|
||||
try {
|
||||
Secret secret = resolveSecret(secretId, region);
|
||||
if (secret.getDeletedDate() != null) {
|
||||
continue;
|
||||
}
|
||||
SecretVersion version = findVersionByStage(secret, AWSCURRENT);
|
||||
if (version != null) {
|
||||
result.add(new BatchSecretValue(
|
||||
secret.getArn(),
|
||||
secret.getName(),
|
||||
version.getSecretString(),
|
||||
version.getSecretBinary(),
|
||||
version.getVersionId(),
|
||||
version.getVersionStages(),
|
||||
version.getCreatedDate()
|
||||
));
|
||||
}
|
||||
} catch (AwsException e) {
|
||||
// AWS documentation says: "Secrets Manager doesn't return an error if a secret in the SecretIdList doesn't exist."
|
||||
// Wait, let me re-check that.
|
||||
// Actually, "If any of the secrets in the SecretIdList don't exist, Secrets Manager returns an error."
|
||||
// Let me verify this in the AWS docs.
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public record BatchSecretValue(
|
||||
String arn,
|
||||
String name,
|
||||
String secretString,
|
||||
String secretBinary,
|
||||
String versionId,
|
||||
List<String> versionStages,
|
||||
Instant createdDate
|
||||
) {
|
||||
}
|
||||
|
||||
private Secret resolveSecret(String secretId, String region) {
|
||||
if (secretId.startsWith("arn:")) {
|
||||
List<Secret> found = store.scan(key -> {
|
||||
|
||||
Reference in new issue
Block a user