@@ -21,21 +21,21 @@ import org.slf4j.LoggerFactory
2121 */
2222class PostgresDataSourceWithPasswordFromSecretsManager extends PGSimpleDataSource {
2323
24- protected val logger : Logger = LoggerFactory .getLogger(this .getClass() )
24+ protected val logger : Logger = LoggerFactory .getLogger(this .getClass)
2525
2626 private var password : String = _
2727 private var passwordSecretId : String = _
2828
29- override def getConnection () : Connection = {
29+ override def getConnection : Connection = {
3030 if (Option (password).isEmpty) {
31- val pw = getPasswordFromSecretsManagerOrConfig()
31+ val pw = getPasswordFromSecretsManagerOrConfig
3232 setInternalPassword(pw)
3333 }
3434
3535 val connectionTry = Try (baseGetConnection(user, password)).recoverWith { case _ : SQLException =>
3636 logger.info(" Failed to create Postgres connection, attempting to refresh the password and try again..." )
3737 for {
38- passwordFromSecretsManager <- getPasswordFromSecretsManager()
38+ passwordFromSecretsManager <- getPasswordFromSecretsManager
3939 connection <- Try (baseGetConnection(user, passwordFromSecretsManager)).recoverWith { case e =>
4040 logger.error(" Failed to create Postgres connection even after password refresh" )
4141 Failure (e)
@@ -50,7 +50,7 @@ class PostgresDataSourceWithPasswordFromSecretsManager extends PGSimpleDataSourc
5050 }
5151
5252 // getter and setter for passwordSecretId are needed as this class is usually constructed by reflection
53- def getPasswordSecretId () : String = passwordSecretId
53+ def getPasswordSecretId : String = passwordSecretId
5454
5555 def setPasswordSecretId (passwordSecretId : String ): Unit = {
5656 this .passwordSecretId = passwordSecretId
@@ -72,8 +72,8 @@ class PostgresDataSourceWithPasswordFromSecretsManager extends PGSimpleDataSourc
7272 this .password = password
7373 }
7474
75- private def getPasswordFromSecretsManager () : Try [String ] = {
76- val secretID = getPasswordSecretId()
75+ private def getPasswordFromSecretsManager : Try [String ] = {
76+ val secretID = getPasswordSecretId
7777
7878 val secretValueTry = Try {
7979 logger.info(s " Fetching password for Postgres from Secrets Manager (secret id: $secretID) " )
@@ -92,10 +92,10 @@ class PostgresDataSourceWithPasswordFromSecretsManager extends PGSimpleDataSourc
9292 }
9393 }
9494
95- private def getPasswordFromSecretsManagerOrConfig () : String = {
96- getPasswordFromSecretsManager() .getOrElse {
95+ private def getPasswordFromSecretsManagerOrConfig : String = {
96+ getPasswordFromSecretsManager.getOrElse {
9797 logger.error(
98- s " Failed to fetch password from Secrets Manager (secret id: ${getPasswordSecretId() }). " +
98+ s " Failed to fetch password from Secrets Manager (secret id: ${getPasswordSecretId}). " +
9999 s " Falling back to config value. "
100100 )
101101 val configPassword = ConfigFactory .load().getConfig(" postgres" ).getString(" password" )
0 commit comments