use of com.amazonaws.services.secretsmanager.model.ResourceExistsException in project datarouter by hotpads.
the class AwsSecretClient method create.
@Override
public final void create(Secret secret) {
var request = new CreateSecretRequest().withName(secret.getName()).withSecretString(secret.getValue());
try {
try (var $ = TracerTool.startSpan("AWSSecretsManager createSecret", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(secret.getName());
client.createSecret(request);
}
} catch (ResourceExistsException e) {
throw new SecretExistsException(secret.getName(), e);
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceExistsException in project datarouter by hotpads.
the class AwsSecretClient method update.
@Override
public final void update(Secret secret) {
// this can update various stuff (like description and kms key) AND updates the version stage to AWSCURRENT.
// for rotation, use PutSecretValue, which only updates the version stages and value of a secret explicitly
var request = new UpdateSecretRequest().withSecretId(secret.getName()).withSecretString(secret.getValue());
try {
try (var $ = TracerTool.startSpan("AWSSecretsManager updateSecret", TraceSpanGroupType.CLOUD_STORAGE)) {
TracerTool.appendToSpanInfo(secret.getName());
client.updateSecret(request);
}
} catch (ResourceExistsException e) {
throw new SecretExistsException("Requested update already exists.", secret.getName(), e);
} catch (ResourceNotFoundException e) {
throw new SecretNotFoundException(secret.getName(), e);
}
}
use of com.amazonaws.services.secretsmanager.model.ResourceExistsException in project JAQU-CAZ-Payments-API by InformedSolutions.
the class SecretsManagerInitialisation method createSecret.
@SneakyThrows
public void createSecret(String secretName, String apiKey, String... cleanAirZoneId) {
Map<String, String> apiKeysMap = Arrays.asList(cleanAirZoneId).stream().map(cazId -> cazId.replace("-", "")).collect(Collectors.toMap(Function.identity(), string -> apiKey));
String secretString = objectMapper.writeValueAsString(apiKeysMap);
try {
CreateSecretRequest createSecretRequest = new CreateSecretRequest().withName(secretName).withSecretString(secretString);
secretsManager.createSecret(createSecretRequest);
} catch (ResourceExistsException e) {
PutSecretValueRequest putSecretValueRequest = new PutSecretValueRequest();
putSecretValueRequest.withSecretId(secretName).withSecretString(secretString);
secretsManager.putSecretValue(putSecretValueRequest);
}
}
Aggregations