1212 */
1313package com .amazonaws .secretsmanager .caching ;
1414
15+ import java .nio .ByteBuffer ;
16+
1517import com .amazonaws .secretsmanager .caching .cache .LRUCache ;
1618import com .amazonaws .secretsmanager .caching .cache .SecretCacheItem ;
17- import com .amazonaws .services .secretsmanager .AWSSecretsManager ;
18- import com .amazonaws .services .secretsmanager .AWSSecretsManagerClientBuilder ;
19- import com .amazonaws .services .secretsmanager .model .GetSecretValueResult ;
19+ import com .amazonaws .secretsmanager .caching .cache .internal .VersionInfo ;
2020
21- import java .nio .ByteBuffer ;
21+ import software .amazon .awssdk .core .client .config .ClientOverrideConfiguration ;
22+ import software .amazon .awssdk .core .client .config .SdkAdvancedClientOption ;
23+ import software .amazon .awssdk .services .secretsmanager .SecretsManagerClient ;
24+ import software .amazon .awssdk .services .secretsmanager .SecretsManagerClientBuilder ;
25+ import software .amazon .awssdk .services .secretsmanager .model .GetSecretValueResponse ;
2226
2327/**
2428 * Provides the primary entry-point to the AWS Secrets Manager client cache SDK.
@@ -47,58 +51,64 @@ public class SecretCache implements AutoCloseable {
4751 private final SecretCacheConfiguration config ;
4852
4953 /** The AWS Secrets Manager client to use when requesting secrets. */
50- private final AWSSecretsManager client ;
54+ private final SecretsManagerClient client ;
5155
5256 /**
53- * Constructs a new secret cache using the standard AWS Secrets Manager client with default options.
57+ * Constructs a new secret cache using the standard AWS Secrets Manager client
58+ * with default options.
5459 */
5560 public SecretCache () {
56- this (AWSSecretsManagerClientBuilder . standard ());
61+ this (SecretsManagerClient . builder ());
5762 }
5863
59-
6064 /**
61- * Constructs a new secret cache using an AWS Secrets Manager client created using the
65+ * Constructs a new secret cache using an AWS Secrets Manager client created
66+ * using the
6267 * provided builder.
6368 *
64- * @param builder
65- * The builder to use for creating the AWS Secrets Manager client.
69+ * @param builder The builder to use for creating the AWS Secrets Manager
70+ * client.
6671 */
67- public SecretCache (AWSSecretsManagerClientBuilder builder ) {
68- this (null == builder ?
69- AWSSecretsManagerClientBuilder .standard ().build () :
70- builder .build ());
72+ public SecretCache (SecretsManagerClientBuilder builder ) {
73+ this (new SecretCacheConfiguration ().withClient (builder
74+ .overrideConfiguration (
75+ builder .overrideConfiguration ().toBuilder ()
76+ .putAdvancedOption (SdkAdvancedClientOption .USER_AGENT_SUFFIX , VersionInfo .USER_AGENT )
77+ .build ())
78+ .build ()));
7179 }
7280
7381 /**
7482 * Constructs a new secret cache using the provided AWS Secrets Manager client.
7583 *
76- * @param client
77- * The AWS Secrets Manager client to use for requesting secret values.
84+ * @param client The AWS Secrets Manager client to use for requesting secret
85+ * values.
7886 */
79- public SecretCache (AWSSecretsManager client ) {
87+ public SecretCache (SecretsManagerClient client ) {
8088 this (new SecretCacheConfiguration ().withClient (client ));
8189 }
8290
8391 /**
8492 * Constructs a new secret cache using the provided cache configuration.
8593 *
86- * @param config
87- * The secret cache configuration.
94+ * @param config The secret cache configuration.
8895 */
8996 public SecretCache (SecretCacheConfiguration config ) {
90- if (null == config ) { config = new SecretCacheConfiguration (); }
97+ if (null == config ) {
98+ config = new SecretCacheConfiguration ();
99+ }
91100 this .cache = new LRUCache <String , SecretCacheItem >(config .getMaxCacheSize ());
92101 this .config = config ;
93- this .client = config .getClient () != null ? config .getClient () :
94- AWSSecretsManagerClientBuilder .standard ().build ();
102+ ClientOverrideConfiguration defaultOverride = ClientOverrideConfiguration .builder ()
103+ .putAdvancedOption (SdkAdvancedClientOption .USER_AGENT_SUFFIX , VersionInfo .USER_AGENT ).build ();
104+ this .client = config .getClient () != null ? config .getClient ()
105+ : SecretsManagerClient .builder ().overrideConfiguration (defaultOverride ).build ();
95106 }
96107
97108 /**
98109 * Method to retrieve the cached secret item.
99110 *
100- * @param secretId
101- * The identifier for the secret being requested.
111+ * @param secretId The identifier for the secret being requested.
102112 * @return The cached secret item
103113 */
104114 private SecretCacheItem getCachedSecret (final String secretId ) {
@@ -114,39 +124,40 @@ private SecretCacheItem getCachedSecret(final String secretId) {
114124 /**
115125 * Method to retrieve a string secret from AWS Secrets Manager.
116126 *
117- * @param secretId
118- * The identifier for the secret being requested.
127+ * @param secretId The identifier for the secret being requested.
119128 * @return The string secret
120129 */
121130 public String getSecretString (final String secretId ) {
122131 SecretCacheItem secret = this .getCachedSecret (secretId );
123- GetSecretValueResult gsv = secret .getSecretValue ();
124- if (null == gsv ) { return null ; }
125- return gsv .getSecretString ();
132+ GetSecretValueResponse gsv = secret .getSecretValue ();
133+ if (null == gsv ) {
134+ return null ;
135+ }
136+ return gsv .secretString ();
126137 }
127138
128139 /**
129140 * Method to retrieve a binary secret from AWS Secrets Manager.
130141 *
131- * @param secretId
132- * The identifier for the secret being requested.
142+ * @param secretId The identifier for the secret being requested.
133143 * @return The binary secret
134144 */
135145 public ByteBuffer getSecretBinary (final String secretId ) {
136146 SecretCacheItem secret = this .getCachedSecret (secretId );
137- GetSecretValueResult gsv = secret .getSecretValue ();
138- if (null == gsv ) { return null ; }
139- return gsv .getSecretBinary ();
147+ GetSecretValueResponse gsv = secret .getSecretValue ();
148+ if (null == gsv ) {
149+ return null ;
150+ }
151+ return gsv .secretBinary ().asByteBuffer ();
140152 }
141153
142154 /**
143155 * Method to force the refresh of a cached secret state.
144156 *
145- * @param secretId
146- * The identifier for the secret being refreshed.
157+ * @param secretId The identifier for the secret being refreshed.
147158 * @return True if the refresh completed without error.
148- * @throws InterruptedException
149- * If the thread is interrupted while waiting for the refresh.
159+ * @throws InterruptedException If the thread is interrupted while waiting for
160+ * the refresh.
150161 */
151162 public boolean refreshNow (final String secretId ) throws InterruptedException {
152163 SecretCacheItem secret = this .getCachedSecret (secretId );
0 commit comments