@google-cloud/apikeys 0.1.0

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.
@@ -0,0 +1,847 @@
1
+ "use strict";
2
+ // Copyright 2022 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
+ // https://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.
15
+ //
16
+ // ** This file is automatically generated by gapic-generator-typescript. **
17
+ // ** https://github.com/googleapis/gapic-generator-typescript **
18
+ // ** All changes to this file may be overwritten. **
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.ApiKeysClient = void 0;
21
+ const jsonProtos = require("../../protos/protos.json");
22
+ /**
23
+ * Client JSON configuration object, loaded from
24
+ * `src/v2/api_keys_client_config.json`.
25
+ * This file defines retry strategy and timeouts for all API methods in this library.
26
+ */
27
+ const gapicConfig = require("./api_keys_client_config.json");
28
+ const version = require('../../../package.json').version;
29
+ /**
30
+ * Manages the API keys associated with projects.
31
+ * @class
32
+ * @memberof v2
33
+ */
34
+ class ApiKeysClient {
35
+ /**
36
+ * Construct an instance of ApiKeysClient.
37
+ *
38
+ * @param {object} [options] - The configuration object.
39
+ * The options accepted by the constructor are described in detail
40
+ * in [this document](https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#creating-the-client-instance).
41
+ * The common options are:
42
+ * @param {object} [options.credentials] - Credentials object.
43
+ * @param {string} [options.credentials.client_email]
44
+ * @param {string} [options.credentials.private_key]
45
+ * @param {string} [options.email] - Account email address. Required when
46
+ * using a .pem or .p12 keyFilename.
47
+ * @param {string} [options.keyFilename] - Full path to the a .json, .pem, or
48
+ * .p12 key downloaded from the Google Developers Console. If you provide
49
+ * a path to a JSON file, the projectId option below is not necessary.
50
+ * NOTE: .pem and .p12 require you to specify options.email as well.
51
+ * @param {number} [options.port] - The port on which to connect to
52
+ * the remote host.
53
+ * @param {string} [options.projectId] - The project ID from the Google
54
+ * Developer's Console, e.g. 'grape-spaceship-123'. We will also check
55
+ * the environment variable GCLOUD_PROJECT for your project ID. If your
56
+ * app is running in an environment which supports
57
+ * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials},
58
+ * your project ID will be detected automatically.
59
+ * @param {string} [options.apiEndpoint] - The domain name of the
60
+ * API remote host.
61
+ * @param {gax.ClientConfig} [options.clientConfig] - Client configuration override.
62
+ * Follows the structure of {@link gapicConfig}.
63
+ * @param {boolean | "rest"} [options.fallback] - Use HTTP fallback mode.
64
+ * Pass "rest" to use HTTP/1.1 REST API instead of gRPC.
65
+ * For more information, please check the
66
+ * {@link https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md#http11-rest-api-mode documentation}.
67
+ * @param {gax} [gaxInstance]: loaded instance of `google-gax`. Useful if you
68
+ * need to avoid loading the default gRPC version and want to use the fallback
69
+ * HTTP implementation. Load only fallback version and pass it to the constructor:
70
+ * ```
71
+ * const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC
72
+ * const client = new ApiKeysClient({fallback: 'rest'}, gax);
73
+ * ```
74
+ */
75
+ constructor(opts, gaxInstance) {
76
+ var _a, _b;
77
+ this._terminated = false;
78
+ this.descriptors = {
79
+ page: {},
80
+ stream: {},
81
+ longrunning: {},
82
+ batching: {},
83
+ };
84
+ // Ensure that options include all the required fields.
85
+ const staticMembers = this.constructor;
86
+ const servicePath = (opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint) || staticMembers.servicePath;
87
+ this._providedCustomServicePath = !!((opts === null || opts === void 0 ? void 0 : opts.servicePath) || (opts === null || opts === void 0 ? void 0 : opts.apiEndpoint));
88
+ const port = (opts === null || opts === void 0 ? void 0 : opts.port) || staticMembers.port;
89
+ const clientConfig = (_a = opts === null || opts === void 0 ? void 0 : opts.clientConfig) !== null && _a !== void 0 ? _a : {};
90
+ const fallback = (_b = opts === null || opts === void 0 ? void 0 : opts.fallback) !== null && _b !== void 0 ? _b : (typeof window !== 'undefined' && typeof (window === null || window === void 0 ? void 0 : window.fetch) === 'function');
91
+ opts = Object.assign({ servicePath, port, clientConfig, fallback }, opts);
92
+ // If scopes are unset in options and we're connecting to a non-default endpoint, set scopes just in case.
93
+ if (servicePath !== staticMembers.servicePath && !('scopes' in opts)) {
94
+ opts['scopes'] = staticMembers.scopes;
95
+ }
96
+ // Load google-gax module synchronously if needed
97
+ if (!gaxInstance) {
98
+ gaxInstance = require('google-gax');
99
+ }
100
+ // Choose either gRPC or proto-over-HTTP implementation of google-gax.
101
+ this._gaxModule = opts.fallback ? gaxInstance.fallback : gaxInstance;
102
+ // Create a `gaxGrpc` object, with any grpc-specific options sent to the client.
103
+ this._gaxGrpc = new this._gaxModule.GrpcClient(opts);
104
+ // Save options to use in initialize() method.
105
+ this._opts = opts;
106
+ // Save the auth object to the client, for use by other methods.
107
+ this.auth = this._gaxGrpc.auth;
108
+ // Set useJWTAccessWithScope on the auth object.
109
+ this.auth.useJWTAccessWithScope = true;
110
+ // Set defaultServicePath on the auth object.
111
+ this.auth.defaultServicePath = staticMembers.servicePath;
112
+ // Set the default scopes in auth client if needed.
113
+ if (servicePath === staticMembers.servicePath) {
114
+ this.auth.defaultScopes = staticMembers.scopes;
115
+ }
116
+ // Determine the client header string.
117
+ const clientHeader = [`gax/${this._gaxModule.version}`, `gapic/${version}`];
118
+ if (typeof process !== 'undefined' && 'versions' in process) {
119
+ clientHeader.push(`gl-node/${process.versions.node}`);
120
+ }
121
+ else {
122
+ clientHeader.push(`gl-web/${this._gaxModule.version}`);
123
+ }
124
+ if (!opts.fallback) {
125
+ clientHeader.push(`grpc/${this._gaxGrpc.grpcVersion}`);
126
+ }
127
+ else if (opts.fallback === 'rest') {
128
+ clientHeader.push(`rest/${this._gaxGrpc.grpcVersion}`);
129
+ }
130
+ if (opts.libName && opts.libVersion) {
131
+ clientHeader.push(`${opts.libName}/${opts.libVersion}`);
132
+ }
133
+ // Load the applicable protos.
134
+ this._protos = this._gaxGrpc.loadProtoJSON(jsonProtos);
135
+ // This API contains "path templates"; forward-slash-separated
136
+ // identifiers to uniquely identify resources within the API.
137
+ // Create useful helper objects for these.
138
+ this.pathTemplates = {
139
+ keyPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}/keys/{key}'),
140
+ locationPathTemplate: new this._gaxModule.PathTemplate('projects/{project}/locations/{location}'),
141
+ projectPathTemplate: new this._gaxModule.PathTemplate('projects/{project}'),
142
+ };
143
+ // Some of the methods on this service return "paged" results,
144
+ // (e.g. 50 results at a time, with tokens to get subsequent
145
+ // pages). Denote the keys used for pagination and results.
146
+ this.descriptors.page = {
147
+ listKeys: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', 'keys'),
148
+ };
149
+ const protoFilesRoot = this._gaxModule.protobuf.Root.fromJSON(jsonProtos);
150
+ // This API contains "long-running operations", which return a
151
+ // an Operation object that allows for tracking of the operation,
152
+ // rather than holding a request open.
153
+ const lroOptions = {
154
+ auth: this.auth,
155
+ grpc: 'grpc' in this._gaxGrpc ? this._gaxGrpc.grpc : undefined,
156
+ };
157
+ if (opts.fallback === 'rest') {
158
+ lroOptions.protoJson = protoFilesRoot;
159
+ lroOptions.httpRules = [
160
+ {
161
+ selector: 'google.longrunning.Operations.GetOperation',
162
+ get: '/v2/{name=operations/*}',
163
+ },
164
+ ];
165
+ }
166
+ this.operationsClient = this._gaxModule
167
+ .lro(lroOptions)
168
+ .operationsClient(opts);
169
+ const createKeyResponse = protoFilesRoot.lookup('.google.api.apikeys.v2.Key');
170
+ const createKeyMetadata = protoFilesRoot.lookup('.google.protobuf.Empty');
171
+ const updateKeyResponse = protoFilesRoot.lookup('.google.api.apikeys.v2.Key');
172
+ const updateKeyMetadata = protoFilesRoot.lookup('.google.protobuf.Empty');
173
+ const deleteKeyResponse = protoFilesRoot.lookup('.google.api.apikeys.v2.Key');
174
+ const deleteKeyMetadata = protoFilesRoot.lookup('.google.protobuf.Empty');
175
+ const undeleteKeyResponse = protoFilesRoot.lookup('.google.api.apikeys.v2.Key');
176
+ const undeleteKeyMetadata = protoFilesRoot.lookup('.google.protobuf.Empty');
177
+ this.descriptors.longrunning = {
178
+ createKey: new this._gaxModule.LongrunningDescriptor(this.operationsClient, createKeyResponse.decode.bind(createKeyResponse), createKeyMetadata.decode.bind(createKeyMetadata)),
179
+ updateKey: new this._gaxModule.LongrunningDescriptor(this.operationsClient, updateKeyResponse.decode.bind(updateKeyResponse), updateKeyMetadata.decode.bind(updateKeyMetadata)),
180
+ deleteKey: new this._gaxModule.LongrunningDescriptor(this.operationsClient, deleteKeyResponse.decode.bind(deleteKeyResponse), deleteKeyMetadata.decode.bind(deleteKeyMetadata)),
181
+ undeleteKey: new this._gaxModule.LongrunningDescriptor(this.operationsClient, undeleteKeyResponse.decode.bind(undeleteKeyResponse), undeleteKeyMetadata.decode.bind(undeleteKeyMetadata)),
182
+ };
183
+ // Put together the default options sent with requests.
184
+ this._defaults = this._gaxGrpc.constructSettings('google.api.apikeys.v2.ApiKeys', gapicConfig, opts.clientConfig || {}, { 'x-goog-api-client': clientHeader.join(' ') });
185
+ // Set up a dictionary of "inner API calls"; the core implementation
186
+ // of calling the API is handled in `google-gax`, with this code
187
+ // merely providing the destination and request information.
188
+ this.innerApiCalls = {};
189
+ // Add a warn function to the client constructor so it can be easily tested.
190
+ this.warn = this._gaxModule.warn;
191
+ }
192
+ /**
193
+ * Initialize the client.
194
+ * Performs asynchronous operations (such as authentication) and prepares the client.
195
+ * This function will be called automatically when any class method is called for the
196
+ * first time, but if you need to initialize it before calling an actual method,
197
+ * feel free to call initialize() directly.
198
+ *
199
+ * You can await on this method if you want to make sure the client is initialized.
200
+ *
201
+ * @returns {Promise} A promise that resolves to an authenticated service stub.
202
+ */
203
+ initialize() {
204
+ // If the client stub promise is already initialized, return immediately.
205
+ if (this.apiKeysStub) {
206
+ return this.apiKeysStub;
207
+ }
208
+ // Put together the "service stub" for
209
+ // google.api.apikeys.v2.ApiKeys.
210
+ this.apiKeysStub = this._gaxGrpc.createStub(this._opts.fallback
211
+ ? this._protos.lookupService('google.api.apikeys.v2.ApiKeys')
212
+ : // eslint-disable-next-line @typescript-eslint/no-explicit-any
213
+ this._protos.google.api.apikeys.v2.ApiKeys, this._opts, this._providedCustomServicePath);
214
+ // Iterate over each of the methods that the service provides
215
+ // and create an API call method for each.
216
+ const apiKeysStubMethods = [
217
+ 'createKey',
218
+ 'listKeys',
219
+ 'getKey',
220
+ 'getKeyString',
221
+ 'updateKey',
222
+ 'deleteKey',
223
+ 'undeleteKey',
224
+ 'lookupKey',
225
+ ];
226
+ for (const methodName of apiKeysStubMethods) {
227
+ const callPromise = this.apiKeysStub.then(stub => (...args) => {
228
+ if (this._terminated) {
229
+ return Promise.reject('The client has already been closed.');
230
+ }
231
+ const func = stub[methodName];
232
+ return func.apply(stub, args);
233
+ }, (err) => () => {
234
+ throw err;
235
+ });
236
+ const descriptor = this.descriptors.page[methodName] ||
237
+ this.descriptors.longrunning[methodName] ||
238
+ undefined;
239
+ const apiCall = this._gaxModule.createApiCall(callPromise, this._defaults[methodName], descriptor, this._opts.fallback);
240
+ this.innerApiCalls[methodName] = apiCall;
241
+ }
242
+ return this.apiKeysStub;
243
+ }
244
+ /**
245
+ * The DNS address for this API service.
246
+ * @returns {string} The DNS address for this service.
247
+ */
248
+ static get servicePath() {
249
+ return 'apikeys.googleapis.com';
250
+ }
251
+ /**
252
+ * The DNS address for this API service - same as servicePath(),
253
+ * exists for compatibility reasons.
254
+ * @returns {string} The DNS address for this service.
255
+ */
256
+ static get apiEndpoint() {
257
+ return 'apikeys.googleapis.com';
258
+ }
259
+ /**
260
+ * The port for this API service.
261
+ * @returns {number} The default port for this service.
262
+ */
263
+ static get port() {
264
+ return 443;
265
+ }
266
+ /**
267
+ * The scopes needed to make gRPC calls for every method defined
268
+ * in this service.
269
+ * @returns {string[]} List of default scopes.
270
+ */
271
+ static get scopes() {
272
+ return [
273
+ 'https://www.googleapis.com/auth/cloud-platform',
274
+ 'https://www.googleapis.com/auth/cloud-platform.read-only',
275
+ ];
276
+ }
277
+ /**
278
+ * Return the project ID used by this class.
279
+ * @returns {Promise} A promise that resolves to string containing the project ID.
280
+ */
281
+ getProjectId(callback) {
282
+ if (callback) {
283
+ this.auth.getProjectId(callback);
284
+ return;
285
+ }
286
+ return this.auth.getProjectId();
287
+ }
288
+ getKey(request, optionsOrCallback, callback) {
289
+ request = request || {};
290
+ let options;
291
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
292
+ callback = optionsOrCallback;
293
+ options = {};
294
+ }
295
+ else {
296
+ options = optionsOrCallback;
297
+ }
298
+ options = options || {};
299
+ options.otherArgs = options.otherArgs || {};
300
+ options.otherArgs.headers = options.otherArgs.headers || {};
301
+ options.otherArgs.headers['x-goog-request-params'] =
302
+ this._gaxModule.routingHeader.fromParams({
303
+ name: request.name || '',
304
+ });
305
+ this.initialize();
306
+ return this.innerApiCalls.getKey(request, options, callback);
307
+ }
308
+ getKeyString(request, optionsOrCallback, callback) {
309
+ request = request || {};
310
+ let options;
311
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
312
+ callback = optionsOrCallback;
313
+ options = {};
314
+ }
315
+ else {
316
+ options = optionsOrCallback;
317
+ }
318
+ options = options || {};
319
+ options.otherArgs = options.otherArgs || {};
320
+ options.otherArgs.headers = options.otherArgs.headers || {};
321
+ options.otherArgs.headers['x-goog-request-params'] =
322
+ this._gaxModule.routingHeader.fromParams({
323
+ name: request.name || '',
324
+ });
325
+ this.initialize();
326
+ return this.innerApiCalls.getKeyString(request, options, callback);
327
+ }
328
+ lookupKey(request, optionsOrCallback, callback) {
329
+ request = request || {};
330
+ let options;
331
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
332
+ callback = optionsOrCallback;
333
+ options = {};
334
+ }
335
+ else {
336
+ options = optionsOrCallback;
337
+ }
338
+ options = options || {};
339
+ options.otherArgs = options.otherArgs || {};
340
+ options.otherArgs.headers = options.otherArgs.headers || {};
341
+ this.initialize();
342
+ return this.innerApiCalls.lookupKey(request, options, callback);
343
+ }
344
+ createKey(request, optionsOrCallback, callback) {
345
+ request = request || {};
346
+ let options;
347
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
348
+ callback = optionsOrCallback;
349
+ options = {};
350
+ }
351
+ else {
352
+ options = optionsOrCallback;
353
+ }
354
+ options = options || {};
355
+ options.otherArgs = options.otherArgs || {};
356
+ options.otherArgs.headers = options.otherArgs.headers || {};
357
+ options.otherArgs.headers['x-goog-request-params'] =
358
+ this._gaxModule.routingHeader.fromParams({
359
+ parent: request.parent || '',
360
+ });
361
+ this.initialize();
362
+ return this.innerApiCalls.createKey(request, options, callback);
363
+ }
364
+ /**
365
+ * Check the status of the long running operation returned by `createKey()`.
366
+ * @param {String} name
367
+ * The operation name that will be passed.
368
+ * @returns {Promise} - The promise which resolves to an object.
369
+ * The decoded operation object has result and metadata field to get information from.
370
+ * Please see the
371
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
372
+ * for more details and examples.
373
+ * @example <caption>include:samples/generated/v2/api_keys.create_key.js</caption>
374
+ * region_tag:apikeys_v2_generated_ApiKeys_CreateKey_async
375
+ */
376
+ async checkCreateKeyProgress(name) {
377
+ const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({ name });
378
+ const [operation] = await this.operationsClient.getOperation(request);
379
+ const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.createKey, this._gaxModule.createDefaultBackoffSettings());
380
+ return decodeOperation;
381
+ }
382
+ updateKey(request, optionsOrCallback, callback) {
383
+ request = request || {};
384
+ let options;
385
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
386
+ callback = optionsOrCallback;
387
+ options = {};
388
+ }
389
+ else {
390
+ options = optionsOrCallback;
391
+ }
392
+ options = options || {};
393
+ options.otherArgs = options.otherArgs || {};
394
+ options.otherArgs.headers = options.otherArgs.headers || {};
395
+ options.otherArgs.headers['x-goog-request-params'] =
396
+ this._gaxModule.routingHeader.fromParams({
397
+ 'key.name': request.key.name || '',
398
+ });
399
+ this.initialize();
400
+ return this.innerApiCalls.updateKey(request, options, callback);
401
+ }
402
+ /**
403
+ * Check the status of the long running operation returned by `updateKey()`.
404
+ * @param {String} name
405
+ * The operation name that will be passed.
406
+ * @returns {Promise} - The promise which resolves to an object.
407
+ * The decoded operation object has result and metadata field to get information from.
408
+ * Please see the
409
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
410
+ * for more details and examples.
411
+ * @example <caption>include:samples/generated/v2/api_keys.update_key.js</caption>
412
+ * region_tag:apikeys_v2_generated_ApiKeys_UpdateKey_async
413
+ */
414
+ async checkUpdateKeyProgress(name) {
415
+ const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({ name });
416
+ const [operation] = await this.operationsClient.getOperation(request);
417
+ const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.updateKey, this._gaxModule.createDefaultBackoffSettings());
418
+ return decodeOperation;
419
+ }
420
+ deleteKey(request, optionsOrCallback, callback) {
421
+ request = request || {};
422
+ let options;
423
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
424
+ callback = optionsOrCallback;
425
+ options = {};
426
+ }
427
+ else {
428
+ options = optionsOrCallback;
429
+ }
430
+ options = options || {};
431
+ options.otherArgs = options.otherArgs || {};
432
+ options.otherArgs.headers = options.otherArgs.headers || {};
433
+ options.otherArgs.headers['x-goog-request-params'] =
434
+ this._gaxModule.routingHeader.fromParams({
435
+ name: request.name || '',
436
+ });
437
+ this.initialize();
438
+ return this.innerApiCalls.deleteKey(request, options, callback);
439
+ }
440
+ /**
441
+ * Check the status of the long running operation returned by `deleteKey()`.
442
+ * @param {String} name
443
+ * The operation name that will be passed.
444
+ * @returns {Promise} - The promise which resolves to an object.
445
+ * The decoded operation object has result and metadata field to get information from.
446
+ * Please see the
447
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
448
+ * for more details and examples.
449
+ * @example <caption>include:samples/generated/v2/api_keys.delete_key.js</caption>
450
+ * region_tag:apikeys_v2_generated_ApiKeys_DeleteKey_async
451
+ */
452
+ async checkDeleteKeyProgress(name) {
453
+ const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({ name });
454
+ const [operation] = await this.operationsClient.getOperation(request);
455
+ const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.deleteKey, this._gaxModule.createDefaultBackoffSettings());
456
+ return decodeOperation;
457
+ }
458
+ undeleteKey(request, optionsOrCallback, callback) {
459
+ request = request || {};
460
+ let options;
461
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
462
+ callback = optionsOrCallback;
463
+ options = {};
464
+ }
465
+ else {
466
+ options = optionsOrCallback;
467
+ }
468
+ options = options || {};
469
+ options.otherArgs = options.otherArgs || {};
470
+ options.otherArgs.headers = options.otherArgs.headers || {};
471
+ options.otherArgs.headers['x-goog-request-params'] =
472
+ this._gaxModule.routingHeader.fromParams({
473
+ name: request.name || '',
474
+ });
475
+ this.initialize();
476
+ return this.innerApiCalls.undeleteKey(request, options, callback);
477
+ }
478
+ /**
479
+ * Check the status of the long running operation returned by `undeleteKey()`.
480
+ * @param {String} name
481
+ * The operation name that will be passed.
482
+ * @returns {Promise} - The promise which resolves to an object.
483
+ * The decoded operation object has result and metadata field to get information from.
484
+ * Please see the
485
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#long-running-operations)
486
+ * for more details and examples.
487
+ * @example <caption>include:samples/generated/v2/api_keys.undelete_key.js</caption>
488
+ * region_tag:apikeys_v2_generated_ApiKeys_UndeleteKey_async
489
+ */
490
+ async checkUndeleteKeyProgress(name) {
491
+ const request = new this._gaxModule.operationsProtos.google.longrunning.GetOperationRequest({ name });
492
+ const [operation] = await this.operationsClient.getOperation(request);
493
+ const decodeOperation = new this._gaxModule.Operation(operation, this.descriptors.longrunning.undeleteKey, this._gaxModule.createDefaultBackoffSettings());
494
+ return decodeOperation;
495
+ }
496
+ listKeys(request, optionsOrCallback, callback) {
497
+ request = request || {};
498
+ let options;
499
+ if (typeof optionsOrCallback === 'function' && callback === undefined) {
500
+ callback = optionsOrCallback;
501
+ options = {};
502
+ }
503
+ else {
504
+ options = optionsOrCallback;
505
+ }
506
+ options = options || {};
507
+ options.otherArgs = options.otherArgs || {};
508
+ options.otherArgs.headers = options.otherArgs.headers || {};
509
+ options.otherArgs.headers['x-goog-request-params'] =
510
+ this._gaxModule.routingHeader.fromParams({
511
+ parent: request.parent || '',
512
+ });
513
+ this.initialize();
514
+ return this.innerApiCalls.listKeys(request, options, callback);
515
+ }
516
+ /**
517
+ * Equivalent to `method.name.toCamelCase()`, but returns a NodeJS Stream object.
518
+ * @param {Object} request
519
+ * The request object that will be sent.
520
+ * @param {string} request.parent
521
+ * Required. Lists all API keys associated with this project.
522
+ * @param {number} [request.pageSize]
523
+ * Optional. Specifies the maximum number of results to be returned at a time.
524
+ * @param {string} [request.pageToken]
525
+ * Optional. Requests a specific page of results.
526
+ * @param {boolean} [request.showDeleted]
527
+ * Optional. Indicate that keys deleted in the past 30 days should also be
528
+ * returned.
529
+ * @param {object} [options]
530
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
531
+ * @returns {Stream}
532
+ * An object stream which emits an object representing [Key]{@link google.api.apikeys.v2.Key} on 'data' event.
533
+ * The client library will perform auto-pagination by default: it will call the API as many
534
+ * times as needed. Note that it can affect your quota.
535
+ * We recommend using `listKeysAsync()`
536
+ * method described below for async iteration which you can stop as needed.
537
+ * Please see the
538
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
539
+ * for more details and examples.
540
+ */
541
+ listKeysStream(request, options) {
542
+ request = request || {};
543
+ options = options || {};
544
+ options.otherArgs = options.otherArgs || {};
545
+ options.otherArgs.headers = options.otherArgs.headers || {};
546
+ options.otherArgs.headers['x-goog-request-params'] =
547
+ this._gaxModule.routingHeader.fromParams({
548
+ parent: request.parent || '',
549
+ });
550
+ const defaultCallSettings = this._defaults['listKeys'];
551
+ const callSettings = defaultCallSettings.merge(options);
552
+ this.initialize();
553
+ return this.descriptors.page.listKeys.createStream(this.innerApiCalls.listKeys, request, callSettings);
554
+ }
555
+ /**
556
+ * Equivalent to `listKeys`, but returns an iterable object.
557
+ *
558
+ * `for`-`await`-`of` syntax is used with the iterable to get response elements on-demand.
559
+ * @param {Object} request
560
+ * The request object that will be sent.
561
+ * @param {string} request.parent
562
+ * Required. Lists all API keys associated with this project.
563
+ * @param {number} [request.pageSize]
564
+ * Optional. Specifies the maximum number of results to be returned at a time.
565
+ * @param {string} [request.pageToken]
566
+ * Optional. Requests a specific page of results.
567
+ * @param {boolean} [request.showDeleted]
568
+ * Optional. Indicate that keys deleted in the past 30 days should also be
569
+ * returned.
570
+ * @param {object} [options]
571
+ * Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
572
+ * @returns {Object}
573
+ * An iterable Object that allows [async iteration](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols).
574
+ * When you iterate the returned iterable, each element will be an object representing
575
+ * [Key]{@link google.api.apikeys.v2.Key}. The API will be called under the hood as needed, once per the page,
576
+ * so you can stop the iteration when you don't need more results.
577
+ * Please see the
578
+ * [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#auto-pagination)
579
+ * for more details and examples.
580
+ * @example <caption>include:samples/generated/v2/api_keys.list_keys.js</caption>
581
+ * region_tag:apikeys_v2_generated_ApiKeys_ListKeys_async
582
+ */
583
+ listKeysAsync(request, options) {
584
+ request = request || {};
585
+ options = options || {};
586
+ options.otherArgs = options.otherArgs || {};
587
+ options.otherArgs.headers = options.otherArgs.headers || {};
588
+ options.otherArgs.headers['x-goog-request-params'] =
589
+ this._gaxModule.routingHeader.fromParams({
590
+ parent: request.parent || '',
591
+ });
592
+ const defaultCallSettings = this._defaults['listKeys'];
593
+ const callSettings = defaultCallSettings.merge(options);
594
+ this.initialize();
595
+ return this.descriptors.page.listKeys.asyncIterate(this.innerApiCalls['listKeys'], request, callSettings);
596
+ }
597
+ /**
598
+ * Gets the latest state of a long-running operation. Clients can use this
599
+ * method to poll the operation result at intervals as recommended by the API
600
+ * service.
601
+ *
602
+ * @param {Object} request - The request object that will be sent.
603
+ * @param {string} request.name - The name of the operation resource.
604
+ * @param {Object=} options
605
+ * Optional parameters. You can override the default settings for this call,
606
+ * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
607
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
608
+ * details.
609
+ * @param {function(?Error, ?Object)=} callback
610
+ * The function which will be called with the result of the API call.
611
+ *
612
+ * The second parameter to the callback is an object representing
613
+ * [google.longrunning.Operation]{@link
614
+ * external:"google.longrunning.Operation"}.
615
+ * @return {Promise} - The promise which resolves to an array.
616
+ * The first element of the array is an object representing
617
+ * [google.longrunning.Operation]{@link
618
+ * external:"google.longrunning.Operation"}. The promise has a method named
619
+ * "cancel" which cancels the ongoing API call.
620
+ *
621
+ * @example
622
+ * ```
623
+ * const client = longrunning.operationsClient();
624
+ * const name = '';
625
+ * const [response] = await client.getOperation({name});
626
+ * // doThingsWith(response)
627
+ * ```
628
+ */
629
+ getOperation(request, options, callback) {
630
+ return this.operationsClient.getOperation(request, options, callback);
631
+ }
632
+ /**
633
+ * Lists operations that match the specified filter in the request. If the
634
+ * server doesn't support this method, it returns `UNIMPLEMENTED`. Returns an iterable object.
635
+ *
636
+ * For-await-of syntax is used with the iterable to recursively get response element on-demand.
637
+ *
638
+ * @param {Object} request - The request object that will be sent.
639
+ * @param {string} request.name - The name of the operation collection.
640
+ * @param {string} request.filter - The standard list filter.
641
+ * @param {number=} request.pageSize -
642
+ * The maximum number of resources contained in the underlying API
643
+ * response. If page streaming is performed per-resource, this
644
+ * parameter does not affect the return value. If page streaming is
645
+ * performed per-page, this determines the maximum number of
646
+ * resources in a page.
647
+ * @param {Object=} options
648
+ * Optional parameters. You can override the default settings for this call,
649
+ * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
650
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
651
+ * details.
652
+ * @returns {Object}
653
+ * An iterable Object that conforms to @link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols.
654
+ *
655
+ * @example
656
+ * ```
657
+ * const client = longrunning.operationsClient();
658
+ * for await (const response of client.listOperationsAsync(request));
659
+ * // doThingsWith(response)
660
+ * ```
661
+ */
662
+ listOperationsAsync(request, options) {
663
+ return this.operationsClient.listOperationsAsync(request, options);
664
+ }
665
+ /**
666
+ * Starts asynchronous cancellation on a long-running operation. The server
667
+ * makes a best effort to cancel the operation, but success is not
668
+ * guaranteed. If the server doesn't support this method, it returns
669
+ * `google.rpc.Code.UNIMPLEMENTED`. Clients can use
670
+ * {@link Operations.GetOperation} or
671
+ * other methods to check whether the cancellation succeeded or whether the
672
+ * operation completed despite cancellation. On successful cancellation,
673
+ * the operation is not deleted; instead, it becomes an operation with
674
+ * an {@link Operation.error} value with a {@link google.rpc.Status.code} of
675
+ * 1, corresponding to `Code.CANCELLED`.
676
+ *
677
+ * @param {Object} request - The request object that will be sent.
678
+ * @param {string} request.name - The name of the operation resource to be cancelled.
679
+ * @param {Object=} options
680
+ * Optional parameters. You can override the default settings for this call,
681
+ * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
682
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
683
+ * details.
684
+ * @param {function(?Error)=} callback
685
+ * The function which will be called with the result of the API call.
686
+ * @return {Promise} - The promise which resolves when API call finishes.
687
+ * The promise has a method named "cancel" which cancels the ongoing API
688
+ * call.
689
+ *
690
+ * @example
691
+ * ```
692
+ * const client = longrunning.operationsClient();
693
+ * await client.cancelOperation({name: ''});
694
+ * ```
695
+ */
696
+ cancelOperation(request, options, callback) {
697
+ return this.operationsClient.cancelOperation(request, options, callback);
698
+ }
699
+ /**
700
+ * Deletes a long-running operation. This method indicates that the client is
701
+ * no longer interested in the operation result. It does not cancel the
702
+ * operation. If the server doesn't support this method, it returns
703
+ * `google.rpc.Code.UNIMPLEMENTED`.
704
+ *
705
+ * @param {Object} request - The request object that will be sent.
706
+ * @param {string} request.name - The name of the operation resource to be deleted.
707
+ * @param {Object=} options
708
+ * Optional parameters. You can override the default settings for this call,
709
+ * e.g, timeout, retries, paginations, etc. See [gax.CallOptions]{@link
710
+ * https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the
711
+ * details.
712
+ * @param {function(?Error)=} callback
713
+ * The function which will be called with the result of the API call.
714
+ * @return {Promise} - The promise which resolves when API call finishes.
715
+ * The promise has a method named "cancel" which cancels the ongoing API
716
+ * call.
717
+ *
718
+ * @example
719
+ * ```
720
+ * const client = longrunning.operationsClient();
721
+ * await client.deleteOperation({name: ''});
722
+ * ```
723
+ */
724
+ deleteOperation(request, options, callback) {
725
+ return this.operationsClient.deleteOperation(request, options, callback);
726
+ }
727
+ // --------------------
728
+ // -- Path templates --
729
+ // --------------------
730
+ /**
731
+ * Return a fully-qualified key resource name string.
732
+ *
733
+ * @param {string} project
734
+ * @param {string} location
735
+ * @param {string} key
736
+ * @returns {string} Resource name string.
737
+ */
738
+ keyPath(project, location, key) {
739
+ return this.pathTemplates.keyPathTemplate.render({
740
+ project: project,
741
+ location: location,
742
+ key: key,
743
+ });
744
+ }
745
+ /**
746
+ * Parse the project from Key resource.
747
+ *
748
+ * @param {string} keyName
749
+ * A fully-qualified path representing Key resource.
750
+ * @returns {string} A string representing the project.
751
+ */
752
+ matchProjectFromKeyName(keyName) {
753
+ return this.pathTemplates.keyPathTemplate.match(keyName).project;
754
+ }
755
+ /**
756
+ * Parse the location from Key resource.
757
+ *
758
+ * @param {string} keyName
759
+ * A fully-qualified path representing Key resource.
760
+ * @returns {string} A string representing the location.
761
+ */
762
+ matchLocationFromKeyName(keyName) {
763
+ return this.pathTemplates.keyPathTemplate.match(keyName).location;
764
+ }
765
+ /**
766
+ * Parse the key from Key resource.
767
+ *
768
+ * @param {string} keyName
769
+ * A fully-qualified path representing Key resource.
770
+ * @returns {string} A string representing the key.
771
+ */
772
+ matchKeyFromKeyName(keyName) {
773
+ return this.pathTemplates.keyPathTemplate.match(keyName).key;
774
+ }
775
+ /**
776
+ * Return a fully-qualified location resource name string.
777
+ *
778
+ * @param {string} project
779
+ * @param {string} location
780
+ * @returns {string} Resource name string.
781
+ */
782
+ locationPath(project, location) {
783
+ return this.pathTemplates.locationPathTemplate.render({
784
+ project: project,
785
+ location: location,
786
+ });
787
+ }
788
+ /**
789
+ * Parse the project from Location resource.
790
+ *
791
+ * @param {string} locationName
792
+ * A fully-qualified path representing Location resource.
793
+ * @returns {string} A string representing the project.
794
+ */
795
+ matchProjectFromLocationName(locationName) {
796
+ return this.pathTemplates.locationPathTemplate.match(locationName).project;
797
+ }
798
+ /**
799
+ * Parse the location from Location resource.
800
+ *
801
+ * @param {string} locationName
802
+ * A fully-qualified path representing Location resource.
803
+ * @returns {string} A string representing the location.
804
+ */
805
+ matchLocationFromLocationName(locationName) {
806
+ return this.pathTemplates.locationPathTemplate.match(locationName).location;
807
+ }
808
+ /**
809
+ * Return a fully-qualified project resource name string.
810
+ *
811
+ * @param {string} project
812
+ * @returns {string} Resource name string.
813
+ */
814
+ projectPath(project) {
815
+ return this.pathTemplates.projectPathTemplate.render({
816
+ project: project,
817
+ });
818
+ }
819
+ /**
820
+ * Parse the project from Project resource.
821
+ *
822
+ * @param {string} projectName
823
+ * A fully-qualified path representing Project resource.
824
+ * @returns {string} A string representing the project.
825
+ */
826
+ matchProjectFromProjectName(projectName) {
827
+ return this.pathTemplates.projectPathTemplate.match(projectName).project;
828
+ }
829
+ /**
830
+ * Terminate the gRPC channel and close the client.
831
+ *
832
+ * The client will no longer be usable and all future behavior is undefined.
833
+ * @returns {Promise} A promise that resolves when the client is closed.
834
+ */
835
+ close() {
836
+ if (this.apiKeysStub && !this._terminated) {
837
+ return this.apiKeysStub.then(stub => {
838
+ this._terminated = true;
839
+ stub.close();
840
+ this.operationsClient.close();
841
+ });
842
+ }
843
+ return Promise.resolve();
844
+ }
845
+ }
846
+ exports.ApiKeysClient = ApiKeysClient;
847
+ //# sourceMappingURL=api_keys_client.js.map