Search in sources :

Example 1 with CreateSecretResponse

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

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

Aggregations

CreateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest)2 CreateSecretResponse (software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse)2 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)1 Tag (software.amazon.awssdk.services.secretsmanager.model.Tag)1