@digipair/skill-s3 0.81.2 → 0.82.1

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/index.esm3.js DELETED
@@ -1,1587 +0,0 @@
1
- import { P as ProviderError, I as IniSectionType, C as CONFIG_PREFIX_SEPARATOR, s as slurpFile, g as getConfigFilepath, p as parseIni, a as getSSOTokenFilepath, b as getSSOTokenFromFile, c as getProfileName, d as CredentialsProviderError, e as setCredentialFeature } from './index.esm2.js';
2
- import 'os';
3
- import 'path';
4
- import 'crypto';
5
- import { p as parseKnownFiles } from './parseKnownFiles.esm.js';
6
- import { promises } from 'fs';
7
- import 'buffer';
8
- import 'stream';
9
- import 'node:stream';
10
- import 'http';
11
- import 'https';
12
- import 'http2';
13
- import 'zlib';
14
- import 'process';
15
-
16
- function _assert_this_initialized(self) {
17
- if (self === void 0) {
18
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
19
- }
20
- return self;
21
- }
22
- function _class_call_check(instance, Constructor) {
23
- if (!(instance instanceof Constructor)) {
24
- throw new TypeError("Cannot call a class as a function");
25
- }
26
- }
27
- function _get_prototype_of(o) {
28
- _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o) {
29
- return o.__proto__ || Object.getPrototypeOf(o);
30
- };
31
- return _get_prototype_of(o);
32
- }
33
- function _inherits(subClass, superClass) {
34
- if (typeof superClass !== "function" && superClass !== null) {
35
- throw new TypeError("Super expression must either be null or a function");
36
- }
37
- subClass.prototype = Object.create(superClass && superClass.prototype, {
38
- constructor: {
39
- value: subClass,
40
- writable: true,
41
- configurable: true
42
- }
43
- });
44
- if (superClass) _set_prototype_of(subClass, superClass);
45
- }
46
- function _possible_constructor_return(self, call) {
47
- if (call && (_type_of(call) === "object" || typeof call === "function")) {
48
- return call;
49
- }
50
- return _assert_this_initialized(self);
51
- }
52
- function _set_prototype_of(o, p) {
53
- _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
54
- o.__proto__ = p;
55
- return o;
56
- };
57
- return _set_prototype_of(o, p);
58
- }
59
- function _type_of(obj) {
60
- "@swc/helpers - typeof";
61
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
62
- }
63
- function _is_native_reflect_construct() {
64
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
65
- if (Reflect.construct.sham) return false;
66
- if (typeof Proxy === "function") return true;
67
- try {
68
- Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
69
- return true;
70
- } catch (e) {
71
- return false;
72
- }
73
- }
74
- function _create_super(Derived) {
75
- var hasNativeReflectConstruct = _is_native_reflect_construct();
76
- return function _createSuperInternal() {
77
- var Super = _get_prototype_of(Derived), result;
78
- if (hasNativeReflectConstruct) {
79
- var NewTarget = _get_prototype_of(this).constructor;
80
- result = Reflect.construct(Super, arguments, NewTarget);
81
- } else {
82
- result = Super.apply(this, arguments);
83
- }
84
- return _possible_constructor_return(this, result);
85
- };
86
- }
87
- var TokenProviderError = /*#__PURE__*/ function(ProviderError) {
88
- _inherits(TokenProviderError, ProviderError);
89
- var _super = _create_super(TokenProviderError);
90
- function TokenProviderError(message) {
91
- var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
92
- _class_call_check(this, TokenProviderError);
93
- var _this;
94
- _this = _super.call(this, message, options);
95
- _this.name = "TokenProviderError";
96
- Object.setPrototypeOf(_assert_this_initialized(_this), TokenProviderError.prototype);
97
- return _this;
98
- }
99
- return TokenProviderError;
100
- }(ProviderError);
101
-
102
- function _array_like_to_array(arr, len) {
103
- if (len == null || len > arr.length) len = arr.length;
104
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
105
- return arr2;
106
- }
107
- function _array_with_holes(arr) {
108
- if (Array.isArray(arr)) return arr;
109
- }
110
- function _define_property$2(obj, key, value) {
111
- if (key in obj) {
112
- Object.defineProperty(obj, key, {
113
- value: value,
114
- enumerable: true,
115
- configurable: true,
116
- writable: true
117
- });
118
- } else {
119
- obj[key] = value;
120
- }
121
- return obj;
122
- }
123
- function _iterable_to_array_limit(arr, i) {
124
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
125
- if (_i == null) return;
126
- var _arr = [];
127
- var _n = true;
128
- var _d = false;
129
- var _s, _e;
130
- try {
131
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
132
- _arr.push(_s.value);
133
- if (i && _arr.length === i) break;
134
- }
135
- } catch (err) {
136
- _d = true;
137
- _e = err;
138
- } finally{
139
- try {
140
- if (!_n && _i["return"] != null) _i["return"]();
141
- } finally{
142
- if (_d) throw _e;
143
- }
144
- }
145
- return _arr;
146
- }
147
- function _non_iterable_rest() {
148
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
149
- }
150
- function _object_spread$2(target) {
151
- for(var i = 1; i < arguments.length; i++){
152
- var source = arguments[i] != null ? arguments[i] : {};
153
- var ownKeys = Object.keys(source);
154
- if (typeof Object.getOwnPropertySymbols === "function") {
155
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
156
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
157
- }));
158
- }
159
- ownKeys.forEach(function(key) {
160
- _define_property$2(target, key, source[key]);
161
- });
162
- }
163
- return target;
164
- }
165
- function ownKeys$1(object, enumerableOnly) {
166
- var keys = Object.keys(object);
167
- if (Object.getOwnPropertySymbols) {
168
- var symbols = Object.getOwnPropertySymbols(object);
169
- if (enumerableOnly) {
170
- symbols = symbols.filter(function(sym) {
171
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
172
- });
173
- }
174
- keys.push.apply(keys, symbols);
175
- }
176
- return keys;
177
- }
178
- function _object_spread_props$1(target, source) {
179
- source = source != null ? source : {};
180
- if (Object.getOwnPropertyDescriptors) {
181
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
182
- } else {
183
- ownKeys$1(Object(source)).forEach(function(key) {
184
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
185
- });
186
- }
187
- return target;
188
- }
189
- function _sliced_to_array(arr, i) {
190
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
191
- }
192
- function _unsupported_iterable_to_array(o, minLen) {
193
- if (!o) return;
194
- if (typeof o === "string") return _array_like_to_array(o, minLen);
195
- var n = Object.prototype.toString.call(o).slice(8, -1);
196
- if (n === "Object" && o.constructor) n = o.constructor.name;
197
- if (n === "Map" || n === "Set") return Array.from(n);
198
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
199
- }
200
- var getSsoSessionData = function(data) {
201
- return Object.entries(data).filter(function(param) {
202
- var _param = _sliced_to_array(param, 1), key = _param[0];
203
- return key.startsWith(IniSectionType.SSO_SESSION + CONFIG_PREFIX_SEPARATOR);
204
- }).reduce(function(acc, param) {
205
- var _param = _sliced_to_array(param, 2), key = _param[0], value = _param[1];
206
- return _object_spread_props$1(_object_spread$2({}, acc), _define_property$2({}, key.substring(key.indexOf(CONFIG_PREFIX_SEPARATOR) + 1), value));
207
- }, {});
208
- };
209
-
210
- function asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, key, arg) {
211
- try {
212
- var info = gen[key](arg);
213
- var value = info.value;
214
- } catch (error) {
215
- reject(error);
216
- return;
217
- }
218
- if (info.done) {
219
- resolve(value);
220
- } else {
221
- Promise.resolve(value).then(_next, _throw);
222
- }
223
- }
224
- function _async_to_generator$5(fn) {
225
- return function() {
226
- var self = this, args = arguments;
227
- return new Promise(function(resolve, reject) {
228
- var gen = fn.apply(self, args);
229
- function _next(value) {
230
- asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "next", value);
231
- }
232
- function _throw(err) {
233
- asyncGeneratorStep$5(gen, resolve, reject, _next, _throw, "throw", err);
234
- }
235
- _next(undefined);
236
- });
237
- };
238
- }
239
- function _ts_generator$5(thisArg, body) {
240
- var f, y, t, g, _ = {
241
- label: 0,
242
- sent: function() {
243
- if (t[0] & 1) throw t[1];
244
- return t[1];
245
- },
246
- trys: [],
247
- ops: []
248
- };
249
- return g = {
250
- next: verb(0),
251
- "throw": verb(1),
252
- "return": verb(2)
253
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
254
- return this;
255
- }), g;
256
- function verb(n) {
257
- return function(v) {
258
- return step([
259
- n,
260
- v
261
- ]);
262
- };
263
- }
264
- function step(op) {
265
- if (f) throw new TypeError("Generator is already executing.");
266
- while(_)try {
267
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
268
- if (y = 0, t) op = [
269
- op[0] & 2,
270
- t.value
271
- ];
272
- switch(op[0]){
273
- case 0:
274
- case 1:
275
- t = op;
276
- break;
277
- case 4:
278
- _.label++;
279
- return {
280
- value: op[1],
281
- done: false
282
- };
283
- case 5:
284
- _.label++;
285
- y = op[1];
286
- op = [
287
- 0
288
- ];
289
- continue;
290
- case 7:
291
- op = _.ops.pop();
292
- _.trys.pop();
293
- continue;
294
- default:
295
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
296
- _ = 0;
297
- continue;
298
- }
299
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
300
- _.label = op[1];
301
- break;
302
- }
303
- if (op[0] === 6 && _.label < t[1]) {
304
- _.label = t[1];
305
- t = op;
306
- break;
307
- }
308
- if (t && _.label < t[2]) {
309
- _.label = t[2];
310
- _.ops.push(op);
311
- break;
312
- }
313
- if (t[2]) _.ops.pop();
314
- _.trys.pop();
315
- continue;
316
- }
317
- op = body.call(thisArg, _);
318
- } catch (e) {
319
- op = [
320
- 6,
321
- e
322
- ];
323
- y = 0;
324
- } finally{
325
- f = t = 0;
326
- }
327
- if (op[0] & 5) throw op[1];
328
- return {
329
- value: op[0] ? op[1] : void 0,
330
- done: true
331
- };
332
- }
333
- }
334
- var swallowError = function() {
335
- return {};
336
- };
337
- var loadSsoSessionData = function() {
338
- var _ref = _async_to_generator$5(function() {
339
- var init, _init_configFilepath;
340
- var _arguments = arguments;
341
- return _ts_generator$5(this, function(_state) {
342
- init = _arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {};
343
- return [
344
- 2,
345
- slurpFile((_init_configFilepath = init.configFilepath) !== null && _init_configFilepath !== void 0 ? _init_configFilepath : getConfigFilepath()).then(parseIni).then(getSsoSessionData).catch(swallowError)
346
- ];
347
- });
348
- });
349
- return function loadSsoSessionData() {
350
- return _ref.apply(this, arguments);
351
- };
352
- }();
353
-
354
- var isSsoProfile = function(arg) {
355
- return arg && (typeof arg.sso_start_url === "string" || typeof arg.sso_account_id === "string" || typeof arg.sso_session === "string" || typeof arg.sso_region === "string" || typeof arg.sso_role_name === "string");
356
- };
357
-
358
- var EXPIRE_WINDOW_MS = 5 * 60 * 1000;
359
- var REFRESH_MESSAGE = "To refresh this SSO session run 'aws sso login' with the corresponding profile.";
360
-
361
- function asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, key, arg) {
362
- try {
363
- var info = gen[key](arg);
364
- var value = info.value;
365
- } catch (error) {
366
- reject(error);
367
- return;
368
- }
369
- if (info.done) {
370
- resolve(value);
371
- } else {
372
- Promise.resolve(value).then(_next, _throw);
373
- }
374
- }
375
- function _async_to_generator$4(fn) {
376
- return function() {
377
- var self = this, args = arguments;
378
- return new Promise(function(resolve, reject) {
379
- var gen = fn.apply(self, args);
380
- function _next(value) {
381
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "next", value);
382
- }
383
- function _throw(err) {
384
- asyncGeneratorStep$4(gen, resolve, reject, _next, _throw, "throw", err);
385
- }
386
- _next(undefined);
387
- });
388
- };
389
- }
390
- function _ts_generator$4(thisArg, body) {
391
- var f, y, t, g, _ = {
392
- label: 0,
393
- sent: function() {
394
- if (t[0] & 1) throw t[1];
395
- return t[1];
396
- },
397
- trys: [],
398
- ops: []
399
- };
400
- return g = {
401
- next: verb(0),
402
- "throw": verb(1),
403
- "return": verb(2)
404
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
405
- return this;
406
- }), g;
407
- function verb(n) {
408
- return function(v) {
409
- return step([
410
- n,
411
- v
412
- ]);
413
- };
414
- }
415
- function step(op) {
416
- if (f) throw new TypeError("Generator is already executing.");
417
- while(_)try {
418
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
419
- if (y = 0, t) op = [
420
- op[0] & 2,
421
- t.value
422
- ];
423
- switch(op[0]){
424
- case 0:
425
- case 1:
426
- t = op;
427
- break;
428
- case 4:
429
- _.label++;
430
- return {
431
- value: op[1],
432
- done: false
433
- };
434
- case 5:
435
- _.label++;
436
- y = op[1];
437
- op = [
438
- 0
439
- ];
440
- continue;
441
- case 7:
442
- op = _.ops.pop();
443
- _.trys.pop();
444
- continue;
445
- default:
446
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
447
- _ = 0;
448
- continue;
449
- }
450
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
451
- _.label = op[1];
452
- break;
453
- }
454
- if (op[0] === 6 && _.label < t[1]) {
455
- _.label = t[1];
456
- t = op;
457
- break;
458
- }
459
- if (t && _.label < t[2]) {
460
- _.label = t[2];
461
- _.ops.push(op);
462
- break;
463
- }
464
- if (t[2]) _.ops.pop();
465
- _.trys.pop();
466
- continue;
467
- }
468
- op = body.call(thisArg, _);
469
- } catch (e) {
470
- op = [
471
- 6,
472
- e
473
- ];
474
- y = 0;
475
- } finally{
476
- f = t = 0;
477
- }
478
- if (op[0] & 5) throw op[1];
479
- return {
480
- value: op[0] ? op[1] : void 0,
481
- done: true
482
- };
483
- }
484
- }
485
- var getSsoOidcClient = function() {
486
- var _ref = _async_to_generator$4(function(ssoRegion) {
487
- var init, _init_clientConfig, _init_clientConfig1, _init_parentClientConfig, SSOOIDCClient, _init_clientConfig2, _init_clientConfig_logger, ssoOidcClient;
488
- var _arguments = arguments;
489
- return _ts_generator$4(this, function(_state) {
490
- switch(_state.label){
491
- case 0:
492
- init = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : {};
493
- return [
494
- 4,
495
- import('./index.esm9.js')
496
- ];
497
- case 1:
498
- SSOOIDCClient = _state.sent().SSOOIDCClient;
499
- ssoOidcClient = new SSOOIDCClient(Object.assign({}, (_init_clientConfig2 = init.clientConfig) !== null && _init_clientConfig2 !== void 0 ? _init_clientConfig2 : {}, {
500
- region: ssoRegion !== null && ssoRegion !== void 0 ? ssoRegion : (_init_clientConfig = init.clientConfig) === null || _init_clientConfig === void 0 ? void 0 : _init_clientConfig.region,
501
- logger: (_init_clientConfig_logger = (_init_clientConfig1 = init.clientConfig) === null || _init_clientConfig1 === void 0 ? void 0 : _init_clientConfig1.logger) !== null && _init_clientConfig_logger !== void 0 ? _init_clientConfig_logger : (_init_parentClientConfig = init.parentClientConfig) === null || _init_parentClientConfig === void 0 ? void 0 : _init_parentClientConfig.logger
502
- }));
503
- return [
504
- 2,
505
- ssoOidcClient
506
- ];
507
- }
508
- });
509
- });
510
- return function getSsoOidcClient(ssoRegion) {
511
- return _ref.apply(this, arguments);
512
- };
513
- }();
514
-
515
- function asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, key, arg) {
516
- try {
517
- var info = gen[key](arg);
518
- var value = info.value;
519
- } catch (error) {
520
- reject(error);
521
- return;
522
- }
523
- if (info.done) {
524
- resolve(value);
525
- } else {
526
- Promise.resolve(value).then(_next, _throw);
527
- }
528
- }
529
- function _async_to_generator$3(fn) {
530
- return function() {
531
- var self = this, args = arguments;
532
- return new Promise(function(resolve, reject) {
533
- var gen = fn.apply(self, args);
534
- function _next(value) {
535
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "next", value);
536
- }
537
- function _throw(err) {
538
- asyncGeneratorStep$3(gen, resolve, reject, _next, _throw, "throw", err);
539
- }
540
- _next(undefined);
541
- });
542
- };
543
- }
544
- function _ts_generator$3(thisArg, body) {
545
- var f, y, t, g, _ = {
546
- label: 0,
547
- sent: function() {
548
- if (t[0] & 1) throw t[1];
549
- return t[1];
550
- },
551
- trys: [],
552
- ops: []
553
- };
554
- return g = {
555
- next: verb(0),
556
- "throw": verb(1),
557
- "return": verb(2)
558
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
559
- return this;
560
- }), g;
561
- function verb(n) {
562
- return function(v) {
563
- return step([
564
- n,
565
- v
566
- ]);
567
- };
568
- }
569
- function step(op) {
570
- if (f) throw new TypeError("Generator is already executing.");
571
- while(_)try {
572
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
573
- if (y = 0, t) op = [
574
- op[0] & 2,
575
- t.value
576
- ];
577
- switch(op[0]){
578
- case 0:
579
- case 1:
580
- t = op;
581
- break;
582
- case 4:
583
- _.label++;
584
- return {
585
- value: op[1],
586
- done: false
587
- };
588
- case 5:
589
- _.label++;
590
- y = op[1];
591
- op = [
592
- 0
593
- ];
594
- continue;
595
- case 7:
596
- op = _.ops.pop();
597
- _.trys.pop();
598
- continue;
599
- default:
600
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
601
- _ = 0;
602
- continue;
603
- }
604
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
605
- _.label = op[1];
606
- break;
607
- }
608
- if (op[0] === 6 && _.label < t[1]) {
609
- _.label = t[1];
610
- t = op;
611
- break;
612
- }
613
- if (t && _.label < t[2]) {
614
- _.label = t[2];
615
- _.ops.push(op);
616
- break;
617
- }
618
- if (t[2]) _.ops.pop();
619
- _.trys.pop();
620
- continue;
621
- }
622
- op = body.call(thisArg, _);
623
- } catch (e) {
624
- op = [
625
- 6,
626
- e
627
- ];
628
- y = 0;
629
- } finally{
630
- f = t = 0;
631
- }
632
- if (op[0] & 5) throw op[1];
633
- return {
634
- value: op[0] ? op[1] : void 0,
635
- done: true
636
- };
637
- }
638
- }
639
- var getNewSsoOidcToken = function() {
640
- var _ref = _async_to_generator$3(function(ssoToken, ssoRegion) {
641
- var init, CreateTokenCommand, ssoOidcClient;
642
- var _arguments = arguments;
643
- return _ts_generator$3(this, function(_state) {
644
- switch(_state.label){
645
- case 0:
646
- init = _arguments.length > 2 && _arguments[2] !== void 0 ? _arguments[2] : {};
647
- return [
648
- 4,
649
- import('./index.esm9.js')
650
- ];
651
- case 1:
652
- CreateTokenCommand = _state.sent().CreateTokenCommand;
653
- return [
654
- 4,
655
- getSsoOidcClient(ssoRegion, init)
656
- ];
657
- case 2:
658
- ssoOidcClient = _state.sent();
659
- return [
660
- 2,
661
- ssoOidcClient.send(new CreateTokenCommand({
662
- clientId: ssoToken.clientId,
663
- clientSecret: ssoToken.clientSecret,
664
- refreshToken: ssoToken.refreshToken,
665
- grantType: "refresh_token"
666
- }))
667
- ];
668
- }
669
- });
670
- });
671
- return function getNewSsoOidcToken(ssoToken, ssoRegion) {
672
- return _ref.apply(this, arguments);
673
- };
674
- }();
675
-
676
- var validateTokenExpiry = function(token) {
677
- if (token.expiration && token.expiration.getTime() < Date.now()) {
678
- throw new TokenProviderError("Token is expired. ".concat(REFRESH_MESSAGE), false);
679
- }
680
- };
681
-
682
- var validateTokenKey = function(key, value) {
683
- var forRefresh = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false;
684
- if (typeof value === "undefined") {
685
- throw new TokenProviderError("Value not present for '".concat(key, "' in SSO Token").concat(forRefresh ? ". Cannot refresh" : "", ". ").concat(REFRESH_MESSAGE), false);
686
- }
687
- };
688
-
689
- var writeFile = promises.writeFile;
690
- var writeSSOTokenToFile = function(id, ssoToken) {
691
- var tokenFilepath = getSSOTokenFilepath(id);
692
- var tokenString = JSON.stringify(ssoToken, null, 2);
693
- return writeFile(tokenFilepath, tokenString);
694
- };
695
-
696
- function asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, key, arg) {
697
- try {
698
- var info = gen[key](arg);
699
- var value = info.value;
700
- } catch (error) {
701
- reject(error);
702
- return;
703
- }
704
- if (info.done) {
705
- resolve(value);
706
- } else {
707
- Promise.resolve(value).then(_next, _throw);
708
- }
709
- }
710
- function _async_to_generator$2(fn) {
711
- return function() {
712
- var self = this, args = arguments;
713
- return new Promise(function(resolve, reject) {
714
- var gen = fn.apply(self, args);
715
- function _next(value) {
716
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "next", value);
717
- }
718
- function _throw(err) {
719
- asyncGeneratorStep$2(gen, resolve, reject, _next, _throw, "throw", err);
720
- }
721
- _next(undefined);
722
- });
723
- };
724
- }
725
- function _define_property$1(obj, key, value) {
726
- if (key in obj) {
727
- Object.defineProperty(obj, key, {
728
- value: value,
729
- enumerable: true,
730
- configurable: true,
731
- writable: true
732
- });
733
- } else {
734
- obj[key] = value;
735
- }
736
- return obj;
737
- }
738
- function _object_spread$1(target) {
739
- for(var i = 1; i < arguments.length; i++){
740
- var source = arguments[i] != null ? arguments[i] : {};
741
- var ownKeys = Object.keys(source);
742
- if (typeof Object.getOwnPropertySymbols === "function") {
743
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
744
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
745
- }));
746
- }
747
- ownKeys.forEach(function(key) {
748
- _define_property$1(target, key, source[key]);
749
- });
750
- }
751
- return target;
752
- }
753
- function ownKeys(object, enumerableOnly) {
754
- var keys = Object.keys(object);
755
- if (Object.getOwnPropertySymbols) {
756
- var symbols = Object.getOwnPropertySymbols(object);
757
- if (enumerableOnly) {
758
- symbols = symbols.filter(function(sym) {
759
- return Object.getOwnPropertyDescriptor(object, sym).enumerable;
760
- });
761
- }
762
- keys.push.apply(keys, symbols);
763
- }
764
- return keys;
765
- }
766
- function _object_spread_props(target, source) {
767
- source = source != null ? source : {};
768
- if (Object.getOwnPropertyDescriptors) {
769
- Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
770
- } else {
771
- ownKeys(Object(source)).forEach(function(key) {
772
- Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
773
- });
774
- }
775
- return target;
776
- }
777
- function _ts_generator$2(thisArg, body) {
778
- var f, y, t, g, _ = {
779
- label: 0,
780
- sent: function() {
781
- if (t[0] & 1) throw t[1];
782
- return t[1];
783
- },
784
- trys: [],
785
- ops: []
786
- };
787
- return g = {
788
- next: verb(0),
789
- "throw": verb(1),
790
- "return": verb(2)
791
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
792
- return this;
793
- }), g;
794
- function verb(n) {
795
- return function(v) {
796
- return step([
797
- n,
798
- v
799
- ]);
800
- };
801
- }
802
- function step(op) {
803
- if (f) throw new TypeError("Generator is already executing.");
804
- while(_)try {
805
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
806
- if (y = 0, t) op = [
807
- op[0] & 2,
808
- t.value
809
- ];
810
- switch(op[0]){
811
- case 0:
812
- case 1:
813
- t = op;
814
- break;
815
- case 4:
816
- _.label++;
817
- return {
818
- value: op[1],
819
- done: false
820
- };
821
- case 5:
822
- _.label++;
823
- y = op[1];
824
- op = [
825
- 0
826
- ];
827
- continue;
828
- case 7:
829
- op = _.ops.pop();
830
- _.trys.pop();
831
- continue;
832
- default:
833
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
834
- _ = 0;
835
- continue;
836
- }
837
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
838
- _.label = op[1];
839
- break;
840
- }
841
- if (op[0] === 6 && _.label < t[1]) {
842
- _.label = t[1];
843
- t = op;
844
- break;
845
- }
846
- if (t && _.label < t[2]) {
847
- _.label = t[2];
848
- _.ops.push(op);
849
- break;
850
- }
851
- if (t[2]) _.ops.pop();
852
- _.trys.pop();
853
- continue;
854
- }
855
- op = body.call(thisArg, _);
856
- } catch (e) {
857
- op = [
858
- 6,
859
- e
860
- ];
861
- y = 0;
862
- } finally{
863
- f = t = 0;
864
- }
865
- if (op[0] & 5) throw op[1];
866
- return {
867
- value: op[0] ? op[1] : void 0,
868
- done: true
869
- };
870
- }
871
- }
872
- var lastRefreshAttemptTime = new Date(0);
873
- var fromSso = function() {
874
- var _init = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
875
- return /*#__PURE__*/ _async_to_generator$2(function() {
876
- var callerClientConfig, _init_logger, init, profiles, _init_profile, profileName, profile, ssoSessionName, ssoSessions, ssoSession, _i, _iter, ssoSessionRequiredKey, ssoRegion, ssoToken, accessToken, expiresAt, existingToken, newSsoOidcToken, newTokenExpiration;
877
- var _arguments = arguments;
878
- return _ts_generator$2(this, function(_state) {
879
- switch(_state.label){
880
- case 0:
881
- callerClientConfig = (_arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}).callerClientConfig;
882
- init = _object_spread_props(_object_spread$1({}, _init), {
883
- parentClientConfig: _object_spread$1({}, callerClientConfig, _init.parentClientConfig)
884
- });
885
- (_init_logger = init.logger) === null || _init_logger === void 0 ? void 0 : _init_logger.debug("@aws-sdk/token-providers - fromSso");
886
- return [
887
- 4,
888
- parseKnownFiles(init)
889
- ];
890
- case 1:
891
- profiles = _state.sent();
892
- profileName = getProfileName({
893
- profile: (_init_profile = init.profile) !== null && _init_profile !== void 0 ? _init_profile : callerClientConfig === null || callerClientConfig === void 0 ? void 0 : callerClientConfig.profile
894
- });
895
- profile = profiles[profileName];
896
- if (!profile) {
897
- throw new TokenProviderError("Profile '".concat(profileName, "' could not be found in shared credentials file."), false);
898
- } else if (!profile["sso_session"]) {
899
- throw new TokenProviderError("Profile '".concat(profileName, "' is missing required property 'sso_session'."));
900
- }
901
- ssoSessionName = profile["sso_session"];
902
- return [
903
- 4,
904
- loadSsoSessionData(init)
905
- ];
906
- case 2:
907
- ssoSessions = _state.sent();
908
- ssoSession = ssoSessions[ssoSessionName];
909
- if (!ssoSession) {
910
- throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' could not be found in shared credentials file."), false);
911
- }
912
- for(_i = 0, _iter = [
913
- "sso_start_url",
914
- "sso_region"
915
- ]; _i < _iter.length; _i++){
916
- ssoSessionRequiredKey = _iter[_i];
917
- if (!ssoSession[ssoSessionRequiredKey]) {
918
- throw new TokenProviderError("Sso session '".concat(ssoSessionName, "' is missing required property '").concat(ssoSessionRequiredKey, "'."), false);
919
- }
920
- }
921
- ssoSession["sso_start_url"];
922
- ssoRegion = ssoSession["sso_region"];
923
- _state.label = 3;
924
- case 3:
925
- _state.trys.push([
926
- 3,
927
- 5,
928
- ,
929
- 6
930
- ]);
931
- return [
932
- 4,
933
- getSSOTokenFromFile(ssoSessionName)
934
- ];
935
- case 4:
936
- ssoToken = _state.sent();
937
- return [
938
- 3,
939
- 6
940
- ];
941
- case 5:
942
- _state.sent();
943
- throw new TokenProviderError("The SSO session token associated with profile=".concat(profileName, " was not found or is invalid. ").concat(REFRESH_MESSAGE), false);
944
- case 6:
945
- validateTokenKey("accessToken", ssoToken.accessToken);
946
- validateTokenKey("expiresAt", ssoToken.expiresAt);
947
- accessToken = ssoToken.accessToken, expiresAt = ssoToken.expiresAt;
948
- existingToken = {
949
- token: accessToken,
950
- expiration: new Date(expiresAt)
951
- };
952
- if (existingToken.expiration.getTime() - Date.now() > EXPIRE_WINDOW_MS) {
953
- return [
954
- 2,
955
- existingToken
956
- ];
957
- }
958
- if (Date.now() - lastRefreshAttemptTime.getTime() < 30 * 1000) {
959
- validateTokenExpiry(existingToken);
960
- return [
961
- 2,
962
- existingToken
963
- ];
964
- }
965
- validateTokenKey("clientId", ssoToken.clientId, true);
966
- validateTokenKey("clientSecret", ssoToken.clientSecret, true);
967
- validateTokenKey("refreshToken", ssoToken.refreshToken, true);
968
- _state.label = 7;
969
- case 7:
970
- _state.trys.push([
971
- 7,
972
- 13,
973
- ,
974
- 14
975
- ]);
976
- lastRefreshAttemptTime.setTime(Date.now());
977
- return [
978
- 4,
979
- getNewSsoOidcToken(ssoToken, ssoRegion, init)
980
- ];
981
- case 8:
982
- newSsoOidcToken = _state.sent();
983
- validateTokenKey("accessToken", newSsoOidcToken.accessToken);
984
- validateTokenKey("expiresIn", newSsoOidcToken.expiresIn);
985
- newTokenExpiration = new Date(Date.now() + newSsoOidcToken.expiresIn * 1000);
986
- _state.label = 9;
987
- case 9:
988
- _state.trys.push([
989
- 9,
990
- 11,
991
- ,
992
- 12
993
- ]);
994
- return [
995
- 4,
996
- writeSSOTokenToFile(ssoSessionName, _object_spread_props(_object_spread$1({}, ssoToken), {
997
- accessToken: newSsoOidcToken.accessToken,
998
- expiresAt: newTokenExpiration.toISOString(),
999
- refreshToken: newSsoOidcToken.refreshToken
1000
- }))
1001
- ];
1002
- case 10:
1003
- _state.sent();
1004
- return [
1005
- 3,
1006
- 12
1007
- ];
1008
- case 11:
1009
- _state.sent();
1010
- return [
1011
- 3,
1012
- 12
1013
- ];
1014
- case 12:
1015
- return [
1016
- 2,
1017
- {
1018
- token: newSsoOidcToken.accessToken,
1019
- expiration: newTokenExpiration
1020
- }
1021
- ];
1022
- case 13:
1023
- _state.sent();
1024
- validateTokenExpiry(existingToken);
1025
- return [
1026
- 2,
1027
- existingToken
1028
- ];
1029
- case 14:
1030
- return [
1031
- 2
1032
- ];
1033
- }
1034
- });
1035
- });
1036
- };
1037
-
1038
- function asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, key, arg) {
1039
- try {
1040
- var info = gen[key](arg);
1041
- var value = info.value;
1042
- } catch (error) {
1043
- reject(error);
1044
- return;
1045
- }
1046
- if (info.done) {
1047
- resolve(value);
1048
- } else {
1049
- Promise.resolve(value).then(_next, _throw);
1050
- }
1051
- }
1052
- function _async_to_generator$1(fn) {
1053
- return function() {
1054
- var self = this, args = arguments;
1055
- return new Promise(function(resolve, reject) {
1056
- var gen = fn.apply(self, args);
1057
- function _next(value) {
1058
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "next", value);
1059
- }
1060
- function _throw(err) {
1061
- asyncGeneratorStep$1(gen, resolve, reject, _next, _throw, "throw", err);
1062
- }
1063
- _next(undefined);
1064
- });
1065
- };
1066
- }
1067
- function _define_property(obj, key, value) {
1068
- if (key in obj) {
1069
- Object.defineProperty(obj, key, {
1070
- value: value,
1071
- enumerable: true,
1072
- configurable: true,
1073
- writable: true
1074
- });
1075
- } else {
1076
- obj[key] = value;
1077
- }
1078
- return obj;
1079
- }
1080
- function _object_spread(target) {
1081
- for(var i = 1; i < arguments.length; i++){
1082
- var source = arguments[i] != null ? arguments[i] : {};
1083
- var ownKeys = Object.keys(source);
1084
- if (typeof Object.getOwnPropertySymbols === "function") {
1085
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1086
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1087
- }));
1088
- }
1089
- ownKeys.forEach(function(key) {
1090
- _define_property(target, key, source[key]);
1091
- });
1092
- }
1093
- return target;
1094
- }
1095
- function _ts_generator$1(thisArg, body) {
1096
- var f, y, t, g, _ = {
1097
- label: 0,
1098
- sent: function() {
1099
- if (t[0] & 1) throw t[1];
1100
- return t[1];
1101
- },
1102
- trys: [],
1103
- ops: []
1104
- };
1105
- return g = {
1106
- next: verb(0),
1107
- "throw": verb(1),
1108
- "return": verb(2)
1109
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1110
- return this;
1111
- }), g;
1112
- function verb(n) {
1113
- return function(v) {
1114
- return step([
1115
- n,
1116
- v
1117
- ]);
1118
- };
1119
- }
1120
- function step(op) {
1121
- if (f) throw new TypeError("Generator is already executing.");
1122
- while(_)try {
1123
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1124
- if (y = 0, t) op = [
1125
- op[0] & 2,
1126
- t.value
1127
- ];
1128
- switch(op[0]){
1129
- case 0:
1130
- case 1:
1131
- t = op;
1132
- break;
1133
- case 4:
1134
- _.label++;
1135
- return {
1136
- value: op[1],
1137
- done: false
1138
- };
1139
- case 5:
1140
- _.label++;
1141
- y = op[1];
1142
- op = [
1143
- 0
1144
- ];
1145
- continue;
1146
- case 7:
1147
- op = _.ops.pop();
1148
- _.trys.pop();
1149
- continue;
1150
- default:
1151
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1152
- _ = 0;
1153
- continue;
1154
- }
1155
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1156
- _.label = op[1];
1157
- break;
1158
- }
1159
- if (op[0] === 6 && _.label < t[1]) {
1160
- _.label = t[1];
1161
- t = op;
1162
- break;
1163
- }
1164
- if (t && _.label < t[2]) {
1165
- _.label = t[2];
1166
- _.ops.push(op);
1167
- break;
1168
- }
1169
- if (t[2]) _.ops.pop();
1170
- _.trys.pop();
1171
- continue;
1172
- }
1173
- op = body.call(thisArg, _);
1174
- } catch (e) {
1175
- op = [
1176
- 6,
1177
- e
1178
- ];
1179
- y = 0;
1180
- } finally{
1181
- f = t = 0;
1182
- }
1183
- if (op[0] & 5) throw op[1];
1184
- return {
1185
- value: op[0] ? op[1] : void 0,
1186
- done: true
1187
- };
1188
- }
1189
- }
1190
- var SHOULD_FAIL_CREDENTIAL_CHAIN = false;
1191
- var resolveSSOCredentials = function() {
1192
- var _ref = _async_to_generator$1(function(param) {
1193
- var ssoStartUrl, ssoSession, ssoAccountId, ssoRegion, ssoRoleName, ssoClient, clientConfig, parentClientConfig, profile, logger, token, refreshMessage, _token, e, accessToken, _ref, SSOClient, GetRoleCredentialsCommand, _clientConfig_logger, _clientConfig_region, sso, ssoResp, e2, tmp, _ref1, accessKeyId, secretAccessKey, sessionToken, expiration, credentialScope, accountId, credentials;
1194
- return _ts_generator$1(this, function(_state) {
1195
- switch(_state.label){
1196
- case 0:
1197
- ssoStartUrl = param.ssoStartUrl, ssoSession = param.ssoSession, ssoAccountId = param.ssoAccountId, ssoRegion = param.ssoRegion, ssoRoleName = param.ssoRoleName, ssoClient = param.ssoClient, clientConfig = param.clientConfig, parentClientConfig = param.parentClientConfig, profile = param.profile, logger = param.logger;
1198
- refreshMessage = "To refresh this SSO session run aws sso login with the corresponding profile.";
1199
- if (!ssoSession) return [
1200
- 3,
1201
- 5
1202
- ];
1203
- _state.label = 1;
1204
- case 1:
1205
- _state.trys.push([
1206
- 1,
1207
- 3,
1208
- ,
1209
- 4
1210
- ]);
1211
- return [
1212
- 4,
1213
- fromSso({
1214
- profile: profile
1215
- })()
1216
- ];
1217
- case 2:
1218
- _token = _state.sent();
1219
- token = {
1220
- accessToken: _token.token,
1221
- expiresAt: new Date(_token.expiration).toISOString()
1222
- };
1223
- return [
1224
- 3,
1225
- 4
1226
- ];
1227
- case 3:
1228
- e = _state.sent();
1229
- throw new CredentialsProviderError(e.message, {
1230
- tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1231
- logger: logger
1232
- });
1233
- case 4:
1234
- return [
1235
- 3,
1236
- 8
1237
- ];
1238
- case 5:
1239
- _state.trys.push([
1240
- 5,
1241
- 7,
1242
- ,
1243
- 8
1244
- ]);
1245
- return [
1246
- 4,
1247
- getSSOTokenFromFile(ssoStartUrl)
1248
- ];
1249
- case 6:
1250
- token = _state.sent();
1251
- return [
1252
- 3,
1253
- 8
1254
- ];
1255
- case 7:
1256
- _state.sent();
1257
- throw new CredentialsProviderError("The SSO session associated with this profile is invalid. ".concat(refreshMessage), {
1258
- tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1259
- logger: logger
1260
- });
1261
- case 8:
1262
- if (new Date(token.expiresAt).getTime() - Date.now() <= 0) {
1263
- throw new CredentialsProviderError("The SSO session associated with this profile has expired. ".concat(refreshMessage), {
1264
- tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1265
- logger: logger
1266
- });
1267
- }
1268
- accessToken = token.accessToken;
1269
- return [
1270
- 4,
1271
- import('./loadSso.esm.js')
1272
- ];
1273
- case 9:
1274
- _ref = _state.sent(), SSOClient = _ref.SSOClient, GetRoleCredentialsCommand = _ref.GetRoleCredentialsCommand;
1275
- sso = ssoClient || new SSOClient(Object.assign({}, clientConfig !== null && clientConfig !== void 0 ? clientConfig : {}, {
1276
- logger: (_clientConfig_logger = clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.logger) !== null && _clientConfig_logger !== void 0 ? _clientConfig_logger : parentClientConfig === null || parentClientConfig === void 0 ? void 0 : parentClientConfig.logger,
1277
- region: (_clientConfig_region = clientConfig === null || clientConfig === void 0 ? void 0 : clientConfig.region) !== null && _clientConfig_region !== void 0 ? _clientConfig_region : ssoRegion
1278
- }));
1279
- _state.label = 10;
1280
- case 10:
1281
- _state.trys.push([
1282
- 10,
1283
- 12,
1284
- ,
1285
- 13
1286
- ]);
1287
- return [
1288
- 4,
1289
- sso.send(new GetRoleCredentialsCommand({
1290
- accountId: ssoAccountId,
1291
- roleName: ssoRoleName,
1292
- accessToken: accessToken
1293
- }))
1294
- ];
1295
- case 11:
1296
- ssoResp = _state.sent();
1297
- return [
1298
- 3,
1299
- 13
1300
- ];
1301
- case 12:
1302
- e2 = _state.sent();
1303
- throw new CredentialsProviderError(e2, {
1304
- tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1305
- logger: logger
1306
- });
1307
- case 13:
1308
- tmp = ssoResp.roleCredentials, _ref1 = tmp === void 0 ? {} : tmp, accessKeyId = _ref1.accessKeyId, secretAccessKey = _ref1.secretAccessKey, sessionToken = _ref1.sessionToken, expiration = _ref1.expiration, credentialScope = _ref1.credentialScope, accountId = _ref1.accountId;
1309
- if (!accessKeyId || !secretAccessKey || !sessionToken || !expiration) {
1310
- throw new CredentialsProviderError("SSO returns an invalid temporary credential.", {
1311
- tryNextLink: SHOULD_FAIL_CREDENTIAL_CHAIN,
1312
- logger: logger
1313
- });
1314
- }
1315
- credentials = _object_spread({
1316
- accessKeyId: accessKeyId,
1317
- secretAccessKey: secretAccessKey,
1318
- sessionToken: sessionToken,
1319
- expiration: new Date(expiration)
1320
- }, credentialScope && {
1321
- credentialScope: credentialScope
1322
- }, accountId && {
1323
- accountId: accountId
1324
- });
1325
- if (ssoSession) {
1326
- setCredentialFeature(credentials, "CREDENTIALS_SSO", "s");
1327
- } else {
1328
- setCredentialFeature(credentials, "CREDENTIALS_SSO_LEGACY", "u");
1329
- }
1330
- return [
1331
- 2,
1332
- credentials
1333
- ];
1334
- }
1335
- });
1336
- });
1337
- return function resolveSSOCredentials(_) {
1338
- return _ref.apply(this, arguments);
1339
- };
1340
- }();
1341
-
1342
- var validateSsoProfile = function(profile, logger) {
1343
- var sso_start_url = profile.sso_start_url, sso_account_id = profile.sso_account_id, sso_region = profile.sso_region, sso_role_name = profile.sso_role_name;
1344
- if (!sso_start_url || !sso_account_id || !sso_region || !sso_role_name) {
1345
- throw new CredentialsProviderError('Profile is configured with invalid SSO credentials. Required parameters "sso_account_id", ' + '"sso_region", "sso_role_name", "sso_start_url". Got '.concat(Object.keys(profile).join(", "), "\nReference: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-sso.html"), {
1346
- tryNextLink: false,
1347
- logger: logger
1348
- });
1349
- }
1350
- return profile;
1351
- };
1352
-
1353
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
1354
- try {
1355
- var info = gen[key](arg);
1356
- var value = info.value;
1357
- } catch (error) {
1358
- reject(error);
1359
- return;
1360
- }
1361
- if (info.done) {
1362
- resolve(value);
1363
- } else {
1364
- Promise.resolve(value).then(_next, _throw);
1365
- }
1366
- }
1367
- function _async_to_generator(fn) {
1368
- return function() {
1369
- var self = this, args = arguments;
1370
- return new Promise(function(resolve, reject) {
1371
- var gen = fn.apply(self, args);
1372
- function _next(value) {
1373
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
1374
- }
1375
- function _throw(err) {
1376
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
1377
- }
1378
- _next(undefined);
1379
- });
1380
- };
1381
- }
1382
- function _ts_generator(thisArg, body) {
1383
- var f, y, t, g, _ = {
1384
- label: 0,
1385
- sent: function() {
1386
- if (t[0] & 1) throw t[1];
1387
- return t[1];
1388
- },
1389
- trys: [],
1390
- ops: []
1391
- };
1392
- return g = {
1393
- next: verb(0),
1394
- "throw": verb(1),
1395
- "return": verb(2)
1396
- }, typeof Symbol === "function" && (g[Symbol.iterator] = function() {
1397
- return this;
1398
- }), g;
1399
- function verb(n) {
1400
- return function(v) {
1401
- return step([
1402
- n,
1403
- v
1404
- ]);
1405
- };
1406
- }
1407
- function step(op) {
1408
- if (f) throw new TypeError("Generator is already executing.");
1409
- while(_)try {
1410
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
1411
- if (y = 0, t) op = [
1412
- op[0] & 2,
1413
- t.value
1414
- ];
1415
- switch(op[0]){
1416
- case 0:
1417
- case 1:
1418
- t = op;
1419
- break;
1420
- case 4:
1421
- _.label++;
1422
- return {
1423
- value: op[1],
1424
- done: false
1425
- };
1426
- case 5:
1427
- _.label++;
1428
- y = op[1];
1429
- op = [
1430
- 0
1431
- ];
1432
- continue;
1433
- case 7:
1434
- op = _.ops.pop();
1435
- _.trys.pop();
1436
- continue;
1437
- default:
1438
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
1439
- _ = 0;
1440
- continue;
1441
- }
1442
- if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
1443
- _.label = op[1];
1444
- break;
1445
- }
1446
- if (op[0] === 6 && _.label < t[1]) {
1447
- _.label = t[1];
1448
- t = op;
1449
- break;
1450
- }
1451
- if (t && _.label < t[2]) {
1452
- _.label = t[2];
1453
- _.ops.push(op);
1454
- break;
1455
- }
1456
- if (t[2]) _.ops.pop();
1457
- _.trys.pop();
1458
- continue;
1459
- }
1460
- op = body.call(thisArg, _);
1461
- } catch (e) {
1462
- op = [
1463
- 6,
1464
- e
1465
- ];
1466
- y = 0;
1467
- } finally{
1468
- f = t = 0;
1469
- }
1470
- if (op[0] & 5) throw op[1];
1471
- return {
1472
- value: op[0] ? op[1] : void 0,
1473
- done: true
1474
- };
1475
- }
1476
- }
1477
- var fromSSO = function() {
1478
- var init = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1479
- return /*#__PURE__*/ _async_to_generator(function() {
1480
- var callerClientConfig, _init_logger, ssoStartUrl, ssoAccountId, ssoRegion, ssoRoleName, ssoSession, ssoClient, _init_profile, profileName, profiles, profile, ssoSessions, session, conflictMsg, _validateSsoProfile, sso_start_url, sso_account_id, sso_region, sso_role_name, sso_session;
1481
- var _arguments = arguments;
1482
- return _ts_generator(this, function(_state) {
1483
- switch(_state.label){
1484
- case 0:
1485
- callerClientConfig = (_arguments.length > 0 && _arguments[0] !== void 0 ? _arguments[0] : {}).callerClientConfig;
1486
- (_init_logger = init.logger) === null || _init_logger === void 0 ? void 0 : _init_logger.debug("@aws-sdk/credential-provider-sso - fromSSO");
1487
- ssoStartUrl = init.ssoStartUrl, ssoAccountId = init.ssoAccountId, ssoRegion = init.ssoRegion, ssoRoleName = init.ssoRoleName, ssoSession = init.ssoSession;
1488
- ssoClient = init.ssoClient;
1489
- profileName = getProfileName({
1490
- profile: (_init_profile = init.profile) !== null && _init_profile !== void 0 ? _init_profile : callerClientConfig === null || callerClientConfig === void 0 ? void 0 : callerClientConfig.profile
1491
- });
1492
- if (!(!ssoStartUrl && !ssoAccountId && !ssoRegion && !ssoRoleName && !ssoSession)) return [
1493
- 3,
1494
- 4
1495
- ];
1496
- return [
1497
- 4,
1498
- parseKnownFiles(init)
1499
- ];
1500
- case 1:
1501
- profiles = _state.sent();
1502
- profile = profiles[profileName];
1503
- if (!profile) {
1504
- throw new CredentialsProviderError("Profile ".concat(profileName, " was not found."), {
1505
- logger: init.logger
1506
- });
1507
- }
1508
- if (!isSsoProfile(profile)) {
1509
- throw new CredentialsProviderError("Profile ".concat(profileName, " is not configured with SSO credentials."), {
1510
- logger: init.logger
1511
- });
1512
- }
1513
- if (!(profile === null || profile === void 0 ? void 0 : profile.sso_session)) return [
1514
- 3,
1515
- 3
1516
- ];
1517
- return [
1518
- 4,
1519
- loadSsoSessionData(init)
1520
- ];
1521
- case 2:
1522
- ssoSessions = _state.sent();
1523
- session = ssoSessions[profile.sso_session];
1524
- conflictMsg = " configurations in profile ".concat(profileName, " and sso-session ").concat(profile.sso_session);
1525
- if (ssoRegion && ssoRegion !== session.sso_region) {
1526
- throw new CredentialsProviderError("Conflicting SSO region" + conflictMsg, {
1527
- tryNextLink: false,
1528
- logger: init.logger
1529
- });
1530
- }
1531
- if (ssoStartUrl && ssoStartUrl !== session.sso_start_url) {
1532
- throw new CredentialsProviderError("Conflicting SSO start_url" + conflictMsg, {
1533
- tryNextLink: false,
1534
- logger: init.logger
1535
- });
1536
- }
1537
- profile.sso_region = session.sso_region;
1538
- profile.sso_start_url = session.sso_start_url;
1539
- _state.label = 3;
1540
- case 3:
1541
- _validateSsoProfile = validateSsoProfile(profile, init.logger), sso_start_url = _validateSsoProfile.sso_start_url, sso_account_id = _validateSsoProfile.sso_account_id, sso_region = _validateSsoProfile.sso_region, sso_role_name = _validateSsoProfile.sso_role_name, sso_session = _validateSsoProfile.sso_session;
1542
- return [
1543
- 2,
1544
- resolveSSOCredentials({
1545
- ssoStartUrl: sso_start_url,
1546
- ssoSession: sso_session,
1547
- ssoAccountId: sso_account_id,
1548
- ssoRegion: sso_region,
1549
- ssoRoleName: sso_role_name,
1550
- ssoClient: ssoClient,
1551
- clientConfig: init.clientConfig,
1552
- parentClientConfig: init.parentClientConfig,
1553
- profile: profileName
1554
- })
1555
- ];
1556
- case 4:
1557
- if (!ssoStartUrl || !ssoAccountId || !ssoRegion || !ssoRoleName) {
1558
- throw new CredentialsProviderError("Incomplete configuration. The fromSSO() argument hash must include " + '"ssoStartUrl", "ssoAccountId", "ssoRegion", "ssoRoleName"', {
1559
- tryNextLink: false,
1560
- logger: init.logger
1561
- });
1562
- } else {
1563
- return [
1564
- 2,
1565
- resolveSSOCredentials({
1566
- ssoStartUrl: ssoStartUrl,
1567
- ssoSession: ssoSession,
1568
- ssoAccountId: ssoAccountId,
1569
- ssoRegion: ssoRegion,
1570
- ssoRoleName: ssoRoleName,
1571
- ssoClient: ssoClient,
1572
- clientConfig: init.clientConfig,
1573
- parentClientConfig: init.parentClientConfig,
1574
- profile: profileName
1575
- })
1576
- ];
1577
- }
1578
- case 5:
1579
- return [
1580
- 2
1581
- ];
1582
- }
1583
- });
1584
- });
1585
- };
1586
-
1587
- export { fromSSO, isSsoProfile, validateSsoProfile };