externalclient.js
2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"use strict";
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExternalAccountClient = void 0;
const baseexternalclient_1 = require("./baseexternalclient");
const identitypoolclient_1 = require("./identitypoolclient");
const awsclient_1 = require("./awsclient");
/**
* Dummy class with no constructor. Developers are expected to use fromJSON.
*/
class ExternalAccountClient {
constructor() {
throw new Error('ExternalAccountClients should be initialized via: ' +
'ExternalAccountClient.fromJSON(), ' +
'directly via explicit constructors, eg. ' +
'new AwsClient(options), new IdentityPoolClient(options) or via ' +
'new GoogleAuth(options).getClient()');
}
/**
* This static method will instantiate the
* corresponding type of external account credential depending on the
* underlying credential source.
* @param options The external account options object typically loaded
* from the external account JSON credential file.
* @param additionalOptions Optional additional behavior customization
* options. These currently customize expiration threshold time and
* whether to retry on 401/403 API request errors.
* @return A BaseExternalAccountClient instance or null if the options
* provided do not correspond to an external account credential.
*/
static fromJSON(options, additionalOptions) {
var _a;
if (options && options.type === baseexternalclient_1.EXTERNAL_ACCOUNT_TYPE) {
if ((_a = options.credential_source) === null || _a === void 0 ? void 0 : _a.environment_id) {
return new awsclient_1.AwsClient(options, additionalOptions);
}
else {
return new identitypoolclient_1.IdentityPoolClient(options, additionalOptions);
}
}
else {
return null;
}
}
}
exports.ExternalAccountClient = ExternalAccountClient;
//# sourceMappingURL=externalclient.js.map