Class CachableSecretsManager
- java.lang.Object
-
- com.amazonaws.athena.connector.lambda.security.CachableSecretsManager
-
public class CachableSecretsManager extends Object
Since Athena may call your connector or UDF at a high TPS or concurrency you may want to have a short lived cache in front of SecretsManager to avoid bottlenecking on SecretsManager. This class offers such a cache. This class also has utilities for idetifying and replacing secrets in scripts. For example: MyString${WithSecret} would have ${WithSecret} replaced by the corresponding value of the secret in AWS Secrets Manager with that name.
-
-
Field Summary
Fields Modifier and Type Field Description protected static int
MAX_CACHE_SIZE
-
Constructor Summary
Constructors Constructor Description CachableSecretsManager(software.amazon.awssdk.services.secretsmanager.SecretsManagerClient secretsManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addCacheEntry(String name, String value, long createTime)
String
getSecret(String secretName)
Retrieves a secret from SecretsManager, first checking the cache.String
resolveSecrets(String rawString)
Resolves any secrets found in the supplied string, for example: MyString${WithSecret} would have ${WithSecret} repalced by the corresponding value of the secret in AWS Secrets Manager with that name.
-
-
-
Field Detail
-
MAX_CACHE_SIZE
protected static final int MAX_CACHE_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
resolveSecrets
public String resolveSecrets(String rawString)
Resolves any secrets found in the supplied string, for example: MyString${WithSecret} would have ${WithSecret} repalced by the corresponding value of the secret in AWS Secrets Manager with that name. If no such secret is found the function throws.- Parameters:
rawString
- The string in which to find and replace/inject secrets.- Returns:
- The processed rawString that has had all secrets replaced with their secret value from SecretsManager. Throws if any of the secrets can not be found.
-
getSecret
public String getSecret(String secretName)
Retrieves a secret from SecretsManager, first checking the cache. Newly fetched secrets are added to the cache.- Parameters:
secretName
- The name of the secret to retrieve.- Returns:
- The value of the secret, throws if no such secret is found.
-
-