Augustin
Augustin

Reputation: 25

AWS Secrets Manager SDK Java 2.x with Redhat Fuse 7.13

I have a legacy fuse utility bundle which has a code logic to get secret code with AWS SDK Java 1,Now I am trying to convert them to use AWS SDK Java-2.30.3. I have added the secretmanager dependency and updated the bundle configuration to import these packages as optional. But during runtime the below class is not available. How to resolve this issue , with minimal changes.

I am not able to find any inbuilt feature is available in Redhat Fuse.

Caused by: java.lang.NoClassDefFoundError: software/amazon/awssdk/services/secretsmanager/SecretsManagerClient

<dependency>
    <groupId>software.amazon.awssdk</groupId>
    <artifactId>secretsmanager</artifactId>
    <version>2.30.3</version>
    <scope>compile</scope>
</dependency>
public static String getSecret(String region, String secretARN) throws Exception {
    String secretStr = null;

    // Create Secrets Manager client
    try (SecretsManagerClient client = SecretsManagerClient.builder()
            .credentialsProvider(InstanceProfileCredentialsProvider.create())
            .region(Region.of(region))
            .build()) {

        // Create GetSecretValueRequest
        GetSecretValueRequest request = GetSecretValueRequest.builder()
                .secretId(secretARN)
                .build();

        // Fetch secret value
        GetSecretValueResponse response = client.getSecretValue(request);
        secretStr = response.secretString();
    } catch (Exception e) {
        throw new Exception("Error retrieving secret from AWS Secrets Manager", e);
    }
    return secretStr;
}

Upvotes: 0

Views: 52

Answers (1)

Augustin
Augustin

Reputation: 25

  1. I have created a custom feature in fuse with all SecretsManager SDK2 related jars.
  2. Added this feature in org.apache.karaf.features.cfg config file.
# Comma separated list of features to install at startup
#
featuresRepositories = \
    file:///{fusedirectory}/etc/custom-features.xml, \
    ...
featuresBoot = \
    custom-features, \
    secretsmanager-feature, \
    ...

custom-features.xml

<features name ="custom-features" xmlns="http://karaf.apache.org/xmlns/features/v1.4.0">
    <feature name="secretsmanager-feature" version="1.0.0">
        <bundle>wrap:file:///{fusedirectory}/custom_lib/secretsmanager-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/apache-client-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/auth-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/aws-core-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/aws-json-protocol-2.20.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/checksums-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/checksums-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/endpoints-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/http-auth-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/http-auth-aws-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/http-auth-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/http-client-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/identity-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/json-utils-2.20.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/metrics-spi-2.20.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/profiles-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/protocol-core-2.20.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/reactive-streams-1.0.4.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/regions-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/retries-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/retries-spi-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/sdk-core-2.30.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/third-party-jackson-core-2.20.3.jar</bundle>
        <bundle>wrap:file:///{fusedirectory}/custom_lib/utils-2.30.3.jar</bundle>
    </feature>
</features>

Upvotes: 0

Related Questions