Skip to content

Commit

Permalink
Add AWS_SESSION_TOKEN to Fusion environment (#4581)
Browse files Browse the repository at this point in the history
Signed-off-by: Jordi Deu-Pons <[email protected]>
  • Loading branch information
jordeu authored and pditommaso committed Dec 17, 2023
1 parent c6a7f30 commit 0003b39
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class AwsFusionEnv implements FusionEnv {
if( creds ) {
result.AWS_ACCESS_KEY_ID = creds[0]
result.AWS_SECRET_ACCESS_KEY = creds[1]

if( creds.size() > 2 )
result.AWS_SESSION_TOKEN = creds[2]
}
if( endpoint )
result.AWS_S3_ENDPOINT = endpoint
Expand All @@ -59,6 +62,10 @@ class AwsFusionEnv implements FusionEnv {
final result = awsConfig.getCredentials()
if( result )
return result

if( SysEnv.get('AWS_ACCESS_KEY_ID') && SysEnv.get('AWS_SECRET_ACCESS_KEY') && SysEnv.get('AWS_SESSION_TOKEN') )
return List.<String>of(SysEnv.get('AWS_ACCESS_KEY_ID'), SysEnv.get('AWS_SECRET_ACCESS_KEY'), SysEnv.get('AWS_SESSION_TOKEN'))

if( SysEnv.get('AWS_ACCESS_KEY_ID') && SysEnv.get('AWS_SECRET_ACCESS_KEY') )
return List.<String>of(SysEnv.get('AWS_ACCESS_KEY_ID'), SysEnv.get('AWS_SECRET_ACCESS_KEY'))
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,28 @@ class AwsFusionEnvTest extends Specification {
cleanup:
Global.config = null
}

def 'should return env environment with session token' () {
given:
SysEnv.push([AWS_ACCESS_KEY_ID: 'x1', AWS_SECRET_ACCESS_KEY: 'y1', AWS_S3_ENDPOINT: 'http://my-host.com', AWS_SESSION_TOKEN: 'z1'])
and:

when:
def config = Mock(FusionConfig)
def env = new AwsFusionEnv().getEnvironment('s3', Mock(FusionConfig))
then:
env == [AWS_S3_ENDPOINT:'http://my-host.com']

when:
config = Mock(FusionConfig) { exportStorageCredentials() >> true }
env = new AwsFusionEnv().getEnvironment('s3', config)
then:
env == [AWS_ACCESS_KEY_ID: 'x1',
AWS_SECRET_ACCESS_KEY: 'y1',
AWS_S3_ENDPOINT:'http://my-host.com',
AWS_SESSION_TOKEN: 'z1']

cleanup:
SysEnv.pop()
}
}

0 comments on commit 0003b39

Please sign in to comment.