Search in sources :

Example 1 with ResourceExistsException

use of software.amazon.awssdk.services.secretsmanager.model.ResourceExistsException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.

the class AWSVaultServiceImpl method createOrReplace.

@Override
public Uni<Void> createOrReplace(EventBridgeSecret secret) {
    CreateSecretRequest createSecretRequest = CreateSecretRequest.builder().name(secret.getId()).secretString(Json.encode(secret.getValues())).build();
    return Uni.createFrom().future(asyncClient.createSecret(createSecretRequest)).replaceWithVoid().onFailure(e -> !(e instanceof ResourceExistsException)).retry().withJitter(DEFAULT_JITTER).withBackOff(DEFAULT_BACKOFF).atMost(MAX_RETRIES).onFailure(ResourceExistsException.class).recoverWithUni(() -> replaceSecret(secret)).onFailure().transform(e -> new VaultException("Could not replace secret '%s' in AWS Vault", e)).invoke(() -> {
        CACHE.put(secret.getId(), secret);
        LOGGER.debug("Secret '{}' created in AWS Vault", secret.getId());
    });
}
Also used : ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException) Json(io.vertx.core.json.Json) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest) PutSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.PutSecretValueRequest) ResourceExistsException(software.amazon.awssdk.services.secretsmanager.model.ResourceExistsException) Uni(io.smallrye.mutiny.Uni) DeleteSecretRequest(software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest) Inject(javax.inject.Inject) SecretsManagerAsyncClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient) Duration(java.time.Duration) Map(java.util.Map) ApplicationScoped(javax.enterprise.context.ApplicationScoped) EventBridgeSecret(com.redhat.service.bridge.infra.models.EventBridgeSecret) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) VaultException(com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException) LRUCache(io.vertx.ext.web.impl.LRUCache) VaultException(com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException) ResourceExistsException(software.amazon.awssdk.services.secretsmanager.model.ResourceExistsException) CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)

Aggregations

VaultException (com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException)1 EventBridgeSecret (com.redhat.service.bridge.infra.models.EventBridgeSecret)1 Uni (io.smallrye.mutiny.Uni)1 Json (io.vertx.core.json.Json)1 LRUCache (io.vertx.ext.web.impl.LRUCache)1 Duration (java.time.Duration)1 Map (java.util.Map)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Inject (javax.inject.Inject)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 SecretsManagerAsyncClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient)1 CreateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)1 DeleteSecretRequest (software.amazon.awssdk.services.secretsmanager.model.DeleteSecretRequest)1 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)1 PutSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.PutSecretValueRequest)1 ResourceExistsException (software.amazon.awssdk.services.secretsmanager.model.ResourceExistsException)1 ResourceNotFoundException (software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException)1