From a82410eea4b4a101c31be63e9e4445cf33bf4b94 Mon Sep 17 00:00:00 2001
From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com>
Date: Fri, 24 Jun 2022 17:14:19 +0000
Subject: [PATCH] feat: Enable REST transport for most of Java and Go clients
(#694)
- [ ] Regenerate this pull request now.
PiperOrigin-RevId: 456641589
Source-Link: https://github.com/googleapis/googleapis/commit/8a251f5225b789b2383207ffd978f6aa3d77fcf7
Source-Link: https://github.com/googleapis/googleapis-gen/commit/4ca52a529cf01308d9714950edffbea3560cfbdb
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNGNhNTJhNTI5Y2YwMTMwOGQ5NzE0OTUwZWRmZmJlYTM1NjBjZmJkYiJ9
---
java-os-login/.github/.OwlBot.lock.yaml | 4 +-
java-os-login/google-cloud-os-login/pom.xml | 16 +
.../oslogin/v1/OsLoginServiceClient.java | 14 +
.../oslogin/v1/OsLoginServiceSettings.java | 23 +-
...HttpJsonOsLoginServiceCallableFactory.java | 105 +++
.../v1/stub/HttpJsonOsLoginServiceStub.java | 466 ++++++++++
.../v1/stub/OsLoginServiceStubSettings.java | 53 +-
.../v1/OsLoginServiceClientHttpJsonTest.java | 816 ++++++++++++++++++
java-os-login/owlbot.py | 31 +
9 files changed, 1521 insertions(+), 7 deletions(-)
create mode 100644 java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceCallableFactory.java
create mode 100644 java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceStub.java
create mode 100644 java-os-login/google-cloud-os-login/src/test/java/com/google/cloud/oslogin/v1/OsLoginServiceClientHttpJsonTest.java
diff --git a/java-os-login/.github/.OwlBot.lock.yaml b/java-os-login/.github/.OwlBot.lock.yaml
index 68f2b159daba..b0fc9682243e 100644
--- a/java-os-login/.github/.OwlBot.lock.yaml
+++ b/java-os-login/.github/.OwlBot.lock.yaml
@@ -13,5 +13,5 @@
# limitations under the License.
docker:
image: gcr.io/cloud-devrel-public-resources/owlbot-java:latest
- digest: sha256:58ccd4737212f64a7dd4b3063d447447acf71a2b9d409eab19fc7a00b18eadc0
-# created: 2022-06-10T19:20:11.004014696Z
+ digest: sha256:bb0871486fc5f95f969df8fa65e002c0cf952cb7dd3bf647475c1d49ae0535b7
+
diff --git a/java-os-login/google-cloud-os-login/pom.xml b/java-os-login/google-cloud-os-login/pom.xml
index e78f766278d1..e97cc5cd1940 100644
--- a/java-os-login/google-cloud-os-login/pom.xml
+++ b/java-os-login/google-cloud-os-login/pom.xml
@@ -58,6 +58,10 @@
com.google.api
gax-grpc
+
+ com.google.api
+ gax-httpjson
+
org.threeten
threetenbp
@@ -88,12 +92,24 @@
test
+
+ com.google.api
+ gax
+ testlib
+ test
+
com.google.api
gax-grpc
testlib
test
+
+ com.google.api
+ gax-httpjson
+ testlib
+ test
+
diff --git a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceClient.java b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceClient.java
index 090237569874..d7b0251e8516 100644
--- a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceClient.java
+++ b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceClient.java
@@ -94,6 +94,20 @@
* OsLoginServiceClient osLoginServiceClient = OsLoginServiceClient.create(osLoginServiceSettings);
* }
*
+ *
To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
+ * the wire:
+ *
+ *
{@code
+ * // This snippet has been automatically generated for illustrative purposes only.
+ * // It may require modifications to work in your environment.
+ * OsLoginServiceSettings osLoginServiceSettings =
+ * OsLoginServiceSettings.newBuilder()
+ * .setTransportChannelProvider(
+ * OsLoginServiceSettings.defaultHttpJsonTransportProviderBuilder().build())
+ * .build();
+ * OsLoginServiceClient osLoginServiceClient = OsLoginServiceClient.create(osLoginServiceSettings);
+ * }
+ *
* Please refer to the GitHub repository's samples for more quickstart code snippets.
*/
@Generated("by gapic-generator-java")
diff --git a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java
index b5230edc65c4..9b86fee6038f 100644
--- a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java
+++ b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/OsLoginServiceSettings.java
@@ -21,6 +21,7 @@
import com.google.api.gax.core.GoogleCredentialsProvider;
import com.google.api.gax.core.InstantiatingExecutorProvider;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
import com.google.api.gax.rpc.ClientSettings;
@@ -128,11 +129,18 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
return OsLoginServiceStubSettings.defaultCredentialsProviderBuilder();
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return OsLoginServiceStubSettings.defaultGrpcTransportProviderBuilder();
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return OsLoginServiceStubSettings.defaultHttpJsonTransportProviderBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return OsLoginServiceStubSettings.defaultTransportChannelProvider();
}
@@ -142,11 +150,17 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
return OsLoginServiceStubSettings.defaultApiClientHeaderProviderBuilder();
}
- /** Returns a new builder for this class. */
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ @BetaApi
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -184,6 +198,11 @@ private static Builder createDefault() {
return new Builder(OsLoginServiceStubSettings.newBuilder());
}
+ @BetaApi
+ private static Builder createHttpJsonDefault() {
+ return new Builder(OsLoginServiceStubSettings.newHttpJsonBuilder());
+ }
+
public OsLoginServiceStubSettings.Builder getStubSettingsBuilder() {
return ((OsLoginServiceStubSettings.Builder) getStubSettings());
}
diff --git a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceCallableFactory.java b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceCallableFactory.java
new file mode 100644
index 000000000000..269cf0c71475
--- /dev/null
+++ b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceCallableFactory.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2022 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.cloud.oslogin.v1.stub;
+
+import com.google.api.core.BetaApi;
+import com.google.api.gax.httpjson.HttpJsonCallSettings;
+import com.google.api.gax.httpjson.HttpJsonCallableFactory;
+import com.google.api.gax.httpjson.HttpJsonOperationSnapshotCallable;
+import com.google.api.gax.httpjson.HttpJsonStubCallableFactory;
+import com.google.api.gax.httpjson.longrunning.stub.OperationsStub;
+import com.google.api.gax.rpc.BatchingCallSettings;
+import com.google.api.gax.rpc.ClientContext;
+import com.google.api.gax.rpc.OperationCallSettings;
+import com.google.api.gax.rpc.OperationCallable;
+import com.google.api.gax.rpc.PagedCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallSettings;
+import com.google.api.gax.rpc.ServerStreamingCallable;
+import com.google.api.gax.rpc.UnaryCallSettings;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.longrunning.Operation;
+import javax.annotation.Generated;
+
+// AUTO-GENERATED DOCUMENTATION AND CLASS.
+/**
+ * REST callable factory implementation for the OsLoginService service API.
+ *
+ *
This class is for advanced usage.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonOsLoginServiceCallableFactory
+ implements HttpJsonStubCallableFactory {
+
+ @Override
+ public UnaryCallable createUnaryCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ UnaryCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createUnaryCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public
+ UnaryCallable createPagedCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ PagedCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createPagedCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @Override
+ public UnaryCallable createBatchingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ BatchingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createBatchingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+
+ @BetaApi(
+ "The surface for long-running operations is not stable yet and may change in the future.")
+ @Override
+ public
+ OperationCallable createOperationCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ OperationCallSettings callSettings,
+ ClientContext clientContext,
+ OperationsStub operationsStub) {
+ UnaryCallable innerCallable =
+ HttpJsonCallableFactory.createBaseUnaryCallable(
+ httpJsonCallSettings, callSettings.getInitialCallSettings(), clientContext);
+ HttpJsonOperationSnapshotCallable initialCallable =
+ new HttpJsonOperationSnapshotCallable(
+ innerCallable,
+ httpJsonCallSettings.getMethodDescriptor().getOperationSnapshotFactory());
+ return HttpJsonCallableFactory.createOperationCallable(
+ callSettings, clientContext, operationsStub.longRunningClient(), initialCallable);
+ }
+
+ @Override
+ public
+ ServerStreamingCallable createServerStreamingCallable(
+ HttpJsonCallSettings httpJsonCallSettings,
+ ServerStreamingCallSettings callSettings,
+ ClientContext clientContext) {
+ return HttpJsonCallableFactory.createServerStreamingCallable(
+ httpJsonCallSettings, callSettings, clientContext);
+ }
+}
diff --git a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceStub.java b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceStub.java
new file mode 100644
index 000000000000..5b198703d854
--- /dev/null
+++ b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/HttpJsonOsLoginServiceStub.java
@@ -0,0 +1,466 @@
+/*
+ * Copyright 2022 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.cloud.oslogin.v1.stub;
+
+import com.google.api.core.BetaApi;
+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.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.rpc.ClientContext;
+import com.google.api.gax.rpc.UnaryCallable;
+import com.google.cloud.oslogin.common.OsLoginProto;
+import com.google.cloud.oslogin.v1.DeletePosixAccountRequest;
+import com.google.cloud.oslogin.v1.DeleteSshPublicKeyRequest;
+import com.google.cloud.oslogin.v1.GetLoginProfileRequest;
+import com.google.cloud.oslogin.v1.GetSshPublicKeyRequest;
+import com.google.cloud.oslogin.v1.ImportSshPublicKeyRequest;
+import com.google.cloud.oslogin.v1.ImportSshPublicKeyResponse;
+import com.google.cloud.oslogin.v1.LoginProfile;
+import com.google.cloud.oslogin.v1.UpdateSshPublicKeyRequest;
+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 OsLoginService service API.
+ *
+ * This class is for advanced usage and reflects the underlying API directly.
+ */
+@Generated("by gapic-generator-java")
+@BetaApi
+public class HttpJsonOsLoginServiceStub extends OsLoginServiceStub {
+ private static final TypeRegistry typeRegistry = TypeRegistry.newBuilder().build();
+
+ private static final ApiMethodDescriptor
+ deletePosixAccountMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=users/*/projects/*}",
+ 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();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Empty.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ deleteSshPublicKeyMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey")
+ .setHttpMethod("DELETE")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=users/*/sshPublicKeys/*}",
+ 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();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(Empty.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ getLoginProfileMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/GetLoginProfile")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=users/*}/loginProfile",
+ 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, "projectId", request.getProjectId());
+ serializer.putQueryParam(fields, "systemId", request.getSystemId());
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(LoginProfile.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ getSshPublicKeyMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/GetSshPublicKey")
+ .setHttpMethod("GET")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=users/*/sshPublicKeys/*}",
+ 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();
+ return fields;
+ })
+ .setRequestBodyExtractor(request -> null)
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(OsLoginProto.SshPublicKey.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ importSshPublicKeyMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/ImportSshPublicKey")
+ .setHttpMethod("POST")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{parent=users/*}:importSshPublicKey",
+ 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, "projectId", request.getProjectId());
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("sshPublicKey", request.getSshPublicKey()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(ImportSshPublicKeyResponse.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private static final ApiMethodDescriptor
+ updateSshPublicKeyMethodDescriptor =
+ ApiMethodDescriptor.newBuilder()
+ .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/UpdateSshPublicKey")
+ .setHttpMethod("PATCH")
+ .setType(ApiMethodDescriptor.MethodType.UNARY)
+ .setRequestFormatter(
+ ProtoMessageRequestFormatter.newBuilder()
+ .setPath(
+ "/v1/{name=users/*/sshPublicKeys/*}",
+ 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, "updateMask", request.getUpdateMask());
+ return fields;
+ })
+ .setRequestBodyExtractor(
+ request ->
+ ProtoRestSerializer.create()
+ .toBody("sshPublicKey", request.getSshPublicKey()))
+ .build())
+ .setResponseParser(
+ ProtoMessageResponseParser.newBuilder()
+ .setDefaultInstance(OsLoginProto.SshPublicKey.getDefaultInstance())
+ .setDefaultTypeRegistry(typeRegistry)
+ .build())
+ .build();
+
+ private final UnaryCallable deletePosixAccountCallable;
+ private final UnaryCallable deleteSshPublicKeyCallable;
+ private final UnaryCallable getLoginProfileCallable;
+ private final UnaryCallable
+ getSshPublicKeyCallable;
+ private final UnaryCallable
+ importSshPublicKeyCallable;
+ private final UnaryCallable
+ updateSshPublicKeyCallable;
+
+ private final BackgroundResource backgroundResources;
+ private final HttpJsonStubCallableFactory callableFactory;
+
+ public static final HttpJsonOsLoginServiceStub create(OsLoginServiceStubSettings settings)
+ throws IOException {
+ return new HttpJsonOsLoginServiceStub(settings, ClientContext.create(settings));
+ }
+
+ public static final HttpJsonOsLoginServiceStub create(ClientContext clientContext)
+ throws IOException {
+ return new HttpJsonOsLoginServiceStub(
+ OsLoginServiceStubSettings.newHttpJsonBuilder().build(), clientContext);
+ }
+
+ public static final HttpJsonOsLoginServiceStub create(
+ ClientContext clientContext, HttpJsonStubCallableFactory callableFactory) throws IOException {
+ return new HttpJsonOsLoginServiceStub(
+ OsLoginServiceStubSettings.newHttpJsonBuilder().build(), clientContext, callableFactory);
+ }
+
+ /**
+ * Constructs an instance of HttpJsonOsLoginServiceStub, 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 HttpJsonOsLoginServiceStub(
+ OsLoginServiceStubSettings settings, ClientContext clientContext) throws IOException {
+ this(settings, clientContext, new HttpJsonOsLoginServiceCallableFactory());
+ }
+
+ /**
+ * Constructs an instance of HttpJsonOsLoginServiceStub, 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 HttpJsonOsLoginServiceStub(
+ OsLoginServiceStubSettings settings,
+ ClientContext clientContext,
+ HttpJsonStubCallableFactory callableFactory)
+ throws IOException {
+ this.callableFactory = callableFactory;
+
+ HttpJsonCallSettings deletePosixAccountTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deletePosixAccountMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings deleteSshPublicKeyTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(deleteSshPublicKeyMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings getLoginProfileTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getLoginProfileMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ getSshPublicKeyTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(getSshPublicKeyMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ importSshPublicKeyTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(importSshPublicKeyMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+ HttpJsonCallSettings
+ updateSshPublicKeyTransportSettings =
+ HttpJsonCallSettings.newBuilder()
+ .setMethodDescriptor(updateSshPublicKeyMethodDescriptor)
+ .setTypeRegistry(typeRegistry)
+ .build();
+
+ this.deletePosixAccountCallable =
+ callableFactory.createUnaryCallable(
+ deletePosixAccountTransportSettings,
+ settings.deletePosixAccountSettings(),
+ clientContext);
+ this.deleteSshPublicKeyCallable =
+ callableFactory.createUnaryCallable(
+ deleteSshPublicKeyTransportSettings,
+ settings.deleteSshPublicKeySettings(),
+ clientContext);
+ this.getLoginProfileCallable =
+ callableFactory.createUnaryCallable(
+ getLoginProfileTransportSettings, settings.getLoginProfileSettings(), clientContext);
+ this.getSshPublicKeyCallable =
+ callableFactory.createUnaryCallable(
+ getSshPublicKeyTransportSettings, settings.getSshPublicKeySettings(), clientContext);
+ this.importSshPublicKeyCallable =
+ callableFactory.createUnaryCallable(
+ importSshPublicKeyTransportSettings,
+ settings.importSshPublicKeySettings(),
+ clientContext);
+ this.updateSshPublicKeyCallable =
+ callableFactory.createUnaryCallable(
+ updateSshPublicKeyTransportSettings,
+ settings.updateSshPublicKeySettings(),
+ clientContext);
+
+ this.backgroundResources =
+ new BackgroundResourceAggregation(clientContext.getBackgroundResources());
+ }
+
+ @InternalApi
+ public static List getMethodDescriptors() {
+ List methodDescriptors = new ArrayList<>();
+ methodDescriptors.add(deletePosixAccountMethodDescriptor);
+ methodDescriptors.add(deleteSshPublicKeyMethodDescriptor);
+ methodDescriptors.add(getLoginProfileMethodDescriptor);
+ methodDescriptors.add(getSshPublicKeyMethodDescriptor);
+ methodDescriptors.add(importSshPublicKeyMethodDescriptor);
+ methodDescriptors.add(updateSshPublicKeyMethodDescriptor);
+ return methodDescriptors;
+ }
+
+ @Override
+ public UnaryCallable deletePosixAccountCallable() {
+ return deletePosixAccountCallable;
+ }
+
+ @Override
+ public UnaryCallable deleteSshPublicKeyCallable() {
+ return deleteSshPublicKeyCallable;
+ }
+
+ @Override
+ public UnaryCallable getLoginProfileCallable() {
+ return getLoginProfileCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ getSshPublicKeyCallable() {
+ return getSshPublicKeyCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ importSshPublicKeyCallable() {
+ return importSshPublicKeyCallable;
+ }
+
+ @Override
+ public UnaryCallable
+ updateSshPublicKeyCallable() {
+ return updateSshPublicKeyCallable;
+ }
+
+ @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);
+ }
+}
diff --git a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java
index 529d051b337b..ccaf232202e2 100644
--- a/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java
+++ b/java-os-login/google-cloud-os-login/src/main/java/com/google/cloud/oslogin/v1/stub/OsLoginServiceStubSettings.java
@@ -24,6 +24,9 @@
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.GrpcTransportChannel;
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.HttpJsonTransportChannel;
+import com.google.api.gax.httpjson.InstantiatingHttpJsonChannelProvider;
import com.google.api.gax.retrying.RetrySettings;
import com.google.api.gax.rpc.ApiClientHeaderProvider;
import com.google.api.gax.rpc.ClientContext;
@@ -142,6 +145,11 @@ public OsLoginServiceStub createStub() throws IOException {
.equals(GrpcTransportChannel.getGrpcTransportName())) {
return GrpcOsLoginServiceStub.create(this);
}
+ if (getTransportChannelProvider()
+ .getTransportName()
+ .equals(HttpJsonTransportChannel.getHttpJsonTransportName())) {
+ return HttpJsonOsLoginServiceStub.create(this);
+ }
throw new UnsupportedOperationException(
String.format(
"Transport not supported: %s", getTransportChannelProvider().getTransportName()));
@@ -174,18 +182,25 @@ public static GoogleCredentialsProvider.Builder defaultCredentialsProviderBuilde
.setUseJwtAccessWithScope(true);
}
- /** Returns a builder for the default ChannelProvider for this service. */
+ /** Returns a builder for the default gRPC ChannelProvider for this service. */
public static InstantiatingGrpcChannelProvider.Builder defaultGrpcTransportProviderBuilder() {
return InstantiatingGrpcChannelProvider.newBuilder()
.setMaxInboundMessageSize(Integer.MAX_VALUE);
}
+ /** Returns a builder for the default REST ChannelProvider for this service. */
+ @BetaApi
+ public static InstantiatingHttpJsonChannelProvider.Builder
+ defaultHttpJsonTransportProviderBuilder() {
+ return InstantiatingHttpJsonChannelProvider.newBuilder();
+ }
+
public static TransportChannelProvider defaultTransportChannelProvider() {
return defaultGrpcTransportProviderBuilder().build();
}
@BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
- public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ public static ApiClientHeaderProvider.Builder defaultGrpcApiClientHeaderProviderBuilder() {
return ApiClientHeaderProvider.newBuilder()
.setGeneratedLibToken(
"gapic", GaxProperties.getLibraryVersion(OsLoginServiceStubSettings.class))
@@ -193,11 +208,30 @@ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuil
GaxGrpcProperties.getGrpcTokenName(), GaxGrpcProperties.getGrpcVersion());
}
- /** Returns a new builder for this class. */
+ @BetaApi("The surface for customizing headers is not stable yet and may change in the future.")
+ public static ApiClientHeaderProvider.Builder defaultHttpJsonApiClientHeaderProviderBuilder() {
+ return ApiClientHeaderProvider.newBuilder()
+ .setGeneratedLibToken(
+ "gapic", GaxProperties.getLibraryVersion(OsLoginServiceStubSettings.class))
+ .setTransportToken(
+ GaxHttpJsonProperties.getHttpJsonTokenName(),
+ GaxHttpJsonProperties.getHttpJsonVersion());
+ }
+
+ public static ApiClientHeaderProvider.Builder defaultApiClientHeaderProviderBuilder() {
+ return OsLoginServiceStubSettings.defaultGrpcApiClientHeaderProviderBuilder();
+ }
+
+ /** Returns a new gRPC builder for this class. */
public static Builder newBuilder() {
return Builder.createDefault();
}
+ /** Returns a new REST builder for this class. */
+ public static Builder newHttpJsonBuilder() {
+ return Builder.createHttpJsonDefault();
+ }
+
/** Returns a new builder for this class. */
public static Builder newBuilder(ClientContext clientContext) {
return new Builder(clientContext);
@@ -325,6 +359,19 @@ private static Builder createDefault() {
return initDefaults(builder);
}
+ private static Builder createHttpJsonDefault() {
+ Builder builder = new Builder(((ClientContext) null));
+
+ builder.setTransportChannelProvider(defaultHttpJsonTransportProviderBuilder().build());
+ builder.setCredentialsProvider(defaultCredentialsProviderBuilder().build());
+ builder.setInternalHeaderProvider(defaultHttpJsonApiClientHeaderProviderBuilder().build());
+ builder.setEndpoint(getDefaultEndpoint());
+ builder.setMtlsEndpoint(getDefaultMtlsEndpoint());
+ builder.setSwitchToMtlsEndpointAllowed(true);
+
+ return initDefaults(builder);
+ }
+
private static Builder initDefaults(Builder builder) {
builder
.deletePosixAccountSettings()
diff --git a/java-os-login/google-cloud-os-login/src/test/java/com/google/cloud/oslogin/v1/OsLoginServiceClientHttpJsonTest.java b/java-os-login/google-cloud-os-login/src/test/java/com/google/cloud/oslogin/v1/OsLoginServiceClientHttpJsonTest.java
new file mode 100644
index 000000000000..b3bf589dba44
--- /dev/null
+++ b/java-os-login/google-cloud-os-login/src/test/java/com/google/cloud/oslogin/v1/OsLoginServiceClientHttpJsonTest.java
@@ -0,0 +1,816 @@
+/*
+ * Copyright 2022 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.cloud.oslogin.v1;
+
+import com.google.api.gax.core.NoCredentialsProvider;
+import com.google.api.gax.httpjson.GaxHttpJsonProperties;
+import com.google.api.gax.httpjson.testing.MockHttpService;
+import com.google.api.gax.rpc.ApiClientHeaderProvider;
+import com.google.api.gax.rpc.ApiException;
+import com.google.api.gax.rpc.ApiExceptionFactory;
+import com.google.api.gax.rpc.InvalidArgumentException;
+import com.google.api.gax.rpc.StatusCode;
+import com.google.api.gax.rpc.testing.FakeStatusCode;
+import com.google.cloud.oslogin.common.OsLoginProto;
+import com.google.cloud.oslogin.v1.stub.HttpJsonOsLoginServiceStub;
+import com.google.protobuf.Empty;
+import com.google.protobuf.FieldMask;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import javax.annotation.Generated;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+@Generated("by gapic-generator-java")
+public class OsLoginServiceClientHttpJsonTest {
+ private static MockHttpService mockService;
+ private static OsLoginServiceClient client;
+
+ @BeforeClass
+ public static void startStaticServer() throws IOException {
+ mockService =
+ new MockHttpService(
+ HttpJsonOsLoginServiceStub.getMethodDescriptors(),
+ OsLoginServiceSettings.getDefaultEndpoint());
+ OsLoginServiceSettings settings =
+ OsLoginServiceSettings.newHttpJsonBuilder()
+ .setTransportChannelProvider(
+ OsLoginServiceSettings.defaultHttpJsonTransportProviderBuilder()
+ .setHttpTransport(mockService)
+ .build())
+ .setCredentialsProvider(NoCredentialsProvider.create())
+ .build();
+ client = OsLoginServiceClient.create(settings);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ client.close();
+ }
+
+ @Before
+ public void setUp() {}
+
+ @After
+ public void tearDown() throws Exception {
+ mockService.reset();
+ }
+
+ @Test
+ public void deletePosixAccountTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ ProjectName name = ProjectName.of("[USER]", "[PROJECT]");
+
+ client.deletePosixAccount(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deletePosixAccountExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ ProjectName name = ProjectName.of("[USER]", "[PROJECT]");
+ client.deletePosixAccount(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deletePosixAccountTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-9716/projects/project-9716";
+
+ client.deletePosixAccount(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deletePosixAccountExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-9716/projects/project-9716";
+ client.deletePosixAccount(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteSshPublicKeyTest() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+
+ client.deleteSshPublicKey(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deleteSshPublicKeyExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ client.deleteSshPublicKey(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void deleteSshPublicKeyTest2() throws Exception {
+ Empty expectedResponse = Empty.newBuilder().build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+
+ client.deleteSshPublicKey(name);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void deleteSshPublicKeyExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ client.deleteSshPublicKey(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getLoginProfileTest() throws Exception {
+ LoginProfile expectedResponse =
+ LoginProfile.newBuilder()
+ .setName("name3373707")
+ .addAllPosixAccounts(new ArrayList())
+ .putAllSshPublicKeys(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ UserName name = UserName.of("[USER]");
+
+ LoginProfile actualResponse = client.getLoginProfile(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getLoginProfileExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ UserName name = UserName.of("[USER]");
+ client.getLoginProfile(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getLoginProfileTest2() throws Exception {
+ LoginProfile expectedResponse =
+ LoginProfile.newBuilder()
+ .setName("name3373707")
+ .addAllPosixAccounts(new ArrayList())
+ .putAllSshPublicKeys(new HashMap())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-6376";
+
+ LoginProfile actualResponse = client.getLoginProfile(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getLoginProfileExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-6376";
+ client.getLoginProfile(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSshPublicKeyTest() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+
+ OsLoginProto.SshPublicKey actualResponse = client.getSshPublicKey(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getSshPublicKeyExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ client.getSshPublicKey(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void getSshPublicKeyTest2() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+
+ OsLoginProto.SshPublicKey actualResponse = client.getSshPublicKey(name);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void getSshPublicKeyExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ client.getSshPublicKey(name);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void importSshPublicKeyTest() throws Exception {
+ ImportSshPublicKeyResponse expectedResponse =
+ ImportSshPublicKeyResponse.newBuilder()
+ .setLoginProfile(LoginProfile.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ UserName parent = UserName.of("[USER]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+
+ ImportSshPublicKeyResponse actualResponse = client.importSshPublicKey(parent, sshPublicKey);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importSshPublicKeyExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ UserName parent = UserName.of("[USER]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ client.importSshPublicKey(parent, sshPublicKey);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void importSshPublicKeyTest2() throws Exception {
+ ImportSshPublicKeyResponse expectedResponse =
+ ImportSshPublicKeyResponse.newBuilder()
+ .setLoginProfile(LoginProfile.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "users/user-1015";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+
+ ImportSshPublicKeyResponse actualResponse = client.importSshPublicKey(parent, sshPublicKey);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importSshPublicKeyExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "users/user-1015";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ client.importSshPublicKey(parent, sshPublicKey);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void importSshPublicKeyTest3() throws Exception {
+ ImportSshPublicKeyResponse expectedResponse =
+ ImportSshPublicKeyResponse.newBuilder()
+ .setLoginProfile(LoginProfile.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ UserName parent = UserName.of("[USER]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ String projectId = "projectId-894832108";
+
+ ImportSshPublicKeyResponse actualResponse =
+ client.importSshPublicKey(parent, sshPublicKey, projectId);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importSshPublicKeyExceptionTest3() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ UserName parent = UserName.of("[USER]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ String projectId = "projectId-894832108";
+ client.importSshPublicKey(parent, sshPublicKey, projectId);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void importSshPublicKeyTest4() throws Exception {
+ ImportSshPublicKeyResponse expectedResponse =
+ ImportSshPublicKeyResponse.newBuilder()
+ .setLoginProfile(LoginProfile.newBuilder().build())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String parent = "users/user-1015";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ String projectId = "projectId-894832108";
+
+ ImportSshPublicKeyResponse actualResponse =
+ client.importSshPublicKey(parent, sshPublicKey, projectId);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void importSshPublicKeyExceptionTest4() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String parent = "users/user-1015";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ String projectId = "projectId-894832108";
+ client.importSshPublicKey(parent, sshPublicKey, projectId);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateSshPublicKeyTest() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+
+ OsLoginProto.SshPublicKey actualResponse = client.updateSshPublicKey(name, sshPublicKey);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateSshPublicKeyExceptionTest() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ client.updateSshPublicKey(name, sshPublicKey);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateSshPublicKeyTest2() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+
+ OsLoginProto.SshPublicKey actualResponse = client.updateSshPublicKey(name, sshPublicKey);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateSshPublicKeyExceptionTest2() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ client.updateSshPublicKey(name, sshPublicKey);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateSshPublicKeyTest3() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+
+ OsLoginProto.SshPublicKey actualResponse =
+ client.updateSshPublicKey(name, sshPublicKey, updateMask);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateSshPublicKeyExceptionTest3() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ FingerprintName name = FingerprintName.of("[USER]", "[FINGERPRINT]");
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+ client.updateSshPublicKey(name, sshPublicKey, updateMask);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+
+ @Test
+ public void updateSshPublicKeyTest4() throws Exception {
+ OsLoginProto.SshPublicKey expectedResponse =
+ OsLoginProto.SshPublicKey.newBuilder()
+ .setKey("key106079")
+ .setExpirationTimeUsec(-2058878882)
+ .setFingerprint("fingerprint-1375934236")
+ .setName(FingerprintName.of("[USER]", "[FINGERPRINT]").toString())
+ .build();
+ mockService.addResponse(expectedResponse);
+
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+
+ OsLoginProto.SshPublicKey actualResponse =
+ client.updateSshPublicKey(name, sshPublicKey, updateMask);
+ Assert.assertEquals(expectedResponse, actualResponse);
+
+ List actualRequests = mockService.getRequestPaths();
+ Assert.assertEquals(1, actualRequests.size());
+
+ String apiClientHeaderKey =
+ mockService
+ .getRequestHeaders()
+ .get(ApiClientHeaderProvider.getDefaultApiClientHeaderKey())
+ .iterator()
+ .next();
+ Assert.assertTrue(
+ GaxHttpJsonProperties.getDefaultApiClientHeaderPattern()
+ .matcher(apiClientHeaderKey)
+ .matches());
+ }
+
+ @Test
+ public void updateSshPublicKeyExceptionTest4() throws Exception {
+ ApiException exception =
+ ApiExceptionFactory.createException(
+ new Exception(), FakeStatusCode.of(StatusCode.Code.INVALID_ARGUMENT), false);
+ mockService.addException(exception);
+
+ try {
+ String name = "users/user-7353/sshPublicKeys/sshPublicKey-7353";
+ OsLoginProto.SshPublicKey sshPublicKey = OsLoginProto.SshPublicKey.newBuilder().build();
+ FieldMask updateMask = FieldMask.newBuilder().build();
+ client.updateSshPublicKey(name, sshPublicKey, updateMask);
+ Assert.fail("No exception raised");
+ } catch (InvalidArgumentException e) {
+ // Expected exception.
+ }
+ }
+}
diff --git a/java-os-login/owlbot.py b/java-os-login/owlbot.py
index 1899c24a2420..e25d80cc26f0 100644
--- a/java-os-login/owlbot.py
+++ b/java-os-login/owlbot.py
@@ -54,6 +54,37 @@
s.replace('**/OsLoginServiceClientTest.java',
'import com.google.cloud.oslogin.common.ProjectName;',
'import com.google.cloud.oslogin.v1.ProjectName;')
+
+ # put any special-case replacements here
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java', 'PosixAccountName', 'ProjectName')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java', 'SshPublicKeyName',
+ 'FingerprintName')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java', 'PosixAccountName',
+ 'ProjectName')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java', 'SshPublicKeyName',
+ 'FingerprintName')
+
+ # Copy of Resource name helper classes from v1 and import replacements
+
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.FingerprintName;',
+ 'import com.google.cloud.oslogin.v1.FingerprintName;')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.UserName;',
+ 'import com.google.cloud.oslogin.v1.UserName;')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.ProjectName;',
+ 'import com.google.cloud.oslogin.v1.ProjectName;')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.FingerprintName;',
+ 'import com.google.cloud.oslogin.v1.FingerprintName;')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.UserName;',
+ 'import com.google.cloud.oslogin.v1.UserName;')
+ s.replace('**/OsLoginServiceClientHttpJsonTest.java',
+ 'import com.google.cloud.oslogin.common.ProjectName;',
+ 'import com.google.cloud.oslogin.v1.ProjectName;')
+
s.move(library)
s.remove_staging_dirs()