|
20 | 20 | * #L%
|
21 | 21 | */
|
22 | 22 |
|
| 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; |
23 | 26 | import com.amazonaws.services.secretsmanager.AWSSecretsManager;
|
24 | 27 | import com.amazonaws.services.secretsmanager.model.GetSecretValueRequest;
|
25 | 28 | import com.amazonaws.services.secretsmanager.model.GetSecretValueResult;
|
| 29 | +import com.amazonaws.services.secretsmanager.model.ResourceNotFoundException; |
26 | 30 | import org.apache.arrow.util.VisibleForTesting;
|
27 | 31 | import org.slf4j.Logger;
|
28 | 32 | import org.slf4j.LoggerFactory;
|
@@ -93,15 +97,21 @@ public String resolveSecrets(String rawString)
|
93 | 97 | */
|
94 | 98 | public String getSecret(String secretName)
|
95 | 99 | {
|
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())); |
105 | 115 | }
|
106 | 116 |
|
107 | 117 | return cacheEntry.getValue();
|
|
0 commit comments