Class v2.ApiKeysClient (1.2.0)

Manages the API keys associated with projects. v2

Package

@google-cloud/apikeys

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of ApiKeysClient.

Parameters
NameDescription
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new ApiKeysClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

apiKeysStub

apiKeysStub?: Promise<{
        [name: string]: Function;
    }>;

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

operationsClient

operationsClient: gax.OperationsClient;

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

cancelOperation(request, options, callback)

cancelOperation(request: protos.google.longrunning.CancelOperationRequest, options?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.CancelOperationRequest, {} | undefined | null>, callback?: Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>): Promise<protos.google.protobuf.Empty>;

Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED. Clients can use or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an value with a of 1, corresponding to Code.CANCELLED.

Parameters
NameDescription
request CancelOperationRequest

The request object that will be sent.

options CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.CancelOperationRequest, {} | undefined | null>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback Callback<protos.google.longrunning.CancelOperationRequest, protos.google.protobuf.Empty, {} | undefined | null>

The function which will be called with the result of the API call. {Promise} - The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Returns
TypeDescription
Promise<protos.google.protobuf.Empty>
Example

const client = longrunning.operationsClient();
await client.cancelOperation({name: ''});

checkCreateKeyProgress(name)

checkCreateKeyProgress(name: string): Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>;

Check the status of the long running operation returned by createKey().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project in which the API key is created.
   */
  // const parent = 'abc123'
  /**
   *  Required. The API key fields to set at creation time.
   *  You can configure only the `display_name`, `restrictions`, and
   *  `annotations` fields.
   */
  // const key = {}
  /**
   *  User specified key id (optional). If specified, it will become the final
   *  component of the key resource name.
   *  The id must be unique within the project, must conform with RFC-1034,
   *  is restricted to lower-cased letters, and has a maximum length of 63
   *  characters. In another word, the id must match the regular
   *  expression: `[a-z]([a-z0-9-]{0,61}[a-z0-9])?`.
   *  The id must NOT be a UUID-like string.
   */
  // const keyId = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callCreateKey() {
    // Construct request
    const request = {
      parent,
      key,
    };

    // Run request
    const [operation] = await apikeysClient.createKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callCreateKey();

checkDeleteKeyProgress(name)

checkDeleteKeyProgress(name: string): Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>;

Check the status of the long running operation returned by deleteKey().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to be deleted.
   */
  // const name = 'abc123'
  /**
   *  Optional. The etag known to the client for the expected state of the key.
   *  This is to be used for optimistic concurrency.
   */
  // const etag = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callDeleteKey() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await apikeysClient.deleteKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callDeleteKey();

checkUndeleteKeyProgress(name)

checkUndeleteKeyProgress(name: string): Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>;

Check the status of the long running operation returned by undeleteKey().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to be undeleted.
   */
  // const name = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callUndeleteKey() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await apikeysClient.undeleteKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callUndeleteKey();

checkUpdateKeyProgress(name)

checkUpdateKeyProgress(name: string): Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>;

Check the status of the long running operation returned by updateKey().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.api.apikeys.v2.Key, protos.google.protobuf.Empty>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Set the `name` field to the resource name of the API key to be
   *  updated. You can update only the `display_name`, `restrictions`, and
   *  `annotations` fields.
   */
  // const key = {}
  /**
   *  The field mask specifies which fields to be updated as part of this
   *  request. All other fields are ignored.
   *  Mutable fields are: `display_name`, `restrictions`, and `annotations`.
   *  If an update mask is not provided, the service treats it as an implied mask
   *  equivalent to all allowed fields that are set on the wire. If the field
   *  mask has a special value "*", the service treats it equivalent to replace
   *  all allowed mutable fields.
   */
  // const updateMask = {}

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callUpdateKey() {
    // Construct request
    const request = {
      key,
    };

    // Run request
    const [operation] = await apikeysClient.updateKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callUpdateKey();

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
TypeDescription
Promise<void>

{Promise} A promise that resolves when the client is closed.

createKey(request, options)

createKey(request?: protos.google.api.apikeys.v2.ICreateKeyRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Creates a new API key.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request ICreateKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project in which the API key is created.
   */
  // const parent = 'abc123'
  /**
   *  Required. The API key fields to set at creation time.
   *  You can configure only the `display_name`, `restrictions`, and
   *  `annotations` fields.
   */
  // const key = {}
  /**
   *  User specified key id (optional). If specified, it will become the final
   *  component of the key resource name.
   *  The id must be unique within the project, must conform with RFC-1034,
   *  is restricted to lower-cased letters, and has a maximum length of 63
   *  characters. In another word, the id must match the regular
   *  expression: `[a-z]([a-z0-9-]{0,61}[a-z0-9])?`.
   *  The id must NOT be a UUID-like string.
   */
  // const keyId = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callCreateKey() {
    // Construct request
    const request = {
      parent,
      key,
    };

    // Run request
    const [operation] = await apikeysClient.createKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callCreateKey();

createKey(request, options, callback)

createKey(request: protos.google.api.apikeys.v2.ICreateKeyRequest, options: CallOptions, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ICreateKeyRequest
options CallOptions
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

createKey(request, callback)

createKey(request: protos.google.api.apikeys.v2.ICreateKeyRequest, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ICreateKeyRequest
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

deleteKey(request, options)

deleteKey(request?: protos.google.api.apikeys.v2.IDeleteKeyRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Deletes an API key. Deleted key can be retrieved within 30 days of deletion. Afterward, key will be purged from the project.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IDeleteKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to be deleted.
   */
  // const name = 'abc123'
  /**
   *  Optional. The etag known to the client for the expected state of the key.
   *  This is to be used for optimistic concurrency.
   */
  // const etag = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callDeleteKey() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await apikeysClient.deleteKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callDeleteKey();

deleteKey(request, options, callback)

deleteKey(request: protos.google.api.apikeys.v2.IDeleteKeyRequest, options: CallOptions, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IDeleteKeyRequest
options CallOptions
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

deleteKey(request, callback)

deleteKey(request: protos.google.api.apikeys.v2.IDeleteKeyRequest, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IDeleteKeyRequest
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

deleteOperation(request, options, callback)

deleteOperation(request: protos.google.longrunning.DeleteOperationRequest, options?: gax.CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>): Promise<protos.google.protobuf.Empty>;

Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED.

Parameters
NameDescription
request DeleteOperationRequest

The request object that will be sent.

options CallOptions | Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback Callback<protos.google.protobuf.Empty, protos.google.longrunning.DeleteOperationRequest, {} | null | undefined>

The function which will be called with the result of the API call. {Promise} - The promise which resolves when API call finishes. The promise has a method named "cancel" which cancels the ongoing API call.

Returns
TypeDescription
Promise<protos.google.protobuf.Empty>
Example

const client = longrunning.operationsClient();
await client.deleteOperation({name: ''});

getKey(request, options)

getKey(request?: protos.google.api.apikeys.v2.IGetKeyRequest, options?: CallOptions): Promise<[
        protos.google.api.apikeys.v2.IKey,
        protos.google.api.apikeys.v2.IGetKeyRequest | undefined,
        {} | undefined
    ]>;

Gets the metadata for an API key. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IGetKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.api.apikeys.v2.IKey, protos.google.api.apikeys.v2.IGetKeyRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing Key. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to get.
   */
  // const name = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callGetKey() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await apikeysClient.getKey(request);
    console.log(response);
  }

  callGetKey();

getKey(request, options, callback)

getKey(request: protos.google.api.apikeys.v2.IGetKeyRequest, options: CallOptions, callback: Callback<protos.google.api.apikeys.v2.IKey, protos.google.api.apikeys.v2.IGetKeyRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetKeyRequest
options CallOptions
callback Callback<protos.google.api.apikeys.v2.IKey, protos.google.api.apikeys.v2.IGetKeyRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getKey(request, callback)

getKey(request: protos.google.api.apikeys.v2.IGetKeyRequest, callback: Callback<protos.google.api.apikeys.v2.IKey, protos.google.api.apikeys.v2.IGetKeyRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetKeyRequest
callback Callback<protos.google.api.apikeys.v2.IKey, protos.google.api.apikeys.v2.IGetKeyRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getKeyString(request, options)

getKeyString(request?: protos.google.api.apikeys.v2.IGetKeyStringRequest, options?: CallOptions): Promise<[
        protos.google.api.apikeys.v2.IGetKeyStringResponse,
        protos.google.api.apikeys.v2.IGetKeyStringRequest | undefined,
        {} | undefined
    ]>;

Get the key string for an API key.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IGetKeyStringRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.api.apikeys.v2.IGetKeyStringResponse, protos.google.api.apikeys.v2.IGetKeyStringRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing GetKeyStringResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to be retrieved.
   */
  // const name = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callGetKeyString() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await apikeysClient.getKeyString(request);
    console.log(response);
  }

  callGetKeyString();

getKeyString(request, options, callback)

getKeyString(request: protos.google.api.apikeys.v2.IGetKeyStringRequest, options: CallOptions, callback: Callback<protos.google.api.apikeys.v2.IGetKeyStringResponse, protos.google.api.apikeys.v2.IGetKeyStringRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetKeyStringRequest
options CallOptions
callback Callback<protos.google.api.apikeys.v2.IGetKeyStringResponse, protos.google.api.apikeys.v2.IGetKeyStringRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getKeyString(request, callback)

getKeyString(request: protos.google.api.apikeys.v2.IGetKeyStringRequest, callback: Callback<protos.google.api.apikeys.v2.IGetKeyStringResponse, protos.google.api.apikeys.v2.IGetKeyStringRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IGetKeyStringRequest
callback Callback<protos.google.api.apikeys.v2.IGetKeyStringResponse, protos.google.api.apikeys.v2.IGetKeyStringRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

getOperation(request, options, callback)

getOperation(request: protos.google.longrunning.GetOperationRequest, options?: gax.CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>, callback?: Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>): Promise<[protos.google.longrunning.Operation]>;

Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.

Parameters
NameDescription
request GetOperationRequest

The request object that will be sent.

options CallOptions | Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

callback Callback<protos.google.longrunning.Operation, protos.google.longrunning.GetOperationRequest, {} | null | undefined>

The function which will be called with the result of the API call.

The second parameter to the callback is an object representing . {Promise} - The promise which resolves to an array. The first element of the array is an object representing . The promise has a method named "cancel" which cancels the ongoing API call.

Returns
TypeDescription
Promise<[protos.google.longrunning.Operation]>
Example

const client = longrunning.operationsClient();
const name = '';
const [response] = await client.getOperation({name});
// doThingsWith(response)

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
TypeDescription
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

keyPath(project, location, key)

keyPath(project: string, location: string, key: string): string;

Return a fully-qualified key resource name string.

Parameters
NameDescription
project string
location string
key string
Returns
TypeDescription
string

{string} Resource name string.

listKeys(request, options)

listKeys(request?: protos.google.api.apikeys.v2.IListKeysRequest, options?: CallOptions): Promise<[
        protos.google.api.apikeys.v2.IKey[],
        protos.google.api.apikeys.v2.IListKeysRequest | null,
        protos.google.api.apikeys.v2.IListKeysResponse
    ]>;

Lists the API keys owned by a project. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IListKeysRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.api.apikeys.v2.IKey[], protos.google.api.apikeys.v2.IListKeysRequest | null, protos.google.api.apikeys.v2.IListKeysResponse ]>

{Promise} - The promise which resolves to an array. The first element of the array is Array of Key. The client library will perform auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array. Note that it can affect your quota. We recommend using listKeysAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

listKeys(request, options, callback)

listKeys(request: protos.google.api.apikeys.v2.IListKeysRequest, options: CallOptions, callback: PaginationCallback<protos.google.api.apikeys.v2.IListKeysRequest, protos.google.api.apikeys.v2.IListKeysResponse | null | undefined, protos.google.api.apikeys.v2.IKey>): void;
Parameters
NameDescription
request IListKeysRequest
options CallOptions
callback PaginationCallback<protos.google.api.apikeys.v2.IListKeysRequest, protos.google.api.apikeys.v2.IListKeysResponse | null | undefined, protos.google.api.apikeys.v2.IKey>
Returns
TypeDescription
void

listKeys(request, callback)

listKeys(request: protos.google.api.apikeys.v2.IListKeysRequest, callback: PaginationCallback<protos.google.api.apikeys.v2.IListKeysRequest, protos.google.api.apikeys.v2.IListKeysResponse | null | undefined, protos.google.api.apikeys.v2.IKey>): void;
Parameters
NameDescription
request IListKeysRequest
callback PaginationCallback<protos.google.api.apikeys.v2.IListKeysRequest, protos.google.api.apikeys.v2.IListKeysResponse | null | undefined, protos.google.api.apikeys.v2.IKey>
Returns
TypeDescription
void

listKeysAsync(request, options)

listKeysAsync(request?: protos.google.api.apikeys.v2.IListKeysRequest, options?: CallOptions): AsyncIterable<protos.google.api.apikeys.v2.IKey>;

Equivalent to listKeys, but returns an iterable object.

for-await-of syntax is used with the iterable to get response elements on-demand.

Parameters
NameDescription
request IListKeysRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
AsyncIterable<protos.google.api.apikeys.v2.IKey>

{Object} An iterable Object that allows async iteration. When you iterate the returned iterable, each element will be an object representing Key. The API will be called under the hood as needed, once per the page, so you can stop the iteration when you don't need more results. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Lists all API keys associated with this project.
   */
  // const parent = 'abc123'
  /**
   *  Optional. Specifies the maximum number of results to be returned at a time.
   */
  // const pageSize = 1234
  /**
   *  Optional. Requests a specific page of results.
   */
  // const pageToken = 'abc123'
  /**
   *  Optional. Indicate that keys deleted in the past 30 days should also be
   *  returned.
   */
  // const showDeleted = true

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callListKeys() {
    // Construct request
    const request = {
      parent,
    };

    // Run request
    const iterable = apikeysClient.listKeysAsync(request);
    for await (const response of iterable) {
        console.log(response);
    }
  }

  callListKeys();

listKeysStream(request, options)

listKeysStream(request?: protos.google.api.apikeys.v2.IListKeysRequest, options?: CallOptions): Transform;

Equivalent to method.name.toCamelCase(), but returns a NodeJS Stream object.

Parameters
NameDescription
request IListKeysRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Transform

{Stream} An object stream which emits an object representing Key on 'data' event. The client library will perform auto-pagination by default: it will call the API as many times as needed. Note that it can affect your quota. We recommend using listKeysAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

listOperationsAsync(request, options)

listOperationsAsync(request: protos.google.longrunning.ListOperationsRequest, options?: gax.CallOptions): AsyncIterable<protos.google.longrunning.ListOperationsResponse>;

Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns UNIMPLEMENTED. Returns an iterable object.

For-await-of syntax is used with the iterable to recursively get response element on-demand.

Parameters
NameDescription
request ListOperationsRequest

The request object that will be sent.

options CallOptions

Optional parameters. You can override the default settings for this call, e.g, timeout, retries, paginations, etc. See gax.CallOptions for the details.

Returns
TypeDescription
AsyncIterable<protos.google.longrunning.ListOperationsResponse>

{Object} An iterable Object that conforms to iteration protocols.

Example

const client = longrunning.operationsClient();
for await (const response of client.listOperationsAsync(request));
// doThingsWith(response)

locationPath(project, location)

locationPath(project: string, location: string): string;

Return a fully-qualified location resource name string.

Parameters
NameDescription
project string
location string
Returns
TypeDescription
string

{string} Resource name string.

lookupKey(request, options)

lookupKey(request?: protos.google.api.apikeys.v2.ILookupKeyRequest, options?: CallOptions): Promise<[
        protos.google.api.apikeys.v2.ILookupKeyResponse,
        protos.google.api.apikeys.v2.ILookupKeyRequest | undefined,
        {} | undefined
    ]>;

Find the parent project and resource name of the API key that matches the key string in the request. If the API key has been purged, resource name will not be set. The service account must have the apikeys.keys.lookup permission on the parent project.

Parameters
NameDescription
request ILookupKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.api.apikeys.v2.ILookupKeyResponse, protos.google.api.apikeys.v2.ILookupKeyRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing LookupKeyResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Finds the project that owns the key string value.
   */
  // const keyString = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callLookupKey() {
    // Construct request
    const request = {
      keyString,
    };

    // Run request
    const response = await apikeysClient.lookupKey(request);
    console.log(response);
  }

  callLookupKey();

lookupKey(request, options, callback)

lookupKey(request: protos.google.api.apikeys.v2.ILookupKeyRequest, options: CallOptions, callback: Callback<protos.google.api.apikeys.v2.ILookupKeyResponse, protos.google.api.apikeys.v2.ILookupKeyRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ILookupKeyRequest
options CallOptions
callback Callback<protos.google.api.apikeys.v2.ILookupKeyResponse, protos.google.api.apikeys.v2.ILookupKeyRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

lookupKey(request, callback)

lookupKey(request: protos.google.api.apikeys.v2.ILookupKeyRequest, callback: Callback<protos.google.api.apikeys.v2.ILookupKeyResponse, protos.google.api.apikeys.v2.ILookupKeyRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request ILookupKeyRequest
callback Callback<protos.google.api.apikeys.v2.ILookupKeyResponse, protos.google.api.apikeys.v2.ILookupKeyRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

matchKeyFromKeyName(keyName)

matchKeyFromKeyName(keyName: string): string | number;

Parse the key from Key resource.

Parameter
NameDescription
keyName string

A fully-qualified path representing Key resource.

Returns
TypeDescription
string | number

{string} A string representing the key.

matchLocationFromKeyName(keyName)

matchLocationFromKeyName(keyName: string): string | number;

Parse the location from Key resource.

Parameter
NameDescription
keyName string

A fully-qualified path representing Key resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromLocationName(locationName)

matchLocationFromLocationName(locationName: string): string | number;

Parse the location from Location resource.

Parameter
NameDescription
locationName string

A fully-qualified path representing Location resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchProjectFromKeyName(keyName)

matchProjectFromKeyName(keyName: string): string | number;

Parse the project from Key resource.

Parameter
NameDescription
keyName string

A fully-qualified path representing Key resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromLocationName(locationName)

matchProjectFromLocationName(locationName: string): string | number;

Parse the project from Location resource.

Parameter
NameDescription
locationName string

A fully-qualified path representing Location resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromProjectName(projectName)

matchProjectFromProjectName(projectName: string): string | number;

Parse the project from Project resource.

Parameter
NameDescription
projectName string

A fully-qualified path representing Project resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

projectPath(project)

projectPath(project: string): string;

Return a fully-qualified project resource name string.

Parameter
NameDescription
project string
Returns
TypeDescription
string

{string} Resource name string.

undeleteKey(request, options)

undeleteKey(request?: protos.google.api.apikeys.v2.IUndeleteKeyRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Undeletes an API key which was deleted within 30 days.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IUndeleteKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The resource name of the API key to be undeleted.
   */
  // const name = 'abc123'

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callUndeleteKey() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const [operation] = await apikeysClient.undeleteKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callUndeleteKey();

undeleteKey(request, options, callback)

undeleteKey(request: protos.google.api.apikeys.v2.IUndeleteKeyRequest, options: CallOptions, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IUndeleteKeyRequest
options CallOptions
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

undeleteKey(request, callback)

undeleteKey(request: protos.google.api.apikeys.v2.IUndeleteKeyRequest, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IUndeleteKeyRequest
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

updateKey(request, options)

updateKey(request?: protos.google.api.apikeys.v2.IUpdateKeyRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Patches the modifiable fields of an API key. The key string of the API key isn't included in the response.

NOTE: Key is a global resource; hence the only supported value for location is global.

Parameters
NameDescription
request IUpdateKeyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Set the `name` field to the resource name of the API key to be
   *  updated. You can update only the `display_name`, `restrictions`, and
   *  `annotations` fields.
   */
  // const key = {}
  /**
   *  The field mask specifies which fields to be updated as part of this
   *  request. All other fields are ignored.
   *  Mutable fields are: `display_name`, `restrictions`, and `annotations`.
   *  If an update mask is not provided, the service treats it as an implied mask
   *  equivalent to all allowed fields that are set on the wire. If the field
   *  mask has a special value "*", the service treats it equivalent to replace
   *  all allowed mutable fields.
   */
  // const updateMask = {}

  // Imports the Apikeys library
  const {ApiKeysClient} = require('@google-cloud/apikeys').v2;

  // Instantiates a client
  const apikeysClient = new ApiKeysClient();

  async function callUpdateKey() {
    // Construct request
    const request = {
      key,
    };

    // Run request
    const [operation] = await apikeysClient.updateKey(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callUpdateKey();

updateKey(request, options, callback)

updateKey(request: protos.google.api.apikeys.v2.IUpdateKeyRequest, options: CallOptions, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IUpdateKeyRequest
options CallOptions
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

updateKey(request, callback)

updateKey(request: protos.google.api.apikeys.v2.IUpdateKeyRequest, callback: Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IUpdateKeyRequest
callback Callback<LROperation<protos.google.api.apikeys.v2.IKey, protos.google.protobuf.IEmpty>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void