Class ApiKeysClient
- All Implemented Interfaces:
BackgroundResource,AutoCloseable
This class provides the ability to make remote calls to the backing service through method calls that map to API methods. Sample code to get started:
// 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.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) {
KeyName name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]");
Key response = apiKeysClient.getKey(name);
}
Note: close() needs to be called on the ApiKeysClient object to clean up resources such as threads. In the example above, try-with-resources is used, which automatically calls close().
| Method | Description | Method Variants |
|---|---|---|
CreateKey |
Creates a new API key. NOTE: Key is a global resource; hence the only supported value for location is `global`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Methods that return long-running operations have "Async" method variants that return `OperationFuture`, which is used to track polling of the service.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
ListKeys |
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`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetKey |
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`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
GetKeyString |
Get the key string for an API key. NOTE: Key is a global resource; hence the only supported value for location is `global`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
"Flattened" method variants have converted the fields of the request object into function parameters to enable multiple ways to call the same method.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UpdateKey |
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`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Methods that return long-running operations have "Async" method variants that return `OperationFuture`, which is used to track polling of the service.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
DeleteKey |
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`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Methods that return long-running operations have "Async" method variants that return `OperationFuture`, which is used to track polling of the service.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
UndeleteKey |
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`. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
LookupKey |
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. |
Request object method variants only take one parameter, a request object, which must be constructed before the call.
Callable method variants take no parameters and return an immutable API callable object, which can be used to initiate calls to the service.
|
See the individual methods for example code.
Many parameters require resource names to be formatted in a particular way. To assist with these names, this class includes a format method for each type of name, and additionally a parse method to extract the individual identifiers contained within names that are returned.
This class can be customized by passing in a custom instance of ApiKeysSettings to create(). For example:
To customize credentials:
// 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.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ApiKeysSettings apiKeysSettings =
ApiKeysSettings.newBuilder()
.setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
.build();
ApiKeysClient apiKeysClient = ApiKeysClient.create(apiKeysSettings);
To customize the endpoint:
// 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.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ApiKeysSettings apiKeysSettings = ApiKeysSettings.newBuilder().setEndpoint(myEndpoint).build();
ApiKeysClient apiKeysClient = ApiKeysClient.create(apiKeysSettings);
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over the wire:
// 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.
// - It may require specifying regional endpoints when creating the service client as shown in
// https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
ApiKeysSettings apiKeysSettings = ApiKeysSettings.newHttpJsonBuilder().build();
ApiKeysClient apiKeysClient = ApiKeysClient.create(apiKeysSettings);
Please refer to the GitHub repository's samples for more quickstart code snippets.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic class -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedApiKeysClient(ApiKeysSettings settings) Constructs an instance of ApiKeysClient, using the given settings.protectedApiKeysClient(ApiKeysStub stub) -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(long duration, TimeUnit unit) final voidclose()static final ApiKeysClientcreate()Constructs an instance of ApiKeysClient with default settings.static final ApiKeysClientcreate(ApiKeysSettings settings) Constructs an instance of ApiKeysClient, using the given settings.static final ApiKeysClientcreate(ApiKeysStub stub) Constructs an instance of ApiKeysClient, using the given stub for making calls.final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(CreateKeyRequest request) Creates a new API key.final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(LocationName parent, Key key, String keyId) Creates a new API key.final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(String parent, Key key, String keyId) Creates a new API key.Creates a new API key.final OperationCallable<CreateKeyRequest,Key, com.google.protobuf.Empty> Creates a new API key.final OperationFuture<Key,com.google.protobuf.Empty> deleteKeyAsync(DeleteKeyRequest request) Deletes an API key.final OperationFuture<Key,com.google.protobuf.Empty> deleteKeyAsync(KeyName name) Deletes an API key.final OperationFuture<Key,com.google.protobuf.Empty> deleteKeyAsync(String name) Deletes an API key.Deletes an API key.final OperationCallable<DeleteKeyRequest,Key, com.google.protobuf.Empty> Deletes an API key.final OperationsClientReturns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.final KeygetKey(GetKeyRequest request) Gets the metadata for an API key.final KeyGets the metadata for an API key.final KeyGets the metadata for an API key.final UnaryCallable<GetKeyRequest,Key> Gets the metadata for an API key.final GetKeyStringResponsegetKeyString(GetKeyStringRequest request) Get the key string for an API key.final GetKeyStringResponsegetKeyString(KeyName name) Get the key string for an API key.final GetKeyStringResponsegetKeyString(String name) Get the key string for an API key.Get the key string for an API key.final OperationsClientReturns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call.final ApiKeysSettingsgetStub()booleanbooleanlistKeys(ListKeysRequest request) Lists the API keys owned by a project.listKeys(LocationName parent) Lists the API keys owned by a project.Lists the API keys owned by a project.Lists the API keys owned by a project.Lists the API keys owned by a project.final LookupKeyResponselookupKey(LookupKeyRequest request) Find the parent project and resource name of the API key that matches the key string in the request.Find the parent project and resource name of the API key that matches the key string in the request.voidshutdown()voidfinal OperationFuture<Key,com.google.protobuf.Empty> undeleteKeyAsync(UndeleteKeyRequest request) Undeletes an API key which was deleted within 30 days.Undeletes an API key which was deleted within 30 days.final OperationCallable<UndeleteKeyRequest,Key, com.google.protobuf.Empty> Undeletes an API key which was deleted within 30 days.final OperationFuture<Key,com.google.protobuf.Empty> updateKeyAsync(Key key, com.google.protobuf.FieldMask updateMask) Patches the modifiable fields of an API key.final OperationFuture<Key,com.google.protobuf.Empty> updateKeyAsync(UpdateKeyRequest request) Patches the modifiable fields of an API key.Patches the modifiable fields of an API key.final OperationCallable<UpdateKeyRequest,Key, com.google.protobuf.Empty> Patches the modifiable fields of an API key.
-
Constructor Details
-
ApiKeysClient
Constructs an instance of ApiKeysClient, using the given settings. This is protected so that it is easy to make a subclass, but otherwise, the static factory methods should be preferred.- Throws:
IOException
-
ApiKeysClient
-
-
Method Details
-
create
Constructs an instance of ApiKeysClient with default settings.- Throws:
IOException
-
create
Constructs an instance of ApiKeysClient, using the given settings. The channels are created based on the settings passed in, or defaults for any settings that are not set.- Throws:
IOException
-
create
Constructs an instance of ApiKeysClient, using the given stub for making calls. This is for advanced usage - prefer using create(ApiKeysSettings). -
getSettings
-
getStub
-
getOperationsClient
Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call. -
getHttpJsonOperationsClient
Returns the OperationsClient that can be used to query the status of a long-running operation returned by another API method call. -
createKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(LocationName parent, Key key, String keyId) Creates a new API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); Key key = Key.newBuilder().build(); String keyId = "keyId101944282"; Key response = apiKeysClient.createKeyAsync(parent, key, keyId).get(); }- Parameters:
parent- Required. The project in which the API key is created.key- Required. The API key fields to set at creation time. You can configure only the `display_name`, `restrictions`, and `annotations` fields.keyId- 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.
- Throws:
ApiException- if the remote call fails
-
createKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(String parent, Key key, String keyId) Creates a new API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); Key key = Key.newBuilder().build(); String keyId = "keyId101944282"; Key response = apiKeysClient.createKeyAsync(parent, key, keyId).get(); }- Parameters:
parent- Required. The project in which the API key is created.key- Required. The API key fields to set at creation time. You can configure only the `display_name`, `restrictions`, and `annotations` fields.keyId- 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.
- Throws:
ApiException- if the remote call fails
-
createKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> createKeyAsync(CreateKeyRequest request) Creates a new API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { CreateKeyRequest request = CreateKeyRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setKey(Key.newBuilder().build()) .setKeyId("keyId101944282") .build(); Key response = apiKeysClient.createKeyAsync(request).get(); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
createKeyOperationCallable
public final OperationCallable<CreateKeyRequest,Key, createKeyOperationCallable()com.google.protobuf.Empty> Creates a new API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { CreateKeyRequest request = CreateKeyRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setKey(Key.newBuilder().build()) .setKeyId("keyId101944282") .build(); OperationFuture<Key, Empty> future = apiKeysClient.createKeyOperationCallable().futureCall(request); // Do something. Key response = future.get(); } -
createKeyCallable
Creates a new API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { CreateKeyRequest request = CreateKeyRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setKey(Key.newBuilder().build()) .setKeyId("keyId101944282") .build(); ApiFuture<Operation> future = apiKeysClient.createKeyCallable().futureCall(request); // Do something. Operation response = future.get(); } -
listKeys
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); for (Key element : apiKeysClient.listKeys(parent).iterateAll()) { // doThingsWith(element); } }- Parameters:
parent- Required. Lists all API keys associated with this project.- Throws:
ApiException- if the remote call fails
-
listKeys
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { String parent = LocationName.of("[PROJECT]", "[LOCATION]").toString(); for (Key element : apiKeysClient.listKeys(parent).iterateAll()) { // doThingsWith(element); } }- Parameters:
parent- Required. Lists all API keys associated with this project.- Throws:
ApiException- if the remote call fails
-
listKeys
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { ListKeysRequest request = ListKeysRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setShowDeleted(true) .build(); for (Key element : apiKeysClient.listKeys(request).iterateAll()) { // doThingsWith(element); } }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
listKeysPagedCallable
public final UnaryCallable<ListKeysRequest,ApiKeysClient.ListKeysPagedResponse> listKeysPagedCallable()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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { ListKeysRequest request = ListKeysRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setShowDeleted(true) .build(); ApiFuture<Key> future = apiKeysClient.listKeysPagedCallable().futureCall(request); // Do something. for (Key element : future.get().iterateAll()) { // doThingsWith(element); } } -
listKeysCallable
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { ListKeysRequest request = ListKeysRequest.newBuilder() .setParent(LocationName.of("[PROJECT]", "[LOCATION]").toString()) .setPageSize(883849137) .setPageToken("pageToken873572522") .setShowDeleted(true) .build(); while (true) { ListKeysResponse response = apiKeysClient.listKeysCallable().call(request); for (Key element : response.getKeysList()) { // doThingsWith(element); } String nextPageToken = response.getNextPageToken(); if (!Strings.isNullOrEmpty(nextPageToken)) { request = request.toBuilder().setPageToken(nextPageToken).build(); } else { break; } } } -
getKey
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { KeyName name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]"); Key response = apiKeysClient.getKey(name); }- Parameters:
name- Required. The resource name of the API key to get.- Throws:
ApiException- if the remote call fails
-
getKey
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { String name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString(); Key response = apiKeysClient.getKey(name); }- Parameters:
name- Required. The resource name of the API key to get.- Throws:
ApiException- if the remote call fails
-
getKey
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { GetKeyRequest request = GetKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); Key response = apiKeysClient.getKey(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
getKeyCallable
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { GetKeyRequest request = GetKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); ApiFuture<Key> future = apiKeysClient.getKeyCallable().futureCall(request); // Do something. Key response = future.get(); } -
getKeyString
Get the key string for an API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { KeyName name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]"); GetKeyStringResponse response = apiKeysClient.getKeyString(name); }- Parameters:
name- Required. The resource name of the API key to be retrieved.- Throws:
ApiException- if the remote call fails
-
getKeyString
Get the key string for an API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { String name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString(); GetKeyStringResponse response = apiKeysClient.getKeyString(name); }- Parameters:
name- Required. The resource name of the API key to be retrieved.- Throws:
ApiException- if the remote call fails
-
getKeyString
Get the key string for an API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { GetKeyStringRequest request = GetKeyStringRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); GetKeyStringResponse response = apiKeysClient.getKeyString(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
getKeyStringCallable
Get the key string for an API key.NOTE: Key is a global resource; hence the only supported value for location is `global`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { GetKeyStringRequest request = GetKeyStringRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); ApiFuture<GetKeyStringResponse> future = apiKeysClient.getKeyStringCallable().futureCall(request); // Do something. GetKeyStringResponse response = future.get(); } -
updateKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> updateKeyAsync(Key key, com.google.protobuf.FieldMask updateMask) 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { Key key = Key.newBuilder().build(); FieldMask updateMask = FieldMask.newBuilder().build(); Key response = apiKeysClient.updateKeyAsync(key, updateMask).get(); }- Parameters:
key- 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.updateMask- 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.- Throws:
ApiException- if the remote call fails
-
updateKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> updateKeyAsync(UpdateKeyRequest request) 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UpdateKeyRequest request = UpdateKeyRequest.newBuilder() .setKey(Key.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); Key response = apiKeysClient.updateKeyAsync(request).get(); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
updateKeyOperationCallable
public final OperationCallable<UpdateKeyRequest,Key, updateKeyOperationCallable()com.google.protobuf.Empty> 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UpdateKeyRequest request = UpdateKeyRequest.newBuilder() .setKey(Key.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); OperationFuture<Key, Empty> future = apiKeysClient.updateKeyOperationCallable().futureCall(request); // Do something. Key response = future.get(); } -
updateKeyCallable
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UpdateKeyRequest request = UpdateKeyRequest.newBuilder() .setKey(Key.newBuilder().build()) .setUpdateMask(FieldMask.newBuilder().build()) .build(); ApiFuture<Operation> future = apiKeysClient.updateKeyCallable().futureCall(request); // Do something. Operation response = future.get(); } -
deleteKeyAsync
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { KeyName name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]"); Key response = apiKeysClient.deleteKeyAsync(name).get(); }- Parameters:
name- Required. The resource name of the API key to be deleted.- Throws:
ApiException- if the remote call fails
-
deleteKeyAsync
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { String name = KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString(); Key response = apiKeysClient.deleteKeyAsync(name).get(); }- Parameters:
name- Required. The resource name of the API key to be deleted.- Throws:
ApiException- if the remote call fails
-
deleteKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> deleteKeyAsync(DeleteKeyRequest request) 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { DeleteKeyRequest request = DeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .setEtag("etag3123477") .build(); Key response = apiKeysClient.deleteKeyAsync(request).get(); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
deleteKeyOperationCallable
public final OperationCallable<DeleteKeyRequest,Key, deleteKeyOperationCallable()com.google.protobuf.Empty> 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { DeleteKeyRequest request = DeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .setEtag("etag3123477") .build(); OperationFuture<Key, Empty> future = apiKeysClient.deleteKeyOperationCallable().futureCall(request); // Do something. Key response = future.get(); } -
deleteKeyCallable
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { DeleteKeyRequest request = DeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .setEtag("etag3123477") .build(); ApiFuture<Operation> future = apiKeysClient.deleteKeyCallable().futureCall(request); // Do something. Operation response = future.get(); } -
undeleteKeyAsync
public final OperationFuture<Key,com.google.protobuf.Empty> undeleteKeyAsync(UndeleteKeyRequest request) 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UndeleteKeyRequest request = UndeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); Key response = apiKeysClient.undeleteKeyAsync(request).get(); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
undeleteKeyOperationCallable
public final OperationCallable<UndeleteKeyRequest,Key, undeleteKeyOperationCallable()com.google.protobuf.Empty> 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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UndeleteKeyRequest request = UndeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); OperationFuture<Key, Empty> future = apiKeysClient.undeleteKeyOperationCallable().futureCall(request); // Do something. Key response = future.get(); } -
undeleteKeyCallable
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`.
Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { UndeleteKeyRequest request = UndeleteKeyRequest.newBuilder() .setName(KeyName.of("[PROJECT]", "[LOCATION]", "[KEY]").toString()) .build(); ApiFuture<Operation> future = apiKeysClient.undeleteKeyCallable().futureCall(request); // Do something. Operation response = future.get(); } -
lookupKey
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.Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { LookupKeyRequest request = LookupKeyRequest.newBuilder().setKeyString("keyString-1988270256").build(); LookupKeyResponse response = apiKeysClient.lookupKey(request); }- Parameters:
request- The request object containing all of the parameters for the API call.- Throws:
ApiException- if the remote call fails
-
lookupKeyCallable
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.Sample code:
// 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. // - It may require specifying regional endpoints when creating the service client as shown in // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library try (ApiKeysClient apiKeysClient = ApiKeysClient.create()) { LookupKeyRequest request = LookupKeyRequest.newBuilder().setKeyString("keyString-1988270256").build(); ApiFuture<LookupKeyResponse> future = apiKeysClient.lookupKeyCallable().futureCall(request); // Do something. LookupKeyResponse response = future.get(); } -
close
public final void close()- Specified by:
closein interfaceAutoCloseable
-
shutdown
public void shutdown()- Specified by:
shutdownin interfaceBackgroundResource
-
isShutdown
public boolean isShutdown()- Specified by:
isShutdownin interfaceBackgroundResource
-
isTerminated
public boolean isTerminated()- Specified by:
isTerminatedin interfaceBackgroundResource
-
shutdownNow
public void shutdownNow()- Specified by:
shutdownNowin interfaceBackgroundResource
-
awaitTermination
- Specified by:
awaitTerminationin interfaceBackgroundResource- Throws:
InterruptedException
-