Skip to content

Commit

Permalink
Allow overwriting STS config in ChainableTemporaryCredentials (#2803)
Browse files Browse the repository at this point in the history
STS uses the global endpoint per default which does not work for
"opt-in" regions. The `ChainableTemporaryCredentials` wrapper for
fetching credentials via `AssumeRole` or `GetSessionToken` does not
allow overriding the endpoint or set a different region.

This change will introduce another optional constructor parameter for
specifying the STS client configuration and forwarding it to the client
constructor.

fix: #2673
  • Loading branch information
workeitel authored and AllanZhengYP committed Aug 19, 2019
1 parent f731ff1 commit 3ffad9c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "feature",
"category": "ChainableTemporaryCredentials",
"description": "Support for specifying STS client config when creating ChainableTemporaryCredentials to override endpoint or region."
}
12 changes: 8 additions & 4 deletions dist/aws-sdk-react-native.js
Original file line number Diff line number Diff line change
Expand Up @@ -17825,10 +17825,14 @@ return /******/ (function(modules) { // webpackBootstrap
this.tokenCodeFn = options.tokenCodeFn;
}
}
this.service = new STS({
params: params,
credentials: options.masterCredentials || AWS.config.credentials
});
config = AWS.util.merge(
{
params: params,
credentials: options.masterCredentials || AWS.config.credentials
},
options.stsConfig || {}
);
this.service = new STS(config);
},

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/credentials/chainable_temporary_credentials.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {AWSError} from '../error';
import STS = require('../../clients/sts');

export class ChainableTemporaryCredentials extends Credentials {
constructor(options: ChainableTemporaryCredentials.ChainableTemporaryCredentialsOptions, masterCredentials?: Credentials);
constructor(options: ChainableTemporaryCredentials.ChainableTemporaryCredentialsOptions);
/**
* Creates a new temporary credentials object.
*/
Expand All @@ -24,6 +24,7 @@ declare namespace ChainableTemporaryCredentials {
export type ChainableTemporaryCredentialsOptions = {
params?: STS.Types.AssumeRoleRequest|STS.Types.GetSessionTokenRequest,
masterCredentials?: Credentials,
stsConfig: STS.Types.ClientConfiguration,
tokenCodeFn?: (serialNumber: string, callback: (err?: Error, token?: string) => void) => void
}
}
12 changes: 8 additions & 4 deletions lib/credentials/chainable_temporary_credentials.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,14 @@ AWS.ChainableTemporaryCredentials = AWS.util.inherit(AWS.Credentials, {
this.tokenCodeFn = options.tokenCodeFn;
}
}
this.service = new STS({
params: params,
credentials: options.masterCredentials || AWS.config.credentials
});
config = AWS.util.merge(
{
params: params,
credentials: options.masterCredentials || AWS.config.credentials
},
options.stsConfig || {}
);
this.service = new STS(config);
},

/**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@
"helper-test": "mocha scripts/lib/test-helper.spec.js",
"csm-functional-test": "mocha test/publisher/functional_test"
}
}
}
6 changes: 6 additions & 0 deletions test/credentials.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3ffad9c

Please sign in to comment.