Search in sources :

Example 1 with ResourceNotFoundException

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

the class AWSVaultServiceImpl method get.

@Override
public Uni<EventBridgeSecret> get(String name) {
    if (CACHE.containsKey(name)) {
        LOGGER.debug("Secret '{}' found in the cache.", name);
        return Uni.createFrom().item(CACHE.get(name));
    }
    return Uni.createFrom().future(asyncClient.getSecretValue(GetSecretValueRequest.builder().secretId(name).build())).onFailure(e -> !(e instanceof ResourceNotFoundException)).retry().withJitter(DEFAULT_JITTER).withBackOff(DEFAULT_BACKOFF).atMost(MAX_RETRIES).onFailure().transform(e -> new VaultException("Secret '%s' not found in AWS Vault", e)).flatMap(x -> {
        LOGGER.debug("Secret '{}' found in AWS Vault", name);
        EventBridgeSecret secret = new EventBridgeSecret().setId(name).setValues(Json.decodeValue(x.secretString(), Map.class));
        CACHE.put(name, secret);
        return Uni.createFrom().item(secret);
    });
}
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) ResourceNotFoundException(software.amazon.awssdk.services.secretsmanager.model.ResourceNotFoundException) EventBridgeSecret(com.redhat.service.bridge.infra.models.EventBridgeSecret) Map(java.util.Map)

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