1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | Object.defineProperty(exports, "__esModule", { value: true });
|
20 | exports.IamClient = void 0;
|
21 | const grpc_1 = require("./grpc");
|
22 | const fallback_1 = require("./fallback");
|
23 | const createApiCall_1 = require("./createApiCall");
|
24 | const routingHeader = require("./routingHeader");
|
25 | const gapicConfig = require("./iam_policy_service_client_config.json");
|
26 | const fallback = require("./fallback");
|
27 | let version = require('../../package.json').version;
|
28 | const jsonProtos = require("../protos/iam_service.json");
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | class IamClient {
|
34 | constructor(gaxGrpc,
|
35 | // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
36 | options) {
|
37 | this._terminated = false;
|
38 | this.descriptors = { page: {}, stream: {}, longrunning: {} };
|
39 | this.innerApiCalls = {};
|
40 | this.gaxGrpc = gaxGrpc;
|
41 |
|
42 | const opts = Object.assign({
|
43 | servicePath: options.servicePath,
|
44 | port: options.port,
|
45 | clientConfig: options.clientConfig,
|
46 | apiEndpoint: options.apiEndpoint,
|
47 | fallback: options.fallback,
|
48 | }, options);
|
49 | version = opts.fallback ? fallback.version : version;
|
50 | this._gaxGrpc = opts.fallback
|
51 | ? new fallback_1.GrpcClient(opts)
|
52 | : new grpc_1.GrpcClient(opts);
|
53 | opts.scopes = this.constructor.scopes;
|
54 |
|
55 | this._opts = opts;
|
56 |
|
57 | this.auth = gaxGrpc.auth;
|
58 |
|
59 | const clientHeader = [`gax/${version}`, `gapic/${version}`];
|
60 | if (typeof process !== 'undefined' && 'versions' in process) {
|
61 | clientHeader.push(`gl-node/${process.versions.node}`);
|
62 | }
|
63 | else {
|
64 | clientHeader.push(`gl-web/${version}`);
|
65 | }
|
66 | if (!opts.fallback) {
|
67 | clientHeader.push(`grpc/${gaxGrpc.grpcVersion}`);
|
68 | }
|
69 | if (opts.libName && opts.libVersion) {
|
70 | clientHeader.push(`${opts.libName}/${opts.libVersion}`);
|
71 | }
|
72 |
|
73 | this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
|
74 |
|
75 | this._defaults = gaxGrpc.constructSettings('google.iam.v1.IAMPolicy', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
|
76 | this.innerApiCalls = {};
|
77 | }
|
78 | |
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 | initialize() {
|
90 |
|
91 | if (this.iamPolicyStub) {
|
92 | return this.iamPolicyStub;
|
93 | }
|
94 |
|
95 |
|
96 | this.iamPolicyStub = this.gaxGrpc.createStub(this._opts.fallback
|
97 | ? this._protos.lookupService('google.iam.v1.IAMPolicy')
|
98 | : this._protos.google.iam.v1.IAMPolicy, this._opts);
|
99 |
|
100 |
|
101 | const iamPolicyStubMethods = [
|
102 | 'getIamPolicy',
|
103 | 'setIamPolicy',
|
104 | 'testIamPermissions',
|
105 | ];
|
106 | for (const methodName of iamPolicyStubMethods) {
|
107 | const innerCallPromise = this.iamPolicyStub.then(stub => (...args) => {
|
108 | if (this._terminated) {
|
109 | return Promise.reject('The client has already been closed.');
|
110 | }
|
111 | const func = stub[methodName];
|
112 | return func.apply(stub, args);
|
113 | }, (err) => () => {
|
114 | throw err;
|
115 | });
|
116 | this.innerApiCalls[methodName] = createApiCall_1.createApiCall(innerCallPromise, this._defaults[methodName], this.descriptors.page[methodName]);
|
117 | }
|
118 | return this.iamPolicyStub;
|
119 | }
|
120 | |
121 |
|
122 |
|
123 | static get servicePath() {
|
124 | return 'cloudkms.googleapis.com';
|
125 | }
|
126 | |
127 |
|
128 |
|
129 |
|
130 | static get apiEndpoint() {
|
131 | return 'cloudkms.googleapis.com';
|
132 | }
|
133 | |
134 |
|
135 |
|
136 | static get port() {
|
137 | return 443;
|
138 | }
|
139 | |
140 |
|
141 |
|
142 |
|
143 | static get scopes() {
|
144 | return [
|
145 | 'https://www.googleapis.com/auth/cloud-platform',
|
146 | 'https://www.googleapis.com/auth/cloudkms',
|
147 | ];
|
148 | }
|
149 | getProjectId(callback) {
|
150 | if (this.auth && 'getProjectId' in this.auth) {
|
151 | return this.auth.getProjectId(callback);
|
152 | }
|
153 | if (callback) {
|
154 | callback(new Error('Cannot determine project ID.'));
|
155 | }
|
156 | else {
|
157 | return Promise.reject('Cannot determine project ID.');
|
158 | }
|
159 | }
|
160 | getIamPolicy(request, optionsOrCallback, callback) {
|
161 | let options;
|
162 | if (optionsOrCallback instanceof Function && callback === undefined) {
|
163 | callback = optionsOrCallback;
|
164 | options = {};
|
165 | }
|
166 | else {
|
167 | options = optionsOrCallback;
|
168 | }
|
169 | request = request || {};
|
170 | options = options || {};
|
171 | options.otherArgs = options.otherArgs || {};
|
172 | options.otherArgs.headers = options.otherArgs.headers || {};
|
173 | options.otherArgs.headers['x-goog-request-params'] =
|
174 | routingHeader.fromParams({
|
175 | resource: request.resource,
|
176 | });
|
177 | this.initialize();
|
178 | return this.innerApiCalls.getIamPolicy(request, options, callback);
|
179 | }
|
180 | setIamPolicy(request, optionsOrCallback, callback) {
|
181 | let options;
|
182 | if (optionsOrCallback instanceof Function && callback === undefined) {
|
183 | callback = optionsOrCallback;
|
184 | options = {};
|
185 | }
|
186 | else {
|
187 | options = optionsOrCallback;
|
188 | }
|
189 | request = request || {};
|
190 | options = options || {};
|
191 | options.otherArgs = options.otherArgs || {};
|
192 | options.otherArgs.headers = options.otherArgs.headers || {};
|
193 | options.otherArgs.headers['x-goog-request-params'] =
|
194 | routingHeader.fromParams({
|
195 | resource: request.resource,
|
196 | });
|
197 | this.initialize();
|
198 | return this.innerApiCalls.setIamPolicy(request, options, callback);
|
199 | }
|
200 | testIamPermissions(request, optionsOrCallback, callback) {
|
201 | let options;
|
202 | if (optionsOrCallback instanceof Function && callback === undefined) {
|
203 | callback = optionsOrCallback;
|
204 | options = {};
|
205 | }
|
206 | else {
|
207 | options = optionsOrCallback;
|
208 | }
|
209 | request = request || {};
|
210 | options = options || {};
|
211 | options.otherArgs = options.otherArgs || {};
|
212 | options.otherArgs.headers = options.otherArgs.headers || {};
|
213 | options.otherArgs.headers['x-goog-request-params'] =
|
214 | routingHeader.fromParams({
|
215 | resource: request.resource,
|
216 | });
|
217 | this.initialize();
|
218 | return this.innerApiCalls.testIamPermissions(request, options, callback);
|
219 | }
|
220 | |
221 |
|
222 |
|
223 |
|
224 |
|
225 | close() {
|
226 | this.initialize();
|
227 | if (!this._terminated) {
|
228 | return this.iamPolicyStub.then(stub => {
|
229 | this._terminated = true;
|
230 | stub.close();
|
231 | });
|
232 | }
|
233 | return Promise.resolve();
|
234 | }
|
235 | }
|
236 | exports.IamClient = IamClient;
|
237 |
|
\ | No newline at end of file |