Search in sources :

Example 1 with SecretsManagerClient

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

the class CreateSecret method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <secretName> <secretValue> \n\n" + "Where:\n" + "    secretName - the name of the secret (for example, tutorials/MyFirstSecret). \n" + "    secretValue - the secret value. \n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String secretName = args[0];
    String secretValue = args[1];
    Region region = Region.US_EAST_1;
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    String secretARN = createNewSecret(secretsClient, secretName, secretValue);
    System.out.println("The secret ARN is " + secretARN);
    secretsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 2 with SecretsManagerClient

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

the class ListSecrets method main.

public static void main(String[] args) {
    Region region = Region.US_EAST_1;
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    listAllSecrets(secretsClient);
    secretsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 3 with SecretsManagerClient

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

the class DeleteSecret method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "     <secretName> \n\n" + "Where:\n" + "    secretName - the name of the secret (for example, tutorials/MyFirstSecret). \n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String secretName = args[0];
    Region region = Region.US_EAST_1;
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    deleteSpecificSecret(secretsClient, secretName);
    secretsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 4 with SecretsManagerClient

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

the class GetSecretValue method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    <secretName> \n\n" + "Where:\n" + "    secretName - the name of the secret (for example, tutorials/MyFirstSecret). \n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String secretName = args[0];
    Region region = Region.US_EAST_1;
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    getValue(secretsClient, secretName);
    secretsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 5 with SecretsManagerClient

use of software.amazon.awssdk.services.secretsmanager.SecretsManagerClient in project spring-cloud-aws by awspring.

the class SecretsManagerConfigDataLoaderIntegrationTests method secretsManagerClientCanBeOverwrittenInBootstrapConfig.

@Test
void secretsManagerClientCanBeOverwrittenInBootstrapConfig() {
    SecretsManagerClient mockClient = mock(SecretsManagerClient.class);
    when(mockClient.getSecretValue(any(GetSecretValueRequest.class))).thenReturn(GetSecretValueResponse.builder().name("secrets").secretString("{\"message\":\"value from mock\"}").build());
    SpringApplication application = new SpringApplication(App.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    application.addBootstrapRegistryInitializer(registry -> {
        registry.register(SecretsManagerClient.class, ctx -> mockClient);
    });
    try (ConfigurableApplicationContext context = runApplication(application, "aws-secretsmanager:/config/spring")) {
        SecretsManagerClient clientFromContext = context.getBean(SecretsManagerClient.class);
        assertThat(clientFromContext).isEqualTo(mockClient);
        assertThat(context.getEnvironment().getProperty("message")).isEqualTo("value from mock");
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient) Test(org.junit.jupiter.api.Test)

Aggregations

SecretsManagerClient (software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)18 Region (software.amazon.awssdk.regions.Region)7 GetSecretValueRequest (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest)3 GetSecretValueResponse (software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse)2 SecretsManagerException (software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException)2 SecretsManagerPropertySource (io.awspring.cloud.secretsmanager.SecretsManagerPropertySource)1 Test (org.junit.jupiter.api.Test)1 SpringApplication (org.springframework.boot.SpringApplication)1 ConfigData (org.springframework.boot.context.config.ConfigData)1 ConfigDataResourceNotFoundException (org.springframework.boot.context.config.ConfigDataResourceNotFoundException)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1 Nullable (org.springframework.lang.Nullable)1 AwsBasicCredentials (software.amazon.awssdk.auth.credentials.AwsBasicCredentials)1 StaticCredentialsProvider (software.amazon.awssdk.auth.credentials.StaticCredentialsProvider)1 SdkBytes (software.amazon.awssdk.core.SdkBytes)1 SecretsManagerClientBuilder (software.amazon.awssdk.services.secretsmanager.SecretsManagerClientBuilder)1 UpdateSecretRequest (software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest)1