Search in sources :

Example 6 with SecretsManagerClient

use of software.amazon.awssdk.services.secretsmanager.SecretsManagerClient in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method buildSecretsManagerClient.

protected SecretsManagerClient buildSecretsManagerClient() {
    Region region = Region.of(awsRegion);
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    return secretsClient;
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 7 with SecretsManagerClient

use of software.amazon.awssdk.services.secretsmanager.SecretsManagerClient in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method updateSecretValue.

@Override
public void updateSecretValue(String awsKeyName, boolean useKfsInstanceNamespace, String keyValue) {
    createCacheIfNotPresent();
    String fullAwsKey = buildFullAwsKeyName(awsKeyName, useKfsInstanceNamespace);
    UpdateSecretRequest updateSecretRequest = UpdateSecretRequest.builder().secretId(fullAwsKey).secretString(keyValue).build();
    SecretsManagerClient client = buildSecretsManagerClient();
    try {
        performUpdate(updateSecretRequest, client);
        updateCacheValue(fullAwsKey, keyValue);
    } catch (SecretsManagerException e) {
        LOG.error("updateSecretValue, had an error setting value for secret " + fullAwsKey, e);
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient) UpdateSecretRequest(software.amazon.awssdk.services.secretsmanager.model.UpdateSecretRequest)

Example 8 with SecretsManagerClient

use of software.amazon.awssdk.services.secretsmanager.SecretsManagerClient in project cu-kfs by CU-CommunityApps.

the class AwsSecretServiceImpl method retrieveSecretFromAws.

protected String retrieveSecretFromAws(String fullAwsKey) {
    SecretsManagerClient client = buildSecretsManagerClient();
    try {
        GetSecretValueRequest valueRequest = GetSecretValueRequest.builder().secretId(fullAwsKey).build();
        GetSecretValueResponse valueResponse = client.getSecretValue(valueRequest);
        return valueResponse.secretString();
    } catch (SecretsManagerException e) {
        LOG.error("retrieveSecretFromAws, had an error getting value for secret " + fullAwsKey, e);
        throw new RuntimeException(e);
    } finally {
        client.close();
    }
}
Also used : SecretsManagerException(software.amazon.awssdk.services.secretsmanager.model.SecretsManagerException) GetSecretValueRequest(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueRequest) GetSecretValueResponse(software.amazon.awssdk.services.secretsmanager.model.GetSecretValueResponse) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 9 with SecretsManagerClient

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

the class AWSSecretManager method createSecret.

public static void createSecret(String secretName, Object secretValue, String network, Region region, boolean binarySecret) {
    removeBouncyCastleSecurityProvider();
    SecretsManagerClient secretsClient = SecretsManagerClient.builder().region(region).build();
    String secretARN = createNewSecret(secretsClient, secretName, secretValue, network, binarySecret);
    System.out.println("Secret created with ARN " + secretARN);
    secretsClient.close();
}
Also used : SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

Example 10 with SecretsManagerClient

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

the class DescribeSecret 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();
    describeGivenSecret(secretsClient, secretName);
    secretsClient.close();
}
Also used : Region(software.amazon.awssdk.regions.Region) SecretsManagerClient(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient)

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