Search in sources :

Example 1 with CreateSecretRequest

use of com.amazonaws.services.secretsmanager.model.CreateSecretRequest 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 CreateSecretRequest

use of com.amazonaws.services.secretsmanager.model.CreateSecretRequest 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

CreateSecretRequest (com.amazonaws.services.secretsmanager.model.CreateSecretRequest)2 ResourceExistsException (com.amazonaws.services.secretsmanager.model.ResourceExistsException)2 AWSSecretsManager (com.amazonaws.services.secretsmanager.AWSSecretsManager)1 PutSecretValueRequest (com.amazonaws.services.secretsmanager.model.PutSecretValueRequest)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 SecretExistsException (io.datarouter.secret.exception.SecretExistsException)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