1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.AuthClient = exports.DEFAULT_EAGER_REFRESH_THRESHOLD_MILLIS = exports.DEFAULT_UNIVERSE = void 0;
|
17 | const events_1 = require("events");
|
18 | const gaxios_1 = require("gaxios");
|
19 | const transporters_1 = require("../transporters");
|
20 | const util_1 = require("../util");
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | exports.DEFAULT_UNIVERSE = 'googleapis.com';
|
27 |
|
28 |
|
29 |
|
30 | exports.DEFAULT_EAGER_REFRESH_THRESHOLD_MILLIS = 5 * 60 * 1000;
|
31 | class AuthClient extends events_1.EventEmitter {
|
32 | constructor(opts = {}) {
|
33 | var _a, _b, _c, _d, _e;
|
34 | super();
|
35 | this.credentials = {};
|
36 | this.eagerRefreshThresholdMillis = exports.DEFAULT_EAGER_REFRESH_THRESHOLD_MILLIS;
|
37 | this.forceRefreshOnFailure = false;
|
38 | this.universeDomain = exports.DEFAULT_UNIVERSE;
|
39 | const options = (0, util_1.originalOrCamelOptions)(opts);
|
40 |
|
41 | this.projectId = (_a = options.get('project_id')) !== null && _a !== void 0 ? _a : null;
|
42 | this.quotaProjectId = options.get('quota_project_id');
|
43 | this.credentials = (_b = options.get('credentials')) !== null && _b !== void 0 ? _b : {};
|
44 | this.universeDomain = (_c = options.get('universe_domain')) !== null && _c !== void 0 ? _c : exports.DEFAULT_UNIVERSE;
|
45 |
|
46 | this.transporter = (_d = opts.transporter) !== null && _d !== void 0 ? _d : new transporters_1.DefaultTransporter();
|
47 | if (opts.transporterOptions) {
|
48 | this.transporter.defaults = opts.transporterOptions;
|
49 | }
|
50 | if (opts.eagerRefreshThresholdMillis) {
|
51 | this.eagerRefreshThresholdMillis = opts.eagerRefreshThresholdMillis;
|
52 | }
|
53 | this.forceRefreshOnFailure = (_e = opts.forceRefreshOnFailure) !== null && _e !== void 0 ? _e : false;
|
54 | }
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | get gaxios() {
|
61 | if (this.transporter instanceof gaxios_1.Gaxios) {
|
62 | return this.transporter;
|
63 | }
|
64 | else if (this.transporter instanceof transporters_1.DefaultTransporter) {
|
65 | return this.transporter.instance;
|
66 | }
|
67 | else if ('instance' in this.transporter &&
|
68 | this.transporter.instance instanceof gaxios_1.Gaxios) {
|
69 | return this.transporter.instance;
|
70 | }
|
71 | return null;
|
72 | }
|
73 | |
74 |
|
75 |
|
76 | setCredentials(credentials) {
|
77 | this.credentials = credentials;
|
78 | }
|
79 | |
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | addSharedMetadataHeaders(headers) {
|
88 |
|
89 |
|
90 |
|
91 | if (!headers['x-goog-user-project'] &&
|
92 | this.quotaProjectId) {
|
93 | headers['x-goog-user-project'] = this.quotaProjectId;
|
94 | }
|
95 | return headers;
|
96 | }
|
97 | |
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 | static get RETRY_CONFIG() {
|
107 | return {
|
108 | retry: true,
|
109 | retryConfig: {
|
110 | httpMethodsToRetry: ['GET', 'PUT', 'POST', 'HEAD', 'OPTIONS', 'DELETE'],
|
111 | },
|
112 | };
|
113 | }
|
114 | }
|
115 | exports.AuthClient = AuthClient;
|