Skip to content

Commit

Permalink
For the Role Based Credential Providers if there is no roleArn then r…
Browse files Browse the repository at this point in the history
…eturn null to avoid creating a AWSSecurityTokenServiceClient which is slow
  • Loading branch information
tpunder committed Apr 7, 2017
1 parent 9849ed9 commit b920738
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/scala/fm/sbt/S3URLHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit b920738

Please sign in to comment.