use of com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException 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());
});
}
use of com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException 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);
});
}
use of com.redhat.service.bridge.infra.exceptions.definitions.platform.VaultException in project sandbox by 5733d9e2be6485d52ffa08870cabdee0.
the class AWSVaultServiceImpl method replaceSecret.
private Uni<Void> replaceSecret(EventBridgeSecret secret) {
LOGGER.debug("Secret '{}' already exists in AWS Vault. Replacing..", secret.getId());
PutSecretValueRequest putSecretValueRequest = PutSecretValueRequest.builder().secretId(secret.getId()).secretString(Json.encode(secret.getValues())).build();
return Uni.createFrom().future(asyncClient.putSecretValue(putSecretValueRequest)).replaceWithVoid().onFailure().retry().withJitter(DEFAULT_JITTER).withBackOff(DEFAULT_BACKOFF).atMost(MAX_RETRIES).onFailure().transform(e -> new VaultException("Could not replace secret '%s' in AWS Vault", e)).invoke(() -> LOGGER.debug("Secret '{}' replaced", secret.getId()));
}
Aggregations