From b920738d7a97ddfcf3dfe2e20b89bebabdae279b Mon Sep 17 00:00:00 2001 From: Tim Underwood Date: Fri, 7 Apr 2017 10:01:42 -0700 Subject: [PATCH] For the Role Based Credential Providers if there is no roleArn then return null to avoid creating a AWSSecurityTokenServiceClient which is slow --- src/main/scala/fm/sbt/S3URLHandler.scala | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/scala/fm/sbt/S3URLHandler.scala b/src/main/scala/fm/sbt/S3URLHandler.scala index 077d622..29b69aa 100644 --- a/src/main/scala/fm/sbt/S3URLHandler.scala +++ b/src/main/scala/fm/sbt/S3URLHandler.scala @@ -80,10 +80,14 @@ object S3URLHandler { protected def getRoleArn(keys: String*): String def getCredentials(): AWSCredentials = { + val roleArn: String = getRoleArn(RoleArnKeyNames: _*) + + if (roleArn == null || roleArn == "") return null + val securityTokenService: AWSSecurityTokenService = AWSSecurityTokenServiceClient.builder().withCredentials(providerChain).build() val roleRequest: AssumeRoleRequest = new AssumeRoleRequest() - .withRoleArn(getRoleArn(RoleArnKeyNames: _*)) + .withRoleArn(roleArn) .withRoleSessionName(System.currentTimeMillis.toString) val result: AssumeRoleResult = securityTokenService.assumeRole(roleRequest) @@ -100,7 +104,7 @@ object S3URLHandler { val RoleArnKeyName: String = "aws.roleArn" val RoleArnKeyNames: Seq[String] = Seq(RoleArnKeyName) - protected def getRoleArn(keys: String*) = keys.map( System.getProperty ).flatMap( Option(_) ).head.trim + protected def getRoleArn(keys: String*): String = keys.map( System.getProperty ).flatMap( Option(_) ).head.trim } private class RoleBasedEnvironmentVariableCredentialsProvider(providerChain: AWSCredentialsProviderChain) @@ -109,7 +113,7 @@ object S3URLHandler { val RoleArnKeyName: String = "AWS_ROLE_ARN" val RoleArnKeyNames: Seq[String] = Seq("AWS_ROLE_ARN") - protected def getRoleArn(keys: String*) = keys.map( toEnvironmentVariableName ).map( System.getenv ).flatMap( Option(_) ).head.trim + protected def getRoleArn(keys: String*): String = keys.map( toEnvironmentVariableName ).map( System.getenv ).flatMap( Option(_) ).head.trim } private class RoleBasedPropertiesFileCredentialsProvider(providerChain: AWSCredentialsProviderChain, fileName: String)