Skip to content

Commit f3cfdc5

Browse files
committed
exception handling for sdk
1 parent 10d2be6 commit f3cfdc5

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

athena-federation-sdk/src/main/java/com/amazonaws/athena/connector/lambda/security/CachableSecretsManager.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@
2020
* #L%
2121
*/
2222

23+
import com.amazonaws.athena.connector.lambda.exceptions.AthenaConnectorException;
24+
import com.amazonaws.services.glue.model.ErrorDetails;
25+
import com.amazonaws.services.glue.model.FederationSourceErrorCode;
2326
import com.amazonaws.services.secretsmanager.AWSSecretsManager;
2427
import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
2528
import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
29+
import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException;
2630
import org.apache.arrow.util.VisibleForTesting;
2731
import org.slf4j.Logger;
2832
import org.slf4j.LoggerFactory;
@@ -93,15 +97,21 @@ public String resolveSecrets(String rawString)
9397
*/
9498
public String getSecret(String secretName)
9599
{
96-
CacheEntry cacheEntry = cache.get(secretName);
97-
98-
if (cacheEntry == null || cacheEntry.getAge() > MAX_CACHE_AGE_MS) {
99-
logger.info("getSecret: Resolving secret[{}].", secretName);
100-
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest()
101-
.withSecretId(secretName));
102-
cacheEntry = new CacheEntry(secretName, secretValueResult.getSecretString());
103-
evictCache(cache.size() >= MAX_CACHE_SIZE);
104-
cache.put(secretName, cacheEntry);
100+
CacheEntry cacheEntry = null;
101+
try {
102+
cacheEntry = cache.get(secretName);
103+
104+
if (cacheEntry == null || cacheEntry.getAge() > MAX_CACHE_AGE_MS) {
105+
logger.info("getSecret: Resolving secret[{}].", secretName);
106+
GetSecretValueResult secretValueResult = secretsManager.getSecretValue(new GetSecretValueRequest()
107+
.withSecretId(secretName));
108+
cacheEntry = new CacheEntry(secretName, secretValueResult.getSecretString());
109+
evictCache(cache.size() >= MAX_CACHE_SIZE);
110+
cache.put(secretName, cacheEntry);
111+
}
112+
}
113+
catch (ResourceNotFoundException e) {
114+
throw new AthenaConnectorException(e.getMessage(), new ErrorDetails().withErrorCode(FederationSourceErrorCode.EntityNotFoundException.toString()));
105115
}
106116

107117
return cacheEntry.getValue();

0 commit comments

Comments
 (0)