Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions aws.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ component {
string defaultRegion = '',
struct constructorArgs = { },
struct httpProxy = { server: '', port: 80 },
string libraryMapping = ''
string libraryMapping = '',
string token = ''
) {
if ( len( arguments.libraryMapping ) && mid( arguments.libraryMapping, len( arguments.libraryMapping ), 1 ) != '.' ) {
arguments.libraryMapping &= '.';
Expand All @@ -65,7 +66,8 @@ component {
awsSecretKey,
defaultRegion,
httpProxy,
libraryMapping
libraryMapping,
token
);

for ( var service in variables.services ) {
Expand Down
5 changes: 3 additions & 2 deletions com/api.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ component accessors="true" {
required string awsKey,
required string awsSecretKey,
required string defaultRegion,
struct httpProxy = { server: '', port: 80 }
struct httpProxy = { server: '', port: 80 },
string token = ''
) {
variables.utils = new utils();
variables.httpService = server.keyExists( 'lucee' ) ? new httpLucee( utils, httpProxy ) : new httpColdFusion( utils, httpProxy );
variables.credentials = new credentials( awsKey, awsSecretKey, this );
variables.credentials = new credentials( awsKey, awsSecretKey, this, token );
variables.signer = new signature_v4( this );
variables.defaultRegion = arguments.defaultRegion.len() ? arguments.defaultRegion : utils.getSystemSetting(
'AWS_DEFAULT_REGION',
Expand Down
20 changes: 17 additions & 3 deletions com/credentials.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ component {
public any function init(
string awsKey = '',
string awsSecretKey = '',
any api
any api,
string token = ''
) {
variables.api = api;
variables.iamRolePath = '169.254.169.254/latest/meta-data/iam/security-credentials/';
variables.ecsEndpoint = '169.254.170.2';
variables.iamRole = '';
variables.credentialPath = '';
variables.credentials = resolveCredentials( awsKey, awsSecretKey );
variables.credentials = resolveCredentials( awsKey, awsSecretKey, token );
return this;
}

Expand All @@ -36,10 +37,23 @@ component {

private function resolveCredentials(
awsKey,
awsSecretKey
awsSecretKey,
string token = ''
) {
var credentials = defaultCredentials( awsKey, awsSecretKey );

if(len(token)){
try {
variables.iamRole = requestIamRole();
if ( iamRole.len() ) {
variables.credentialPath = iamRolePath & iamRole;
refreshCredentials( credentials );
}
} catch ( any e ) {
// pass
}
}

if ( len( credentials.awsKey ) && len( credentials.awsSecretKey ) ) {
return credentials;
}
Expand Down