Search in sources :

Example 1 with CreateSecretRequest

use of software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest in project aws-doc-sdk-examples by awsdocs.

the class CreateSecret method createNewSecret.

// snippet-start:[secretsmanager.java2.create_secret.main]
public static String createNewSecret(SecretsManagerClient secretsClient, String secretName, String secretValue) {
    try {
        CreateSecretRequest secretRequest = CreateSecretRequest.builder().name(secretName).description("This secret was created by the AWS Secret Manager Java API").secretString(secretValue).build();
        CreateSecretResponse secretResponse = secretsClient.createSecret(secretRequest);
        return secretResponse.arn();
    } catch (SecretsManagerException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
    return "";
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest) CreateSecretResponse(software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)

Example 2 with CreateSecretRequest

use of software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest in project radixdlt by radixdlt.

the class AWSSecretManager method createNewSecret.

private static String createNewSecret(SecretsManagerClient secretsClient, String secretName, Object secretValue, String network, boolean binarySecret) {
    List<Tag> tagList = buildTags(network, secretName);
    CreateSecretRequest secretRequest;
    if (binarySecret) {
        secretRequest = CreateSecretRequest.builder().name(secretName).description("Validator keys").secretBinary((SdkBytes) secretValue).tags(tagList).build();
    } else {
        secretRequest = CreateSecretRequest.builder().name(secretName).description("Validator keys").secretString((String) secretValue).tags(tagList).build();
    }
    CreateSecretResponse secretResponse = secretsClient.createSecret(secretRequest);
    return secretResponse.arn();
}
Also used : SdkBytes(software.amazon.awssdk.core.SdkBytes) CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest) Tag(software.amazon.awssdk.services.secretsmanager.model.Tag) CreateSecretResponse(software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)

Example 3 with CreateSecretRequest

use of software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest 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)

Example 4 with CreateSecretRequest

use of software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest in project web3signer by ConsenSys.

the class AwsSecretsManagerUtil method createSecret.

public String createSecret(String secretValue) {
    secretName = "signers-aws-integration/" + UUID.randomUUID();
    final CreateSecretRequest secretRequest = CreateSecretRequest.builder().name(secretName).secretString(secretValue).build();
    secretsManagerClient.createSecret(secretRequest);
    return secretName;
}
Also used : CreateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)

Aggregations

CreateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)4 CreateSecretResponse (software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)2 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 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 SecretsManagerAsyncClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerAsyncClient)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