UNPKG

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