• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.oslogin.v1.stub;
18 
19 import com.google.api.gax.core.BackgroundResource;
20 import com.google.api.gax.core.BackgroundResourceAggregation;
21 import com.google.api.gax.grpc.GrpcCallSettings;
22 import com.google.api.gax.grpc.GrpcStubCallableFactory;
23 import com.google.api.gax.rpc.ClientContext;
24 import com.google.api.gax.rpc.UnaryCallable;
25 import com.google.cloud.oslogin.common.OsLoginProto;
26 import com.google.cloud.oslogin.v1.CreateSshPublicKeyRequest;
27 import com.google.cloud.oslogin.v1.DeletePosixAccountRequest;
28 import com.google.cloud.oslogin.v1.DeleteSshPublicKeyRequest;
29 import com.google.cloud.oslogin.v1.GetLoginProfileRequest;
30 import com.google.cloud.oslogin.v1.GetSshPublicKeyRequest;
31 import com.google.cloud.oslogin.v1.ImportSshPublicKeyRequest;
32 import com.google.cloud.oslogin.v1.ImportSshPublicKeyResponse;
33 import com.google.cloud.oslogin.v1.LoginProfile;
34 import com.google.cloud.oslogin.v1.UpdateSshPublicKeyRequest;
35 import com.google.common.collect.ImmutableMap;
36 import com.google.longrunning.stub.GrpcOperationsStub;
37 import com.google.protobuf.Empty;
38 import io.grpc.MethodDescriptor;
39 import io.grpc.protobuf.ProtoUtils;
40 import java.io.IOException;
41 import java.util.concurrent.TimeUnit;
42 import javax.annotation.Generated;
43 
44 // AUTO-GENERATED DOCUMENTATION AND CLASS.
45 /**
46  * gRPC stub implementation for the OsLoginService service API.
47  *
48  * <p>This class is for advanced usage and reflects the underlying API directly.
49  */
50 @Generated("by gapic-generator-java")
51 public class GrpcOsLoginServiceStub extends OsLoginServiceStub {
52   private static final MethodDescriptor<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
53       createSshPublicKeyMethodDescriptor =
54           MethodDescriptor.<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
55               .setType(MethodDescriptor.MethodType.UNARY)
56               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/CreateSshPublicKey")
57               .setRequestMarshaller(
58                   ProtoUtils.marshaller(CreateSshPublicKeyRequest.getDefaultInstance()))
59               .setResponseMarshaller(
60                   ProtoUtils.marshaller(OsLoginProto.SshPublicKey.getDefaultInstance()))
61               .build();
62 
63   private static final MethodDescriptor<DeletePosixAccountRequest, Empty>
64       deletePosixAccountMethodDescriptor =
65           MethodDescriptor.<DeletePosixAccountRequest, Empty>newBuilder()
66               .setType(MethodDescriptor.MethodType.UNARY)
67               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/DeletePosixAccount")
68               .setRequestMarshaller(
69                   ProtoUtils.marshaller(DeletePosixAccountRequest.getDefaultInstance()))
70               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
71               .build();
72 
73   private static final MethodDescriptor<DeleteSshPublicKeyRequest, Empty>
74       deleteSshPublicKeyMethodDescriptor =
75           MethodDescriptor.<DeleteSshPublicKeyRequest, Empty>newBuilder()
76               .setType(MethodDescriptor.MethodType.UNARY)
77               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/DeleteSshPublicKey")
78               .setRequestMarshaller(
79                   ProtoUtils.marshaller(DeleteSshPublicKeyRequest.getDefaultInstance()))
80               .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance()))
81               .build();
82 
83   private static final MethodDescriptor<GetLoginProfileRequest, LoginProfile>
84       getLoginProfileMethodDescriptor =
85           MethodDescriptor.<GetLoginProfileRequest, LoginProfile>newBuilder()
86               .setType(MethodDescriptor.MethodType.UNARY)
87               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/GetLoginProfile")
88               .setRequestMarshaller(
89                   ProtoUtils.marshaller(GetLoginProfileRequest.getDefaultInstance()))
90               .setResponseMarshaller(ProtoUtils.marshaller(LoginProfile.getDefaultInstance()))
91               .build();
92 
93   private static final MethodDescriptor<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>
94       getSshPublicKeyMethodDescriptor =
95           MethodDescriptor.<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
96               .setType(MethodDescriptor.MethodType.UNARY)
97               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/GetSshPublicKey")
98               .setRequestMarshaller(
99                   ProtoUtils.marshaller(GetSshPublicKeyRequest.getDefaultInstance()))
100               .setResponseMarshaller(
101                   ProtoUtils.marshaller(OsLoginProto.SshPublicKey.getDefaultInstance()))
102               .build();
103 
104   private static final MethodDescriptor<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>
105       importSshPublicKeyMethodDescriptor =
106           MethodDescriptor.<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>newBuilder()
107               .setType(MethodDescriptor.MethodType.UNARY)
108               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/ImportSshPublicKey")
109               .setRequestMarshaller(
110                   ProtoUtils.marshaller(ImportSshPublicKeyRequest.getDefaultInstance()))
111               .setResponseMarshaller(
112                   ProtoUtils.marshaller(ImportSshPublicKeyResponse.getDefaultInstance()))
113               .build();
114 
115   private static final MethodDescriptor<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
116       updateSshPublicKeyMethodDescriptor =
117           MethodDescriptor.<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
118               .setType(MethodDescriptor.MethodType.UNARY)
119               .setFullMethodName("google.cloud.oslogin.v1.OsLoginService/UpdateSshPublicKey")
120               .setRequestMarshaller(
121                   ProtoUtils.marshaller(UpdateSshPublicKeyRequest.getDefaultInstance()))
122               .setResponseMarshaller(
123                   ProtoUtils.marshaller(OsLoginProto.SshPublicKey.getDefaultInstance()))
124               .build();
125 
126   private final UnaryCallable<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
127       createSshPublicKeyCallable;
128   private final UnaryCallable<DeletePosixAccountRequest, Empty> deletePosixAccountCallable;
129   private final UnaryCallable<DeleteSshPublicKeyRequest, Empty> deleteSshPublicKeyCallable;
130   private final UnaryCallable<GetLoginProfileRequest, LoginProfile> getLoginProfileCallable;
131   private final UnaryCallable<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>
132       getSshPublicKeyCallable;
133   private final UnaryCallable<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>
134       importSshPublicKeyCallable;
135   private final UnaryCallable<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
136       updateSshPublicKeyCallable;
137 
138   private final BackgroundResource backgroundResources;
139   private final GrpcOperationsStub operationsStub;
140   private final GrpcStubCallableFactory callableFactory;
141 
create(OsLoginServiceStubSettings settings)142   public static final GrpcOsLoginServiceStub create(OsLoginServiceStubSettings settings)
143       throws IOException {
144     return new GrpcOsLoginServiceStub(settings, ClientContext.create(settings));
145   }
146 
create(ClientContext clientContext)147   public static final GrpcOsLoginServiceStub create(ClientContext clientContext)
148       throws IOException {
149     return new GrpcOsLoginServiceStub(
150         OsLoginServiceStubSettings.newBuilder().build(), clientContext);
151   }
152 
create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)153   public static final GrpcOsLoginServiceStub create(
154       ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException {
155     return new GrpcOsLoginServiceStub(
156         OsLoginServiceStubSettings.newBuilder().build(), clientContext, callableFactory);
157   }
158 
159   /**
160    * Constructs an instance of GrpcOsLoginServiceStub, using the given settings. This is protected
161    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
162    * preferred.
163    */
GrpcOsLoginServiceStub(OsLoginServiceStubSettings settings, ClientContext clientContext)164   protected GrpcOsLoginServiceStub(OsLoginServiceStubSettings settings, ClientContext clientContext)
165       throws IOException {
166     this(settings, clientContext, new GrpcOsLoginServiceCallableFactory());
167   }
168 
169   /**
170    * Constructs an instance of GrpcOsLoginServiceStub, using the given settings. This is protected
171    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
172    * preferred.
173    */
GrpcOsLoginServiceStub( OsLoginServiceStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)174   protected GrpcOsLoginServiceStub(
175       OsLoginServiceStubSettings settings,
176       ClientContext clientContext,
177       GrpcStubCallableFactory callableFactory)
178       throws IOException {
179     this.callableFactory = callableFactory;
180     this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory);
181 
182     GrpcCallSettings<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
183         createSshPublicKeyTransportSettings =
184             GrpcCallSettings.<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
185                 .setMethodDescriptor(createSshPublicKeyMethodDescriptor)
186                 .setParamsExtractor(
187                     request -> {
188                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
189                       params.put("parent", String.valueOf(request.getParent()));
190                       return params.build();
191                     })
192                 .build();
193     GrpcCallSettings<DeletePosixAccountRequest, Empty> deletePosixAccountTransportSettings =
194         GrpcCallSettings.<DeletePosixAccountRequest, Empty>newBuilder()
195             .setMethodDescriptor(deletePosixAccountMethodDescriptor)
196             .setParamsExtractor(
197                 request -> {
198                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
199                   params.put("name", String.valueOf(request.getName()));
200                   return params.build();
201                 })
202             .build();
203     GrpcCallSettings<DeleteSshPublicKeyRequest, Empty> deleteSshPublicKeyTransportSettings =
204         GrpcCallSettings.<DeleteSshPublicKeyRequest, Empty>newBuilder()
205             .setMethodDescriptor(deleteSshPublicKeyMethodDescriptor)
206             .setParamsExtractor(
207                 request -> {
208                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
209                   params.put("name", String.valueOf(request.getName()));
210                   return params.build();
211                 })
212             .build();
213     GrpcCallSettings<GetLoginProfileRequest, LoginProfile> getLoginProfileTransportSettings =
214         GrpcCallSettings.<GetLoginProfileRequest, LoginProfile>newBuilder()
215             .setMethodDescriptor(getLoginProfileMethodDescriptor)
216             .setParamsExtractor(
217                 request -> {
218                   ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
219                   params.put("name", String.valueOf(request.getName()));
220                   return params.build();
221                 })
222             .build();
223     GrpcCallSettings<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>
224         getSshPublicKeyTransportSettings =
225             GrpcCallSettings.<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
226                 .setMethodDescriptor(getSshPublicKeyMethodDescriptor)
227                 .setParamsExtractor(
228                     request -> {
229                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
230                       params.put("name", String.valueOf(request.getName()));
231                       return params.build();
232                     })
233                 .build();
234     GrpcCallSettings<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>
235         importSshPublicKeyTransportSettings =
236             GrpcCallSettings.<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>newBuilder()
237                 .setMethodDescriptor(importSshPublicKeyMethodDescriptor)
238                 .setParamsExtractor(
239                     request -> {
240                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
241                       params.put("parent", String.valueOf(request.getParent()));
242                       return params.build();
243                     })
244                 .build();
245     GrpcCallSettings<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
246         updateSshPublicKeyTransportSettings =
247             GrpcCallSettings.<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>newBuilder()
248                 .setMethodDescriptor(updateSshPublicKeyMethodDescriptor)
249                 .setParamsExtractor(
250                     request -> {
251                       ImmutableMap.Builder<String, String> params = ImmutableMap.builder();
252                       params.put("name", String.valueOf(request.getName()));
253                       return params.build();
254                     })
255                 .build();
256 
257     this.createSshPublicKeyCallable =
258         callableFactory.createUnaryCallable(
259             createSshPublicKeyTransportSettings,
260             settings.createSshPublicKeySettings(),
261             clientContext);
262     this.deletePosixAccountCallable =
263         callableFactory.createUnaryCallable(
264             deletePosixAccountTransportSettings,
265             settings.deletePosixAccountSettings(),
266             clientContext);
267     this.deleteSshPublicKeyCallable =
268         callableFactory.createUnaryCallable(
269             deleteSshPublicKeyTransportSettings,
270             settings.deleteSshPublicKeySettings(),
271             clientContext);
272     this.getLoginProfileCallable =
273         callableFactory.createUnaryCallable(
274             getLoginProfileTransportSettings, settings.getLoginProfileSettings(), clientContext);
275     this.getSshPublicKeyCallable =
276         callableFactory.createUnaryCallable(
277             getSshPublicKeyTransportSettings, settings.getSshPublicKeySettings(), clientContext);
278     this.importSshPublicKeyCallable =
279         callableFactory.createUnaryCallable(
280             importSshPublicKeyTransportSettings,
281             settings.importSshPublicKeySettings(),
282             clientContext);
283     this.updateSshPublicKeyCallable =
284         callableFactory.createUnaryCallable(
285             updateSshPublicKeyTransportSettings,
286             settings.updateSshPublicKeySettings(),
287             clientContext);
288 
289     this.backgroundResources =
290         new BackgroundResourceAggregation(clientContext.getBackgroundResources());
291   }
292 
getOperationsStub()293   public GrpcOperationsStub getOperationsStub() {
294     return operationsStub;
295   }
296 
297   @Override
298   public UnaryCallable<CreateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
createSshPublicKeyCallable()299       createSshPublicKeyCallable() {
300     return createSshPublicKeyCallable;
301   }
302 
303   @Override
deletePosixAccountCallable()304   public UnaryCallable<DeletePosixAccountRequest, Empty> deletePosixAccountCallable() {
305     return deletePosixAccountCallable;
306   }
307 
308   @Override
deleteSshPublicKeyCallable()309   public UnaryCallable<DeleteSshPublicKeyRequest, Empty> deleteSshPublicKeyCallable() {
310     return deleteSshPublicKeyCallable;
311   }
312 
313   @Override
getLoginProfileCallable()314   public UnaryCallable<GetLoginProfileRequest, LoginProfile> getLoginProfileCallable() {
315     return getLoginProfileCallable;
316   }
317 
318   @Override
319   public UnaryCallable<GetSshPublicKeyRequest, OsLoginProto.SshPublicKey>
getSshPublicKeyCallable()320       getSshPublicKeyCallable() {
321     return getSshPublicKeyCallable;
322   }
323 
324   @Override
325   public UnaryCallable<ImportSshPublicKeyRequest, ImportSshPublicKeyResponse>
importSshPublicKeyCallable()326       importSshPublicKeyCallable() {
327     return importSshPublicKeyCallable;
328   }
329 
330   @Override
331   public UnaryCallable<UpdateSshPublicKeyRequest, OsLoginProto.SshPublicKey>
updateSshPublicKeyCallable()332       updateSshPublicKeyCallable() {
333     return updateSshPublicKeyCallable;
334   }
335 
336   @Override
close()337   public final void close() {
338     try {
339       backgroundResources.close();
340     } catch (RuntimeException e) {
341       throw e;
342     } catch (Exception e) {
343       throw new IllegalStateException("Failed to close resource", e);
344     }
345   }
346 
347   @Override
shutdown()348   public void shutdown() {
349     backgroundResources.shutdown();
350   }
351 
352   @Override
isShutdown()353   public boolean isShutdown() {
354     return backgroundResources.isShutdown();
355   }
356 
357   @Override
isTerminated()358   public boolean isTerminated() {
359     return backgroundResources.isTerminated();
360   }
361 
362   @Override
shutdownNow()363   public void shutdownNow() {
364     backgroundResources.shutdownNow();
365   }
366 
367   @Override
awaitTermination(long duration, TimeUnit unit)368   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
369     return backgroundResources.awaitTermination(duration, unit);
370   }
371 }
372