cdk-comprehend-s3olap 2.0.77 → 2.0.80
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.jsii +3 -3
- package/lib/cdk-comprehend-s3olap.js +2 -2
- package/lib/comprehend-lambdas.js +2 -2
- package/lib/iam-roles.js +4 -4
- package/node_modules/aws-sdk/CHANGELOG.md +18 -1
- package/node_modules/aws-sdk/README.md +1 -1
- package/node_modules/aws-sdk/apis/cloudfront-2020-05-31.min.json +350 -82
- package/node_modules/aws-sdk/apis/config-2014-11-12.min.json +107 -91
- package/node_modules/aws-sdk/apis/iotwireless-2020-11-22.min.json +123 -79
- package/node_modules/aws-sdk/apis/mediapackage-2017-10-12.min.json +7 -0
- package/node_modules/aws-sdk/apis/panorama-2019-07-24.min.json +47 -10
- package/node_modules/aws-sdk/apis/quicksight-2018-04-01.min.json +64 -29
- package/node_modules/aws-sdk/apis/sso-oidc-2019-06-10.min.json +1 -2
- package/node_modules/aws-sdk/clients/cloudfront.d.ts +246 -4
- package/node_modules/aws-sdk/clients/configservice.d.ts +27 -7
- package/node_modules/aws-sdk/clients/elbv2.d.ts +1 -1
- package/node_modules/aws-sdk/clients/gamelift.d.ts +1 -1
- package/node_modules/aws-sdk/clients/iam.d.ts +6 -6
- package/node_modules/aws-sdk/clients/iotwireless.d.ts +60 -11
- package/node_modules/aws-sdk/clients/ivs.d.ts +3 -3
- package/node_modules/aws-sdk/clients/mediapackage.d.ts +2 -0
- package/node_modules/aws-sdk/clients/panorama.d.ts +62 -0
- package/node_modules/aws-sdk/clients/quicksight.d.ts +38 -4
- package/node_modules/aws-sdk/clients/rds.d.ts +5 -5
- package/node_modules/aws-sdk/clients/ssooidc.d.ts +12 -12
- package/node_modules/aws-sdk/clients/transfer.d.ts +20 -20
- package/node_modules/aws-sdk/dist/aws-sdk-core-react-native.js +151 -31
- package/node_modules/aws-sdk/dist/aws-sdk-react-native.js +160 -40
- package/node_modules/aws-sdk/dist/aws-sdk.js +687 -287
- package/node_modules/aws-sdk/dist/aws-sdk.min.js +85 -85
- package/node_modules/aws-sdk/lib/config-base.d.ts +14 -0
- package/node_modules/aws-sdk/lib/config.js +78 -1
- package/node_modules/aws-sdk/lib/core.js +1 -1
- package/node_modules/aws-sdk/lib/event_listeners.js +49 -30
- package/node_modules/aws-sdk/lib/node_loader.js +17 -1
- package/node_modules/aws-sdk/lib/service.js +2 -0
- package/node_modules/aws-sdk/lib/shared-ini/ini-loader.d.ts +1 -12
- package/node_modules/aws-sdk/lib/shared-ini/ini-loader.js +68 -30
- package/node_modules/aws-sdk/lib/signers/bearer.js +14 -0
- package/node_modules/aws-sdk/lib/signers/request_signer.js +2 -0
- package/node_modules/aws-sdk/lib/token/sso_token_provider.d.ts +12 -0
- package/node_modules/aws-sdk/lib/token/sso_token_provider.js +245 -0
- package/node_modules/aws-sdk/lib/token/static_token_provider.d.ts +8 -0
- package/node_modules/aws-sdk/lib/token/static_token_provider.js +27 -0
- package/node_modules/aws-sdk/lib/token/token_provider_chain.d.ts +24 -0
- package/node_modules/aws-sdk/lib/token/token_provider_chain.js +165 -0
- package/node_modules/aws-sdk/lib/token.d.ts +101 -0
- package/node_modules/aws-sdk/lib/token.js +219 -0
- package/node_modules/aws-sdk/package.json +1 -1
- package/node_modules/aws-sdk/scripts/region-checker/allowlist.js +4 -1
- package/package.json +6 -6
@@ -0,0 +1,245 @@
|
|
1
|
+
var AWS = require('../core');
|
2
|
+
var crypto = require('crypto');
|
3
|
+
var fs = require('fs');
|
4
|
+
var path = require('path');
|
5
|
+
var iniLoader = AWS.util.iniLoader;
|
6
|
+
|
7
|
+
// Tracking refresh attempt to ensure refresh is not attempted more than once every 30 seconds.
|
8
|
+
var lastRefreshAttemptTime = 0;
|
9
|
+
|
10
|
+
/**
|
11
|
+
* Throws error is key is not present in token object.
|
12
|
+
*
|
13
|
+
* @param token [Object] Object to be validated.
|
14
|
+
* @param key [String] The key to be validated on the object.
|
15
|
+
*/
|
16
|
+
var validateTokenKey = function validateTokenKey(token, key) {
|
17
|
+
if (!token[key]) {
|
18
|
+
throw AWS.util.error(
|
19
|
+
new Error('Key "' + key + '" not present in SSO Token'),
|
20
|
+
{ code: 'SSOTokenProviderFailure' }
|
21
|
+
);
|
22
|
+
}
|
23
|
+
};
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Calls callback function with or without error based on provided times in case
|
27
|
+
* of unsuccessful refresh.
|
28
|
+
*
|
29
|
+
* @param currentTime [number] current time in milliseconds since ECMAScript epoch.
|
30
|
+
* @param tokenExpireTime [number] token expire time in milliseconds since ECMAScript epoch.
|
31
|
+
* @param callback [Function] Callback to call in case of error.
|
32
|
+
*/
|
33
|
+
var refreshUnsuccessful = function refreshUnsuccessful(
|
34
|
+
currentTime,
|
35
|
+
tokenExpireTime,
|
36
|
+
callback
|
37
|
+
) {
|
38
|
+
if (tokenExpireTime > currentTime) {
|
39
|
+
// Cached token is still valid, return.
|
40
|
+
callback(null);
|
41
|
+
} else {
|
42
|
+
// Token invalid, throw error requesting user to sso login.
|
43
|
+
throw AWS.util.error(
|
44
|
+
new Error('SSO Token refresh failed. Please log in using "aws sso login"'),
|
45
|
+
{ code: 'SSOTokenProviderFailure' }
|
46
|
+
);
|
47
|
+
}
|
48
|
+
};
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Represents token loaded from disk derived from the AWS SSO device grant authorication flow.
|
52
|
+
*
|
53
|
+
* ## Using SSO Token Provider
|
54
|
+
*
|
55
|
+
* This provider is checked by default in the Node.js environment in TokenProviderChain.
|
56
|
+
* To use the SSO Token Provider, simply add your SSO Start URL and Region to the
|
57
|
+
* ~/.aws/config file in the following format:
|
58
|
+
*
|
59
|
+
* [default]
|
60
|
+
* sso_start_url = https://d-abc123.awsapps.com/start
|
61
|
+
* sso_region = us-east-1
|
62
|
+
*
|
63
|
+
* ## Using custom profiles
|
64
|
+
*
|
65
|
+
* The SDK supports loading token for separate profiles. This can be done in two ways:
|
66
|
+
*
|
67
|
+
* 1. Set the `AWS_PROFILE` environment variable in your process prior to loading the SDK.
|
68
|
+
* 2. Directly load the AWS.SSOTokenProvider:
|
69
|
+
*
|
70
|
+
* ```javascript
|
71
|
+
* var ssoTokenProvider = new AWS.SSOTokenProvider({profile: 'myprofile'});
|
72
|
+
* ```
|
73
|
+
*
|
74
|
+
* @!macro nobrowser
|
75
|
+
*/
|
76
|
+
AWS.SSOTokenProvider = AWS.util.inherit(AWS.Token, {
|
77
|
+
/**
|
78
|
+
* Expiry window of five minutes.
|
79
|
+
*/
|
80
|
+
expiryWindow: 5 * 60,
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Creates a new token object from cached access token.
|
84
|
+
*
|
85
|
+
* @param options [map] a set of options
|
86
|
+
* @option options profile [String] (AWS_PROFILE env var or 'default')
|
87
|
+
* the name of the profile to load.
|
88
|
+
* @option options callback [Function] (err) Token is eagerly loaded
|
89
|
+
* by the constructor. When the callback is called with no error, the
|
90
|
+
* token has been loaded successfully.
|
91
|
+
*/
|
92
|
+
constructor: function SSOTokenProvider(options) {
|
93
|
+
AWS.Token.call(this);
|
94
|
+
|
95
|
+
options = options || {};
|
96
|
+
|
97
|
+
this.expired = true;
|
98
|
+
this.profile = options.profile || process.env.AWS_PROFILE || AWS.util.defaultProfile;
|
99
|
+
this.get(options.callback || AWS.util.fn.noop);
|
100
|
+
},
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Reads sso_start_url from provided profile, and reads token from
|
104
|
+
* ~/.aws/sso/cache/<sha1-of-utf8-encoded-value-from-sso_start_url>.json
|
105
|
+
*
|
106
|
+
* Throws an error if required fields token and expiresAt are missing.
|
107
|
+
* Throws an error if token has expired and metadata to perform refresh is
|
108
|
+
* not available.
|
109
|
+
* Attempts to refresh the token if it's within 5 minutes before expiry time.
|
110
|
+
*
|
111
|
+
* @api private
|
112
|
+
*/
|
113
|
+
load: function load(callback) {
|
114
|
+
var self = this;
|
115
|
+
var profiles = iniLoader.loadFrom({ isConfig: true });
|
116
|
+
var profile = profiles[this.profile] || {};
|
117
|
+
|
118
|
+
if (Object.keys(profile).length === 0) {
|
119
|
+
throw AWS.util.error(
|
120
|
+
new Error('Profile "' + this.profile + '" not found'),
|
121
|
+
{ code: 'SSOTokenProviderFailure' }
|
122
|
+
);
|
123
|
+
} else if (!profile['sso_session']) {
|
124
|
+
throw AWS.util.error(
|
125
|
+
new Error('Profile "' + profileName + '" is missing required property "sso_session".'),
|
126
|
+
{ code: 'SSOTokenProviderFailure' }
|
127
|
+
);
|
128
|
+
}
|
129
|
+
|
130
|
+
var ssoSessionName = profile['sso_session'];
|
131
|
+
var ssoSessions = iniLoader.loadSsoSessionsFrom();
|
132
|
+
var ssoSession = ssoSessions[ssoSessionName];
|
133
|
+
|
134
|
+
if (!ssoSession) {
|
135
|
+
throw AWS.util.error(
|
136
|
+
new Error('Sso session "' + ssoSessionName + '" not found'),
|
137
|
+
{ code: 'SSOTokenProviderFailure' }
|
138
|
+
);
|
139
|
+
} else if (!ssoSession['sso_start_url']) {
|
140
|
+
throw AWS.util.error(
|
141
|
+
new Error('Sso session "' + profileName + '" is missing required property "sso_start_url".'),
|
142
|
+
{ code: 'SSOTokenProviderFailure' }
|
143
|
+
);
|
144
|
+
} else if (!ssoSession['sso_region']) {
|
145
|
+
throw AWS.util.error(
|
146
|
+
new Error('Sso session "' + profileName + '" is missing required property "sso_region".'),
|
147
|
+
{ code: 'SSOTokenProviderFailure' }
|
148
|
+
);
|
149
|
+
}
|
150
|
+
|
151
|
+
var hasher = crypto.createHash('sha1');
|
152
|
+
var fileName = hasher.update(ssoSessionName).digest('hex') + '.json';
|
153
|
+
var cachePath = path.join(iniLoader.getHomeDir(), '.aws', 'sso', 'cache', fileName);
|
154
|
+
var tokenFromCache = JSON.parse(fs.readFileSync(cachePath));
|
155
|
+
|
156
|
+
if (!tokenFromCache) {
|
157
|
+
throw AWS.util.error(
|
158
|
+
new Error('Cached token not found. Please log in using "aws sso login"'
|
159
|
+
+ ' for profile "' + this.profile + '".'),
|
160
|
+
{ code: 'SSOTokenProviderFailure' }
|
161
|
+
);
|
162
|
+
}
|
163
|
+
|
164
|
+
validateTokenKey(tokenFromCache, 'accessToken');
|
165
|
+
validateTokenKey(tokenFromCache, 'expiresAt');
|
166
|
+
|
167
|
+
var currentTime = AWS.util.date.getDate().getTime();
|
168
|
+
var adjustedTime = new Date(currentTime + this.expiryWindow * 1000);
|
169
|
+
var tokenExpireTime = new Date(tokenFromCache['expiresAt']);
|
170
|
+
|
171
|
+
if (tokenExpireTime > adjustedTime) {
|
172
|
+
// Token is valid and not expired.
|
173
|
+
self.token = tokenFromCache.accessToken;
|
174
|
+
self.expireTime = tokenExpireTime;
|
175
|
+
self.expired = false;
|
176
|
+
callback(null);
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
|
180
|
+
// Skip new refresh, if last refresh was done within 30 seconds.
|
181
|
+
if (currentTime - lastRefreshAttemptTime < 30 * 1000) {
|
182
|
+
refreshUnsuccessful(currentTime, tokenExpireTime, callback);
|
183
|
+
return;
|
184
|
+
}
|
185
|
+
|
186
|
+
// Token is in expiry window, refresh from SSOOIDC.createToken() call.
|
187
|
+
validateTokenKey(tokenFromCache, 'clientId');
|
188
|
+
validateTokenKey(tokenFromCache, 'clientSecret');
|
189
|
+
validateTokenKey(tokenFromCache, 'refreshToken');
|
190
|
+
|
191
|
+
if (!self.service || self.service.config.region !== ssoSession.sso_region) {
|
192
|
+
self.service = new AWS.SSOOIDC({ region: ssoSession.sso_region });
|
193
|
+
}
|
194
|
+
|
195
|
+
var params = {
|
196
|
+
clientId: tokenFromCache.clientId,
|
197
|
+
clientSecret: tokenFromCache.clientSecret,
|
198
|
+
refreshToken: tokenFromCache.refreshToken,
|
199
|
+
grantType: 'refresh_token',
|
200
|
+
};
|
201
|
+
|
202
|
+
lastRefreshAttemptTime = AWS.util.date.getDate().getTime();
|
203
|
+
self.service.createToken(params, function(err, data) {
|
204
|
+
if (err || !data) {
|
205
|
+
refreshUnsuccessful(currentTime, tokenExpireTime, callback);
|
206
|
+
} else {
|
207
|
+
try {
|
208
|
+
validateTokenKey(data, 'accessToken');
|
209
|
+
validateTokenKey(data, 'expiresIn');
|
210
|
+
self.expired = false;
|
211
|
+
self.token = data.accessToken;
|
212
|
+
self.expireTime = new Date(Date.now() + data.expiresIn * 1000);
|
213
|
+
callback(null);
|
214
|
+
|
215
|
+
try {
|
216
|
+
// Write updated token data to disk.
|
217
|
+
tokenFromCache.accessToken = data.accessToken;
|
218
|
+
tokenFromCache.expiresAt = self.expireTime.toISOString();
|
219
|
+
tokenFromCache.refreshToken = data.refreshToken;
|
220
|
+
fs.writeFileSync(cachePath, JSON.stringify(tokenFromCache, null, 2));
|
221
|
+
} catch (error) {
|
222
|
+
// Swallow error if unable to write token to file.
|
223
|
+
}
|
224
|
+
} catch (error) {
|
225
|
+
refreshUnsuccessful(currentTime, tokenExpireTime, callback);
|
226
|
+
}
|
227
|
+
}
|
228
|
+
});
|
229
|
+
},
|
230
|
+
|
231
|
+
/**
|
232
|
+
* Loads the cached access token from disk.
|
233
|
+
*
|
234
|
+
* @callback callback function(err)
|
235
|
+
* Called after the AWS SSO process has been executed. When this
|
236
|
+
* callback is called with no error, it means that the token information
|
237
|
+
* has been loaded into the object (as the `token` property).
|
238
|
+
* @param err [Error] if an error occurred, this value will be filled.
|
239
|
+
* @see get
|
240
|
+
*/
|
241
|
+
refresh: function refresh(callback) {
|
242
|
+
iniLoader.clearCachedFiles();
|
243
|
+
this.coalesceRefresh(callback || AWS.util.fn.callback);
|
244
|
+
},
|
245
|
+
});
|
@@ -0,0 +1,27 @@
|
|
1
|
+
var AWS = require('../core');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Represents the simplest token provider. It returns a static token string
|
5
|
+
* and has an optional expireTime.
|
6
|
+
*/
|
7
|
+
AWS.StaticTokenProvider = AWS.util.inherit(AWS.Token, {
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Creates a new StaticTokenProvider class with a given {token} and
|
11
|
+
* optional {expireTime}.
|
12
|
+
*
|
13
|
+
* ```javascript
|
14
|
+
* var staticTokenProvider = new AWS.StaticTokenProvider({
|
15
|
+
* token: 'token'
|
16
|
+
* });
|
17
|
+
* staticTokenProvider.token == 'token' // from constructor
|
18
|
+
* ```
|
19
|
+
*
|
20
|
+
* @option options token [String] represents the literal token string.
|
21
|
+
* @option options expireTime [Date] optional field representing the time at which
|
22
|
+
* the token expires.
|
23
|
+
*/
|
24
|
+
constructor: function StaticTokenProvider(options) {
|
25
|
+
AWS.Token.call(this, options);
|
26
|
+
}
|
27
|
+
});
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import {Token} from '../token';
|
2
|
+
import {AWSError} from '../error';
|
3
|
+
export class TokenProviderChain {
|
4
|
+
/**
|
5
|
+
* Creates a new TokenProviderChain with a default set of providers specified by defaultProviders.
|
6
|
+
*/
|
7
|
+
constructor(providers?: provider[])
|
8
|
+
/**
|
9
|
+
* Resolves the provider chain by searching for the first set of token in providers.
|
10
|
+
*/
|
11
|
+
resolve(callback:(err: AWSError|null, token?: Token) => void): TokenProviderChain;
|
12
|
+
/**
|
13
|
+
* Return a Promise on resolve() function
|
14
|
+
*/
|
15
|
+
resolvePromise(): Promise<Token>;
|
16
|
+
/**
|
17
|
+
* Returns a list of token objects or functions that return token objects. If the provider is a function, the function will be executed lazily when the provider needs to be checked for valid token. By default, this object will be set to the defaultProviders.
|
18
|
+
*/
|
19
|
+
providers: Array<Token|provider>;
|
20
|
+
|
21
|
+
static defaultProviders: provider[]
|
22
|
+
}
|
23
|
+
|
24
|
+
type provider = () => Token;
|
@@ -0,0 +1,165 @@
|
|
1
|
+
var AWS = require('../core');
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Creates a token provider chain that searches for token in a list of
|
5
|
+
* token providers specified by the {providers} property.
|
6
|
+
*
|
7
|
+
* By default, the chain will use the {defaultProviders} to resolve token.
|
8
|
+
*
|
9
|
+
* ## Setting Providers
|
10
|
+
*
|
11
|
+
* Each provider in the {providers} list should be a function that returns
|
12
|
+
* a {AWS.Token} object, or a hardcoded token object. The function
|
13
|
+
* form allows for delayed execution of the Token construction.
|
14
|
+
*
|
15
|
+
* ## Resolving Token from a Chain
|
16
|
+
*
|
17
|
+
* Call {resolve} to return the first valid token object that can be
|
18
|
+
* loaded by the provider chain.
|
19
|
+
*
|
20
|
+
* For example, to resolve a chain with a custom provider that checks a file
|
21
|
+
* on disk after the set of {defaultProviders}:
|
22
|
+
*
|
23
|
+
* ```javascript
|
24
|
+
* var diskProvider = new FileTokenProvider('./token.json');
|
25
|
+
* var chain = new AWS.TokenProviderChain();
|
26
|
+
* chain.providers.push(diskProvider);
|
27
|
+
* chain.resolve();
|
28
|
+
* ```
|
29
|
+
*
|
30
|
+
* The above code will return the `diskProvider` object if the
|
31
|
+
* file contains token and the `defaultProviders` do not contain
|
32
|
+
* any token.
|
33
|
+
*
|
34
|
+
* @!attribute providers
|
35
|
+
* @return [Array<AWS.Token, Function>]
|
36
|
+
* a list of token objects or functions that return token
|
37
|
+
* objects. If the provider is a function, the function will be
|
38
|
+
* executed lazily when the provider needs to be checked for valid
|
39
|
+
* token. By default, this object will be set to the {defaultProviders}.
|
40
|
+
* @see defaultProviders
|
41
|
+
*/
|
42
|
+
AWS.TokenProviderChain = AWS.util.inherit(AWS.Token, {
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Creates a new TokenProviderChain with a default set of providers
|
46
|
+
* specified by {defaultProviders}.
|
47
|
+
*/
|
48
|
+
constructor: function TokenProviderChain(providers) {
|
49
|
+
if (providers) {
|
50
|
+
this.providers = providers;
|
51
|
+
} else {
|
52
|
+
this.providers = AWS.TokenProviderChain.defaultProviders.slice(0);
|
53
|
+
}
|
54
|
+
this.resolveCallbacks = [];
|
55
|
+
},
|
56
|
+
|
57
|
+
/**
|
58
|
+
* @!method resolvePromise()
|
59
|
+
* Returns a 'thenable' promise.
|
60
|
+
* Resolves the provider chain by searching for the first token in {providers}.
|
61
|
+
*
|
62
|
+
* Two callbacks can be provided to the `then` method on the returned promise.
|
63
|
+
* The first callback will be called if the promise is fulfilled, and the second
|
64
|
+
* callback will be called if the promise is rejected.
|
65
|
+
* @callback fulfilledCallback function(token)
|
66
|
+
* Called if the promise is fulfilled and the provider resolves the chain
|
67
|
+
* to a token object
|
68
|
+
* @param token [AWS.Token] the token object resolved by the provider chain.
|
69
|
+
* @callback rejectedCallback function(error)
|
70
|
+
* Called if the promise is rejected.
|
71
|
+
* @param err [Error] the error object returned if no token is found.
|
72
|
+
* @return [Promise] A promise that represents the state of the `resolve` method call.
|
73
|
+
* @example Calling the `resolvePromise` method.
|
74
|
+
* var promise = chain.resolvePromise();
|
75
|
+
* promise.then(function(token) { ... }, function(err) { ... });
|
76
|
+
*/
|
77
|
+
|
78
|
+
/**
|
79
|
+
* Resolves the provider chain by searching for the first token in {providers}.
|
80
|
+
*
|
81
|
+
* @callback callback function(err, token)
|
82
|
+
* Called when the provider resolves the chain to a token object
|
83
|
+
* or null if no token can be found.
|
84
|
+
*
|
85
|
+
* @param err [Error] the error object returned if no token is found.
|
86
|
+
* @param token [AWS.Token] the token object resolved by the provider chain.
|
87
|
+
* @return [AWS.TokenProviderChain] the provider, for chaining.
|
88
|
+
*/
|
89
|
+
resolve: function resolve(callback) {
|
90
|
+
var self = this;
|
91
|
+
if (self.providers.length === 0) {
|
92
|
+
callback(new Error('No providers'));
|
93
|
+
return self;
|
94
|
+
}
|
95
|
+
|
96
|
+
if (self.resolveCallbacks.push(callback) === 1) {
|
97
|
+
var index = 0;
|
98
|
+
var providers = self.providers.slice(0);
|
99
|
+
|
100
|
+
function resolveNext(err, token) {
|
101
|
+
if ((!err && token) || index === providers.length) {
|
102
|
+
AWS.util.arrayEach(self.resolveCallbacks, function (callback) {
|
103
|
+
callback(err, token);
|
104
|
+
});
|
105
|
+
self.resolveCallbacks.length = 0;
|
106
|
+
return;
|
107
|
+
}
|
108
|
+
|
109
|
+
var provider = providers[index++];
|
110
|
+
if (typeof provider === 'function') {
|
111
|
+
token = provider.call();
|
112
|
+
} else {
|
113
|
+
token = provider;
|
114
|
+
}
|
115
|
+
|
116
|
+
if (token.get) {
|
117
|
+
token.get(function (getErr) {
|
118
|
+
resolveNext(getErr, getErr ? null : token);
|
119
|
+
});
|
120
|
+
} else {
|
121
|
+
resolveNext(null, token);
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
resolveNext();
|
126
|
+
}
|
127
|
+
|
128
|
+
return self;
|
129
|
+
}
|
130
|
+
});
|
131
|
+
|
132
|
+
/**
|
133
|
+
* The default set of providers used by a vanilla TokenProviderChain.
|
134
|
+
*
|
135
|
+
* In the browser:
|
136
|
+
*
|
137
|
+
* ```javascript
|
138
|
+
* AWS.TokenProviderChain.defaultProviders = []
|
139
|
+
* ```
|
140
|
+
*
|
141
|
+
* In Node.js:
|
142
|
+
*
|
143
|
+
* ```javascript
|
144
|
+
* AWS.TokenProviderChain.defaultProviders = [
|
145
|
+
* function () { return new AWS.SSOTokenProvider(); },
|
146
|
+
* ]
|
147
|
+
* ```
|
148
|
+
*/
|
149
|
+
AWS.TokenProviderChain.defaultProviders = [];
|
150
|
+
|
151
|
+
/**
|
152
|
+
* @api private
|
153
|
+
*/
|
154
|
+
AWS.TokenProviderChain.addPromisesToClass = function addPromisesToClass(PromiseDependency) {
|
155
|
+
this.prototype.resolvePromise = AWS.util.promisifyMethod('resolve', PromiseDependency);
|
156
|
+
};
|
157
|
+
|
158
|
+
/**
|
159
|
+
* @api private
|
160
|
+
*/
|
161
|
+
AWS.TokenProviderChain.deletePromisesFromClass = function deletePromisesFromClass() {
|
162
|
+
delete this.prototype.resolvePromise;
|
163
|
+
};
|
164
|
+
|
165
|
+
AWS.util.addPromises(AWS.TokenProviderChain);
|
@@ -0,0 +1,101 @@
|
|
1
|
+
import {AWSError} from './error';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Represents AWS token object, which contains {token}, and optional
|
5
|
+
* {expireTime}.
|
6
|
+
* Creating a `Token` object allows you to pass around your
|
7
|
+
* token to configuration and service objects.
|
8
|
+
*
|
9
|
+
* Note that this class typically does not need to be constructed manually,
|
10
|
+
* as the {AWS.Config} and {AWS.Service} classes both accept simple
|
11
|
+
* options hashes with the two keys. The token from this object will be used
|
12
|
+
* automatically in operations which require them.
|
13
|
+
*
|
14
|
+
* ## Expiring and Refreshing Token
|
15
|
+
*
|
16
|
+
* Occasionally token can expire in the middle of a long-running
|
17
|
+
* application. In this case, the SDK will automatically attempt to
|
18
|
+
* refresh the token from the storage location if the Token
|
19
|
+
* class implements the {refresh} method.
|
20
|
+
*
|
21
|
+
* If you are implementing a token storage location, you
|
22
|
+
* will want to create a subclass of the `Token` class and
|
23
|
+
* override the {refresh} method. This method allows token to be
|
24
|
+
* retrieved from the backing store, be it a file system, database, or
|
25
|
+
* some network storage. The method should reset the token attributes
|
26
|
+
* on the object.
|
27
|
+
*/
|
28
|
+
export class Token {
|
29
|
+
/**
|
30
|
+
* Creates a Token object with a given set of token information as an options hash.
|
31
|
+
*
|
32
|
+
* @param {object} options - An option hash containing a set of token information.
|
33
|
+
*/
|
34
|
+
constructor(options: TokenOptions);
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Gets the existing token, refreshing it if it's are not yet loaded or have expired.
|
38
|
+
* Users should call this method before using refresh(), as this will not attempt to reload
|
39
|
+
* tokeb when they are already loaded into the object.
|
40
|
+
*
|
41
|
+
* @param {get} callback - When called with no error, the token information has been loaded into the object.
|
42
|
+
*/
|
43
|
+
get(callback: (err?: AWSError) => void): void;
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Gets the existing token, refreshing ot if necessary, and returns
|
47
|
+
* a promise that will be fulfilled immediately (if no refresh is necessary)
|
48
|
+
* or when the refresh has completed.
|
49
|
+
*/
|
50
|
+
getPromise(): Promise<void>;
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Returns whether the token object should call refresh()
|
54
|
+
*/
|
55
|
+
needsRefresh(): boolean;
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Refreshes the token.
|
59
|
+
* Users should call get() before attempting to forcibly refresh token.
|
60
|
+
*
|
61
|
+
* @param {function} callback - When called with no error, the token information has been loaded into the object.
|
62
|
+
*/
|
63
|
+
refresh(callback: (err?: AWSError) => void): void;
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Invokes a token refresh and returns a promise that will be fulfilled
|
67
|
+
* when the refresh has completed or rejected when the refresh has failed.
|
68
|
+
* Users should call get() before attempting to forcibly refresh token.
|
69
|
+
*/
|
70
|
+
refreshPromise(): Promise<void>;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* The literal token string.
|
74
|
+
*/
|
75
|
+
token: string;
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Whether the token has expired and require a refresh.
|
79
|
+
* Used in conjunction with expireTime.
|
80
|
+
*/
|
81
|
+
expired: boolean;
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Time when token should be considered expired.
|
85
|
+
* Used in conjunction with expired.
|
86
|
+
*/
|
87
|
+
expireTime: Date;
|
88
|
+
|
89
|
+
static expiryWindow: number;
|
90
|
+
}
|
91
|
+
|
92
|
+
export interface TokenOptions {
|
93
|
+
/**
|
94
|
+
* The literal token string.
|
95
|
+
*/
|
96
|
+
token: string
|
97
|
+
/**
|
98
|
+
* The time at which the token expires.
|
99
|
+
*/
|
100
|
+
expireTime?: Date
|
101
|
+
}
|