Search in sources :

Example 1 with ResourceExistsException

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);
    }
}
Also used : ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) CreateSecretRequest(com.amazonaws.services.secretsmanager.model.CreateSecretRequest) SecretExistsException(io.datarouter.secret.exception.SecretExistsException)

Example 2 with ResourceExistsException

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);
    }
}
Also used : ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) ResourceNotFoundException(com.amazonaws.services.secretsmanager.model.ResourceNotFoundException) SecretNotFoundException(io.datarouter.secret.exception.SecretNotFoundException) SecretExistsException(io.datarouter.secret.exception.SecretExistsException) UpdateSecretRequest(com.amazonaws.services.secretsmanager.model.UpdateSecretRequest)

Example 3 with ResourceExistsException

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);
    }
}
Also used : Arrays(java.util.Arrays) Component(org.springframework.stereotype.Component) SneakyThrows(lombok.SneakyThrows) CreateSecretRequest(com.amazonaws.services.secretsmanager.model.CreateSecretRequest) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AWSSecretsManager(com.amazonaws.services.secretsmanager.AWSSecretsManager) ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) AllArgsConstructor(lombok.AllArgsConstructor) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PutSecretValueRequest(com.amazonaws.services.secretsmanager.model.PutSecretValueRequest) ResourceExistsException(com.amazonaws.services.secretsmanager.model.ResourceExistsException) CreateSecretRequest(com.amazonaws.services.secretsmanager.model.CreateSecretRequest) SneakyThrows(lombok.SneakyThrows)

Aggregations

ResourceExistsException (com.amazonaws.services.secretsmanager.model.ResourceExistsException)3 CreateSecretRequest (com.amazonaws.services.secretsmanager.model.CreateSecretRequest)2 SecretExistsException (io.datarouter.secret.exception.SecretExistsException)2 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)1 PutSecretValueRequest (com.amazonaws.services.secretsmanager.model.PutSecretValueRequest)1 ResourceNotFoundException (com.amazonaws.services.secretsmanager.model.ResourceNotFoundException)1 UpdateSecretRequest (com.amazonaws.services.secretsmanager.model.UpdateSecretRequest)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SecretNotFoundException (io.datarouter.secret.exception.SecretNotFoundException)1 Arrays (java.util.Arrays)1 Map (java.util.Map)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 AllArgsConstructor (lombok.AllArgsConstructor)1 SneakyThrows (lombok.SneakyThrows)1 Component (org.springframework.stereotype.Component)1