in wrapper/src/main/java/software/amazon/jdbc/plugin/AwsSecretsManagerConnectionPlugin.java [244:308]
private boolean updateSecret(final HostSpec hostSpec, final boolean forceReFetch) throws SQLException {
TelemetryFactory telemetryFactory = this.pluginService.getTelemetryFactory();
TelemetryContext telemetryContext = telemetryFactory.openTelemetryContext(
TELEMETRY_UPDATE_SECRETS, TelemetryTraceLevel.NESTED);
this.fetchCredentialsCounter.inc();
try {
boolean fetched = false;
this.secret = AwsSecretsManagerCacheHolder.secretsCache.get(this.secretKey);
if (secret == null || forceReFetch) {
try {
this.secret = fetchLatestCredentials(hostSpec);
if (this.secret != null) {
fetched = true;
AwsSecretsManagerCacheHolder.secretsCache.put(this.secretKey, this.secret);
}
} catch (final SecretsManagerException | JsonProcessingException exception) {
LOGGER.log(
Level.WARNING,
exception,
() -> Messages.get(
"AwsSecretsManagerConnectionPlugin.failedToFetchDbCredentials"));
throw new SQLException(
Messages.get("AwsSecretsManagerConnectionPlugin.failedToFetchDbCredentials"), exception);
} catch (SdkClientException exception) {
LOGGER.log(
Level.WARNING,
exception,
() -> Messages.get(
"AwsSecretsManagerConnectionPlugin.endpointOverrideInvalidConnection",
new Object[] {exception.getMessage()}));
throw new SQLException(
Messages.get("AwsSecretsManagerConnectionPlugin.endpointOverrideInvalidConnection",
new Object[] {exception.getMessage()}), exception);
} catch (Exception exception) {
if (exception.getCause() != null && exception.getCause() instanceof URISyntaxException) {
LOGGER.log(
Level.WARNING,
exception,
() -> Messages.get(
"AwsSecretsManagerConnectionPlugin.endpointOverrideMisconfigured",
new Object[] {exception.getCause().getMessage()}));
throw new RuntimeException(Messages.get("AwsSecretsManagerConnectionPlugin.endpointOverrideMisconfigured",
new Object[] {exception.getCause().getMessage()}));
}
LOGGER.log(
Level.WARNING,
exception,
() -> Messages.get(
"AwsSecretsManagerConnectionPlugin.unhandledException",
new Object[] {exception.getMessage()}));
throw new SQLException(exception);
}
}
return fetched;
} catch (Exception ex) {
telemetryContext.setSuccess(false);
telemetryContext.setException(ex);
throw ex;
} finally {
telemetryContext.closeContext();
}
}