in jetbrains-ultimate/src/software/aws/toolkits/jetbrains/datagrip/auth/SecretsManagerAuth.kt [50:92]
override fun intercept(
connection: ProtoConnection,
silent: Boolean
): CompletionStage<ProtoConnection>? {
LOG.info { "Intercepting db connection [$connection]" }
val scope = projectCoroutineScope(connection.runConfiguration.project)
return scope.future {
var result = Result.Succeeded
val project = connection.runConfiguration.project
try {
val connectionSettings = getConfiguration(connection)
val dbSecret = getDbSecret(connectionSettings)
if (
connection.connectionPoint.dataSource.sshConfiguration?.isEnabled != true &&
connection.connectionPoint.additionalJdbcProperties[GET_URL_FROM_SECRET]?.toBoolean() == true
) {
dbSecret.host ?: throw IllegalArgumentException(message("datagrip.secretsmanager.validation.no_host", connectionSettings.secretId))
dbSecret.port ?: throw IllegalArgumentException(message("datagrip.secretsmanager.validation.no_port", connectionSettings.secretId))
// we have to rewrite the url which is pretty messy. The util is not better than using split (requires magic strings
// to access the properties), so use split instead
val db = connection.url.split("/").last()
val jdbcUrlBeginning = connection.url.split("://").first()
connection.url = "$jdbcUrlBeginning://${dbSecret.host}:${dbSecret.port}/$db"
}
DatabaseCredentialsAuthProvider.applyCredentials(
connection,
Credentials(dbSecret.username, dbSecret.password),
true
)
} catch (e: Throwable) {
result = Result.Failed
throw e
} finally {
val engine = connection.getDatabaseEngine()
if (engine == "redshift") {
RedshiftTelemetry.getCredentials(project, result, SecretsManager)
} else {
RdsTelemetry.getCredentials(project, result, SecretsManager, engine)
}
}
}
}