All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.api.apikeys.v2.stub.HttpJsonApiKeysStub Maven / Gradle / Ivy

There is a newer version: 0.53.0
Show newest version
/*
 * Copyright 2024 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.google.api.apikeys.v2.stub;

import static com.google.api.apikeys.v2.ApiKeysClient.ListKeysPagedResponse;

import com.google.api.HttpRule;
import com.google.api.apikeys.v2.CreateKeyRequest;
import com.google.api.apikeys.v2.DeleteKeyRequest;
import com.google.api.apikeys.v2.GetKeyRequest;
import com.google.api.apikeys.v2.GetKeyStringRequest;
import com.google.api.apikeys.v2.GetKeyStringResponse;
import com.google.api.apikeys.v2.Key;
import com.google.api.apikeys.v2.ListKeysRequest;
import com.google.api.apikeys.v2.ListKeysResponse;
import com.google.api.apikeys.v2.LookupKeyRequest;
import com.google.api.apikeys.v2.LookupKeyResponse;
import com.google.api.apikeys.v2.UndeleteKeyRequest;
import com.google.api.apikeys.v2.UpdateKeyRequest;
import com.google.api.core.InternalApi;
import com.google.api.gax.core.BackgroundResource;
import com.google.api.gax.core.BackgroundResourceAggregation;
import com.google.api.gax.httpjson.ApiMethodDescriptor;
import com.google.api.gax.httpjson.HttpJsonCallSettings;
import com.google.api.gax.httpjson.HttpJsonOperationSnapshot;
import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
import com.google.api.gax.httpjson.ProtoMessageRequestFormatter;
import com.google.api.gax.httpjson.ProtoMessageResponseParser;
import com.google.api.gax.httpjson.ProtoRestSerializer;
import com.google.api.gax.httpjson.longrunning.stub.HttpJsonOperationsStub;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.OperationCallable;
import com.google.api.gax.rpc.RequestParamsBuilder;
import com.google.api.gax.rpc.UnaryCallable;
import com.google.common.collect.ImmutableMap;
import com.google.longrunning.Operation;
import com.google.protobuf.Empty;
import com.google.protobuf.TypeRegistry;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.annotation.Generated;

// AUTO-GENERATED DOCUMENTATION AND CLASS.
/**
 * REST stub implementation for the ApiKeys service API.
 *
 * 

This class is for advanced usage and reflects the underlying API directly. */ @Generated("by gapic-generator-java") public class HttpJsonApiKeysStub extends ApiKeysStub { private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().add(Empty.getDescriptor()).add(Key.getDescriptor()).build(); private static final ApiMethodDescriptor createKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/CreateKey") .setHttpMethod("POST") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{parent=projects/*/locations/*}/keys", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "parent", request.getParent()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "keyId", request.getKeyId()); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor( request -> ProtoRestSerializer.create().toBody("key", request.getKey(), true)) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Operation.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .setOperationSnapshotFactory( (CreateKeyRequest request, Operation response) -> HttpJsonOperationSnapshot.create(response)) .build(); private static final ApiMethodDescriptor listKeysMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/ListKeys") .setHttpMethod("GET") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{parent=projects/*/locations/*}/keys", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "parent", request.getParent()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "pageSize", request.getPageSize()); serializer.putQueryParam(fields, "pageToken", request.getPageToken()); serializer.putQueryParam( fields, "showDeleted", request.getShowDeleted()); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(ListKeysResponse.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .build(); private static final ApiMethodDescriptor getKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/GetKey") .setHttpMethod("GET") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{name=projects/*/locations/*/keys/*}", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "name", request.getName()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Key.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .build(); private static final ApiMethodDescriptor getKeyStringMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/GetKeyString") .setHttpMethod("GET") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{name=projects/*/locations/*/keys/*}/keyString", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "name", request.getName()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(GetKeyStringResponse.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .build(); private static final ApiMethodDescriptor updateKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/UpdateKey") .setHttpMethod("PATCH") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{key.name=projects/*/locations/*/keys/*}", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "key.name", request.getKey().getName()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "updateMask", request.getUpdateMask()); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor( request -> ProtoRestSerializer.create().toBody("key", request.getKey(), true)) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Operation.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .setOperationSnapshotFactory( (UpdateKeyRequest request, Operation response) -> HttpJsonOperationSnapshot.create(response)) .build(); private static final ApiMethodDescriptor deleteKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/DeleteKey") .setHttpMethod("DELETE") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{name=projects/*/locations/*/keys/*}", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "name", request.getName()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "etag", request.getEtag()); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Operation.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .setOperationSnapshotFactory( (DeleteKeyRequest request, Operation response) -> HttpJsonOperationSnapshot.create(response)) .build(); private static final ApiMethodDescriptor undeleteKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/UndeleteKey") .setHttpMethod("POST") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/{name=projects/*/locations/*/keys/*}:undelete", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putPathParam(fields, "name", request.getName()); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor( request -> ProtoRestSerializer.create() .toBody("*", request.toBuilder().clearName().build(), true)) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(Operation.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .setOperationSnapshotFactory( (UndeleteKeyRequest request, Operation response) -> HttpJsonOperationSnapshot.create(response)) .build(); private static final ApiMethodDescriptor lookupKeyMethodDescriptor = ApiMethodDescriptor.newBuilder() .setFullMethodName("google.api.apikeys.v2.ApiKeys/LookupKey") .setHttpMethod("GET") .setType(ApiMethodDescriptor.MethodType.UNARY) .setRequestFormatter( ProtoMessageRequestFormatter.newBuilder() .setPath( "/v2/keys:lookupKey", request -> { Map fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); return fields; }) .setQueryParamsExtractor( request -> { Map> fields = new HashMap<>(); ProtoRestSerializer serializer = ProtoRestSerializer.create(); serializer.putQueryParam(fields, "keyString", request.getKeyString()); serializer.putQueryParam(fields, "$alt", "json;enum-encoding=int"); return fields; }) .setRequestBodyExtractor(request -> null) .build()) .setResponseParser( ProtoMessageResponseParser.newBuilder() .setDefaultInstance(LookupKeyResponse.getDefaultInstance()) .setDefaultTypeRegistry(typeRegistry) .build()) .build(); private final UnaryCallable createKeyCallable; private final OperationCallable createKeyOperationCallable; private final UnaryCallable listKeysCallable; private final UnaryCallable listKeysPagedCallable; private final UnaryCallable getKeyCallable; private final UnaryCallable getKeyStringCallable; private final UnaryCallable updateKeyCallable; private final OperationCallable updateKeyOperationCallable; private final UnaryCallable deleteKeyCallable; private final OperationCallable deleteKeyOperationCallable; private final UnaryCallable undeleteKeyCallable; private final OperationCallable undeleteKeyOperationCallable; private final UnaryCallable lookupKeyCallable; private final BackgroundResource backgroundResources; private final HttpJsonOperationsStub httpJsonOperationsStub; private final HttpJsonStubCallableFactory callableFactory; public static final HttpJsonApiKeysStub create(ApiKeysStubSettings settings) throws IOException { return new HttpJsonApiKeysStub(settings, ClientContext.create(settings)); } public static final HttpJsonApiKeysStub create(ClientContext clientContext) throws IOException { return new HttpJsonApiKeysStub(ApiKeysStubSettings.newHttpJsonBuilder().build(), clientContext); } public static final HttpJsonApiKeysStub create( ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { return new HttpJsonApiKeysStub( ApiKeysStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory); } /** * Constructs an instance of HttpJsonApiKeysStub, 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. */ protected HttpJsonApiKeysStub(ApiKeysStubSettings settings, ClientContext clientContext) throws IOException { this(settings, clientContext, new HttpJsonApiKeysCallableFactory()); } /** * Constructs an instance of HttpJsonApiKeysStub, 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. */ protected HttpJsonApiKeysStub( ApiKeysStubSettings settings, ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException { this.callableFactory = callableFactory; this.httpJsonOperationsStub = HttpJsonOperationsStub.create( clientContext, callableFactory, typeRegistry, ImmutableMap.builder() .put( "google.longrunning.Operations.GetOperation", HttpRule.newBuilder().setGet("/v2/{name=operations/*}").build()) .build()); HttpJsonCallSettings createKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(createKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); HttpJsonCallSettings listKeysTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(listKeysMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("parent", String.valueOf(request.getParent())); return builder.build(); }) .build(); HttpJsonCallSettings getKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); HttpJsonCallSettings getKeyStringTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(getKeyStringMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); HttpJsonCallSettings updateKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(updateKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("key.name", String.valueOf(request.getKey().getName())); return builder.build(); }) .build(); HttpJsonCallSettings deleteKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(deleteKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); HttpJsonCallSettings undeleteKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(undeleteKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .setParamsExtractor( request -> { RequestParamsBuilder builder = RequestParamsBuilder.create(); builder.add("name", String.valueOf(request.getName())); return builder.build(); }) .build(); HttpJsonCallSettings lookupKeyTransportSettings = HttpJsonCallSettings.newBuilder() .setMethodDescriptor(lookupKeyMethodDescriptor) .setTypeRegistry(typeRegistry) .build(); this.createKeyCallable = callableFactory.createUnaryCallable( createKeyTransportSettings, settings.createKeySettings(), clientContext); this.createKeyOperationCallable = callableFactory.createOperationCallable( createKeyTransportSettings, settings.createKeyOperationSettings(), clientContext, httpJsonOperationsStub); this.listKeysCallable = callableFactory.createUnaryCallable( listKeysTransportSettings, settings.listKeysSettings(), clientContext); this.listKeysPagedCallable = callableFactory.createPagedCallable( listKeysTransportSettings, settings.listKeysSettings(), clientContext); this.getKeyCallable = callableFactory.createUnaryCallable( getKeyTransportSettings, settings.getKeySettings(), clientContext); this.getKeyStringCallable = callableFactory.createUnaryCallable( getKeyStringTransportSettings, settings.getKeyStringSettings(), clientContext); this.updateKeyCallable = callableFactory.createUnaryCallable( updateKeyTransportSettings, settings.updateKeySettings(), clientContext); this.updateKeyOperationCallable = callableFactory.createOperationCallable( updateKeyTransportSettings, settings.updateKeyOperationSettings(), clientContext, httpJsonOperationsStub); this.deleteKeyCallable = callableFactory.createUnaryCallable( deleteKeyTransportSettings, settings.deleteKeySettings(), clientContext); this.deleteKeyOperationCallable = callableFactory.createOperationCallable( deleteKeyTransportSettings, settings.deleteKeyOperationSettings(), clientContext, httpJsonOperationsStub); this.undeleteKeyCallable = callableFactory.createUnaryCallable( undeleteKeyTransportSettings, settings.undeleteKeySettings(), clientContext); this.undeleteKeyOperationCallable = callableFactory.createOperationCallable( undeleteKeyTransportSettings, settings.undeleteKeyOperationSettings(), clientContext, httpJsonOperationsStub); this.lookupKeyCallable = callableFactory.createUnaryCallable( lookupKeyTransportSettings, settings.lookupKeySettings(), clientContext); this.backgroundResources = new BackgroundResourceAggregation(clientContext.getBackgroundResources()); } @InternalApi public static List getMethodDescriptors() { List methodDescriptors = new ArrayList<>(); methodDescriptors.add(createKeyMethodDescriptor); methodDescriptors.add(listKeysMethodDescriptor); methodDescriptors.add(getKeyMethodDescriptor); methodDescriptors.add(getKeyStringMethodDescriptor); methodDescriptors.add(updateKeyMethodDescriptor); methodDescriptors.add(deleteKeyMethodDescriptor); methodDescriptors.add(undeleteKeyMethodDescriptor); methodDescriptors.add(lookupKeyMethodDescriptor); return methodDescriptors; } public HttpJsonOperationsStub getHttpJsonOperationsStub() { return httpJsonOperationsStub; } @Override public UnaryCallable createKeyCallable() { return createKeyCallable; } @Override public OperationCallable createKeyOperationCallable() { return createKeyOperationCallable; } @Override public UnaryCallable listKeysCallable() { return listKeysCallable; } @Override public UnaryCallable listKeysPagedCallable() { return listKeysPagedCallable; } @Override public UnaryCallable getKeyCallable() { return getKeyCallable; } @Override public UnaryCallable getKeyStringCallable() { return getKeyStringCallable; } @Override public UnaryCallable updateKeyCallable() { return updateKeyCallable; } @Override public OperationCallable updateKeyOperationCallable() { return updateKeyOperationCallable; } @Override public UnaryCallable deleteKeyCallable() { return deleteKeyCallable; } @Override public OperationCallable deleteKeyOperationCallable() { return deleteKeyOperationCallable; } @Override public UnaryCallable undeleteKeyCallable() { return undeleteKeyCallable; } @Override public OperationCallable undeleteKeyOperationCallable() { return undeleteKeyOperationCallable; } @Override public UnaryCallable lookupKeyCallable() { return lookupKeyCallable; } @Override public final void close() { try { backgroundResources.close(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException("Failed to close resource", e); } } @Override public void shutdown() { backgroundResources.shutdown(); } @Override public boolean isShutdown() { return backgroundResources.isShutdown(); } @Override public boolean isTerminated() { return backgroundResources.isTerminated(); } @Override public void shutdownNow() { backgroundResources.shutdownNow(); } @Override public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { return backgroundResources.awaitTermination(duration, unit); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy