Debian Codegraph @

oslogin/apiv1/os_login_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package oslogin
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 osloginpb "cloud.google.com/go/oslogin/apiv1/osloginpb"
30 commonpb "cloud.google.com/go/oslogin/common/commonpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/option"
33 "google.golang.org/api/option/internaloption"
34 gtransport "google.golang.org/api/transport/grpc"
35 httptransport "google.golang.org/api/transport/http"
36 "google.golang.org/grpc"
37 "google.golang.org/grpc/codes"
38 "google.golang.org/protobuf/encoding/protojson"
39 )
40
41 var newClientHook clientHook
42
43 // CallOptions contains the retry settings for each method of Client.
44 type CallOptions struct {
45 CreateSshPublicKey []gax.CallOption
46 DeletePosixAccount []gax.CallOption
47 DeleteSshPublicKey []gax.CallOption
48 GetLoginProfile []gax.CallOption
49 GetSshPublicKey []gax.CallOption
50 ImportSshPublicKey []gax.CallOption
51 UpdateSshPublicKey []gax.CallOption
52 }
53
54 func defaultGRPCClientOptions() []option.ClientOption {
55 return []option.ClientOption{
56 internaloption.WithDefaultEndpoint("oslogin.googleapis.com:443"),
57 internaloption.WithDefaultEndpointTemplate("oslogin.UNIVERSE_DOMAIN:443"),
58 internaloption.WithDefaultMTLSEndpoint("oslogin.mtls.googleapis.com:443"),
59 internaloption.WithDefaultUniverseDomain("googleapis.com"),
60 internaloption.WithDefaultAudience("https://oslogin.googleapis.com/"),
61 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
62 internaloption.EnableJwtWithScope(),
63 internaloption.EnableNewAuthLibrary(),
64 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
65 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
66 }
67 }
68
69 func defaultCallOptions() *CallOptions {
70 return &CallOptions{
71 CreateSshPublicKey: []gax.CallOption{},
72 DeletePosixAccount: []gax.CallOption{
73 gax.WithTimeout(10000 * time.Millisecond),
74 gax.WithRetry(func() gax.Retryer {
75 return gax.OnCodes([]codes.Code{
76 codes.Unavailable,
77 codes.DeadlineExceeded,
78 }, gax.Backoff{
79 Initial: 100 * time.Millisecond,
80 Max: 60000 * time.Millisecond,
81 Multiplier: 1.30,
82 })
83 }),
84 },
85 DeleteSshPublicKey: []gax.CallOption{
86 gax.WithTimeout(10000 * time.Millisecond),
87 gax.WithRetry(func() gax.Retryer {
88 return gax.OnCodes([]codes.Code{
89 codes.Unavailable,
90 codes.DeadlineExceeded,
91 }, gax.Backoff{
92 Initial: 100 * time.Millisecond,
93 Max: 60000 * time.Millisecond,
94 Multiplier: 1.30,
95 })
96 }),
97 },
98 GetLoginProfile: []gax.CallOption{
99 gax.WithTimeout(10000 * time.Millisecond),
100 gax.WithRetry(func() gax.Retryer {
101 return gax.OnCodes([]codes.Code{
102 codes.Unavailable,
103 codes.DeadlineExceeded,
104 }, gax.Backoff{
105 Initial: 100 * time.Millisecond,
106 Max: 60000 * time.Millisecond,
107 Multiplier: 1.30,
108 })
109 }),
110 },
111 GetSshPublicKey: []gax.CallOption{
112 gax.WithTimeout(10000 * time.Millisecond),
113 gax.WithRetry(func() gax.Retryer {
114 return gax.OnCodes([]codes.Code{
115 codes.Unavailable,
116 codes.DeadlineExceeded,
117 }, gax.Backoff{
118 Initial: 100 * time.Millisecond,
119 Max: 60000 * time.Millisecond,
120 Multiplier: 1.30,
121 })
122 }),
123 },
124 ImportSshPublicKey: []gax.CallOption{
125 gax.WithTimeout(10000 * time.Millisecond),
126 gax.WithRetry(func() gax.Retryer {
127 return gax.OnCodes([]codes.Code{
128 codes.Unavailable,
129 codes.DeadlineExceeded,
130 }, gax.Backoff{
131 Initial: 100 * time.Millisecond,
132 Max: 60000 * time.Millisecond,
133 Multiplier: 1.30,
134 })
135 }),
136 },
137 UpdateSshPublicKey: []gax.CallOption{
138 gax.WithTimeout(10000 * time.Millisecond),
139 gax.WithRetry(func() gax.Retryer {
140 return gax.OnCodes([]codes.Code{
141 codes.Unavailable,
142 codes.DeadlineExceeded,
143 }, gax.Backoff{
144 Initial: 100 * time.Millisecond,
145 Max: 60000 * time.Millisecond,
146 Multiplier: 1.30,
147 })
148 }),
149 },
150 }
151 }
152
153 func defaultRESTCallOptions() *CallOptions {
154 return &CallOptions{
155 CreateSshPublicKey: []gax.CallOption{},
156 DeletePosixAccount: []gax.CallOption{
157 gax.WithTimeout(10000 * time.Millisecond),
158 gax.WithRetry(func() gax.Retryer {
159 return gax.OnHTTPCodes(gax.Backoff{
160 Initial: 100 * time.Millisecond,
161 Max: 60000 * time.Millisecond,
162 Multiplier: 1.30,
163 },
164 http.StatusServiceUnavailable,
165 http.StatusGatewayTimeout)
166 }),
167 },
168 DeleteSshPublicKey: []gax.CallOption{
169 gax.WithTimeout(10000 * time.Millisecond),
170 gax.WithRetry(func() gax.Retryer {
171 return gax.OnHTTPCodes(gax.Backoff{
172 Initial: 100 * time.Millisecond,
173 Max: 60000 * time.Millisecond,
174 Multiplier: 1.30,
175 },
176 http.StatusServiceUnavailable,
177 http.StatusGatewayTimeout)
178 }),
179 },
180 GetLoginProfile: []gax.CallOption{
181 gax.WithTimeout(10000 * time.Millisecond),
182 gax.WithRetry(func() gax.Retryer {
183 return gax.OnHTTPCodes(gax.Backoff{
184 Initial: 100 * time.Millisecond,
185 Max: 60000 * time.Millisecond,
186 Multiplier: 1.30,
187 },
188 http.StatusServiceUnavailable,
189 http.StatusGatewayTimeout)
190 }),
191 },
192 GetSshPublicKey: []gax.CallOption{
193 gax.WithTimeout(10000 * time.Millisecond),
194 gax.WithRetry(func() gax.Retryer {
195 return gax.OnHTTPCodes(gax.Backoff{
196 Initial: 100 * time.Millisecond,
197 Max: 60000 * time.Millisecond,
198 Multiplier: 1.30,
199 },
200 http.StatusServiceUnavailable,
201 http.StatusGatewayTimeout)
202 }),
203 },
204 ImportSshPublicKey: []gax.CallOption{
205 gax.WithTimeout(10000 * time.Millisecond),
206 gax.WithRetry(func() gax.Retryer {
207 return gax.OnHTTPCodes(gax.Backoff{
208 Initial: 100 * time.Millisecond,
209 Max: 60000 * time.Millisecond,
210 Multiplier: 1.30,
211 },
212 http.StatusServiceUnavailable,
213 http.StatusGatewayTimeout)
214 }),
215 },
216 UpdateSshPublicKey: []gax.CallOption{
217 gax.WithTimeout(10000 * time.Millisecond),
218 gax.WithRetry(func() gax.Retryer {
219 return gax.OnHTTPCodes(gax.Backoff{
220 Initial: 100 * time.Millisecond,
221 Max: 60000 * time.Millisecond,
222 Multiplier: 1.30,
223 },
224 http.StatusServiceUnavailable,
225 http.StatusGatewayTimeout)
226 }),
227 },
228 }
229 }
230
231 // internalClient is an interface that defines the methods available from Cloud OS Login API.
232 type internalClient interface {
233 Close() error
234 setGoogleClientInfo(...string)
235 Connection() *grpc.ClientConn
236 CreateSshPublicKey(context.Context, *osloginpb.CreateSshPublicKeyRequest, ...gax.CallOption) (*commonpb.SshPublicKey, error)
237 DeletePosixAccount(context.Context, *osloginpb.DeletePosixAccountRequest, ...gax.CallOption) error
238 DeleteSshPublicKey(context.Context, *osloginpb.DeleteSshPublicKeyRequest, ...gax.CallOption) error
239 GetLoginProfile(context.Context, *osloginpb.GetLoginProfileRequest, ...gax.CallOption) (*osloginpb.LoginProfile, error)
240 GetSshPublicKey(context.Context, *osloginpb.GetSshPublicKeyRequest, ...gax.CallOption) (*commonpb.SshPublicKey, error)
241 ImportSshPublicKey(context.Context, *osloginpb.ImportSshPublicKeyRequest, ...gax.CallOption) (*osloginpb.ImportSshPublicKeyResponse, error)
242 UpdateSshPublicKey(context.Context, *osloginpb.UpdateSshPublicKeyRequest, ...gax.CallOption) (*commonpb.SshPublicKey, error)
243 }
244
245 // Client is a client for interacting with Cloud OS Login API.
246 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
247 //
248 // # Cloud OS Login API
249 //
250 // The Cloud OS Login API allows you to manage users and their associated SSH
251 // public keys for logging into virtual machines on Google Cloud Platform.
252 type Client struct {
253 // The internal transport-dependent client.
254 internalClient internalClient
255
256 // The call options for this service.
257 CallOptions *CallOptions
258 }
259
260 // Wrapper methods routed to the internal client.
261
262 // Close closes the connection to the API service. The user should invoke this when
263 // the client is no longer required.
264 func (c *Client) Close() error {
265 return c.internalClient.Close()
266 }
267
268 // setGoogleClientInfo sets the name and version of the application in
269 // the `x-goog-api-client` header passed on each request. Intended for
270 // use by Google-written clients.
271 func (c *Client) setGoogleClientInfo(keyval ...string) {
272 c.internalClient.setGoogleClientInfo(keyval...)
273 }
274
275 // Connection returns a connection to the API service.
276 //
277 // Deprecated: Connections are now pooled so this method does not always
278 // return the same resource.
279 func (c *Client) Connection() *grpc.ClientConn {
280 return c.internalClient.Connection()
281 }
282
283 // CreateSshPublicKey create an SSH public key
284 func (c *Client) CreateSshPublicKey(ctx context.Context, req *osloginpb.CreateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
285 return c.internalClient.CreateSshPublicKey(ctx, req, opts...)
286 }
287
288 // DeletePosixAccount deletes a POSIX account.
289 func (c *Client) DeletePosixAccount(ctx context.Context, req *osloginpb.DeletePosixAccountRequest, opts ...gax.CallOption) error {
290 return c.internalClient.DeletePosixAccount(ctx, req, opts...)
291 }
292
293 // DeleteSshPublicKey deletes an SSH public key.
294 func (c *Client) DeleteSshPublicKey(ctx context.Context, req *osloginpb.DeleteSshPublicKeyRequest, opts ...gax.CallOption) error {
295 return c.internalClient.DeleteSshPublicKey(ctx, req, opts...)
296 }
297
298 // GetLoginProfile retrieves the profile information used for logging in to a virtual machine
299 // on Google Compute Engine.
300 func (c *Client) GetLoginProfile(ctx context.Context, req *osloginpb.GetLoginProfileRequest, opts ...gax.CallOption) (*osloginpb.LoginProfile, error) {
301 return c.internalClient.GetLoginProfile(ctx, req, opts...)
302 }
303
304 // GetSshPublicKey retrieves an SSH public key.
305 func (c *Client) GetSshPublicKey(ctx context.Context, req *osloginpb.GetSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
306 return c.internalClient.GetSshPublicKey(ctx, req, opts...)
307 }
308
309 // ImportSshPublicKey adds an SSH public key and returns the profile information. Default POSIX
310 // account information is set when no username and UID exist as part of the
311 // login profile.
312 func (c *Client) ImportSshPublicKey(ctx context.Context, req *osloginpb.ImportSshPublicKeyRequest, opts ...gax.CallOption) (*osloginpb.ImportSshPublicKeyResponse, error) {
313 return c.internalClient.ImportSshPublicKey(ctx, req, opts...)
314 }
315
316 // UpdateSshPublicKey updates an SSH public key and returns the profile information. This method
317 // supports patch semantics.
318 func (c *Client) UpdateSshPublicKey(ctx context.Context, req *osloginpb.UpdateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
319 return c.internalClient.UpdateSshPublicKey(ctx, req, opts...)
320 }
321
322 // gRPCClient is a client for interacting with Cloud OS Login API over gRPC transport.
323 //
324 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
325 type gRPCClient struct {
326 // Connection pool of gRPC connections to the service.
327 connPool gtransport.ConnPool
328
329 // Points back to the CallOptions field of the containing Client
330 CallOptions **CallOptions
331
332 // The gRPC API client.
333 client osloginpb.OsLoginServiceClient
334
335 // The x-goog-* metadata to be sent with each request.
336 xGoogHeaders []string
337
338 logger *slog.Logger
339 }
340
341 // NewClient creates a new os login service client based on gRPC.
342 // The returned client must be Closed when it is done being used to clean up its underlying connections.
343 //
344 // # Cloud OS Login API
345 //
346 // The Cloud OS Login API allows you to manage users and their associated SSH
347 // public keys for logging into virtual machines on Google Cloud Platform.
348 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
349 clientOpts := defaultGRPCClientOptions()
350 if newClientHook != nil {
351 hookOpts, err := newClientHook(ctx, clientHookParams{})
352 if err != nil {
353 return nil, err
354 }
355 clientOpts = append(clientOpts, hookOpts...)
356 }
357
358 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
359 if err != nil {
360 return nil, err
361 }
362 client := Client{CallOptions: defaultCallOptions()}
363
364 c := &gRPCClient{
365 connPool: connPool,
366 client: osloginpb.NewOsLoginServiceClient(connPool),
367 CallOptions: &client.CallOptions,
368 logger: internaloption.GetLogger(opts),
369 }
370 c.setGoogleClientInfo()
371
372 client.internalClient = c
373
374 return &client, nil
375 }
376
377 // Connection returns a connection to the API service.
378 //
379 // Deprecated: Connections are now pooled so this method does not always
380 // return the same resource.
381 func (c *gRPCClient) Connection() *grpc.ClientConn {
382 return c.connPool.Conn()
383 }
384
385 // setGoogleClientInfo sets the name and version of the application in
386 // the `x-goog-api-client` header passed on each request. Intended for
387 // use by Google-written clients.
388 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
389 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
390 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
391 c.xGoogHeaders = []string{
392 "x-goog-api-client", gax.XGoogHeader(kv...),
393 }
394 }
395
396 // Close closes the connection to the API service. The user should invoke this when
397 // the client is no longer required.
398 func (c *gRPCClient) Close() error {
399 return c.connPool.Close()
400 }
401
402 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
403 type restClient struct {
404 // The http endpoint to connect to.
405 endpoint string
406
407 // The http client.
408 httpClient *http.Client
409
410 // The x-goog-* headers to be sent with each request.
411 xGoogHeaders []string
412
413 // Points back to the CallOptions field of the containing Client
414 CallOptions **CallOptions
415
416 logger *slog.Logger
417 }
418
419 // NewRESTClient creates a new os login service rest client.
420 //
421 // # Cloud OS Login API
422 //
423 // The Cloud OS Login API allows you to manage users and their associated SSH
424 // public keys for logging into virtual machines on Google Cloud Platform.
425 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
426 clientOpts := append(defaultRESTClientOptions(), opts...)
427 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
428 if err != nil {
429 return nil, err
430 }
431
432 callOpts := defaultRESTCallOptions()
433 c := &restClient{
434 endpoint: endpoint,
435 httpClient: httpClient,
436 CallOptions: &callOpts,
437 logger: internaloption.GetLogger(opts),
438 }
439 c.setGoogleClientInfo()
440
441 return &Client{internalClient: c, CallOptions: callOpts}, nil
442 }
443
444 func defaultRESTClientOptions() []option.ClientOption {
445 return []option.ClientOption{
446 internaloption.WithDefaultEndpoint("https://oslogin.googleapis.com"),
447 internaloption.WithDefaultEndpointTemplate("https://oslogin.UNIVERSE_DOMAIN"),
448 internaloption.WithDefaultMTLSEndpoint("https://oslogin.mtls.googleapis.com"),
449 internaloption.WithDefaultUniverseDomain("googleapis.com"),
450 internaloption.WithDefaultAudience("https://oslogin.googleapis.com/"),
451 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
452 internaloption.EnableNewAuthLibrary(),
453 }
454 }
455
456 // setGoogleClientInfo sets the name and version of the application in
457 // the `x-goog-api-client` header passed on each request. Intended for
458 // use by Google-written clients.
459 func (c *restClient) setGoogleClientInfo(keyval ...string) {
460 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
461 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
462 c.xGoogHeaders = []string{
463 "x-goog-api-client", gax.XGoogHeader(kv...),
464 }
465 }
466
467 // Close closes the connection to the API service. The user should invoke this when
468 // the client is no longer required.
469 func (c *restClient) Close() error {
470 // Replace httpClient with nil to force cleanup.
471 c.httpClient = nil
472 return nil
473 }
474
475 // Connection returns a connection to the API service.
476 //
477 // Deprecated: This method always returns nil.
478 func (c *restClient) Connection() *grpc.ClientConn {
479 return nil
480 }
481 func (c *gRPCClient) CreateSshPublicKey(ctx context.Context, req *osloginpb.CreateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
482 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
483
484 hds = append(c.xGoogHeaders, hds...)
485 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
486 opts = append((*c.CallOptions).CreateSshPublicKey[0:len((*c.CallOptions).CreateSshPublicKey):len((*c.CallOptions).CreateSshPublicKey)], opts...)
487 var resp *commonpb.SshPublicKey
488 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
489 var err error
490 resp, err = executeRPC(ctx, c.client.CreateSshPublicKey, req, settings.GRPC, c.logger, "CreateSshPublicKey")
491 return err
492 }, opts...)
493 if err != nil {
494 return nil, err
495 }
496 return resp, nil
497 }
498
499 func (c *gRPCClient) DeletePosixAccount(ctx context.Context, req *osloginpb.DeletePosixAccountRequest, opts ...gax.CallOption) error {
500 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
501
502 hds = append(c.xGoogHeaders, hds...)
503 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
504 opts = append((*c.CallOptions).DeletePosixAccount[0:len((*c.CallOptions).DeletePosixAccount):len((*c.CallOptions).DeletePosixAccount)], opts...)
505 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
506 var err error
507 _, err = executeRPC(ctx, c.client.DeletePosixAccount, req, settings.GRPC, c.logger, "DeletePosixAccount")
508 return err
509 }, opts...)
510 return err
511 }
512
513 func (c *gRPCClient) DeleteSshPublicKey(ctx context.Context, req *osloginpb.DeleteSshPublicKeyRequest, opts ...gax.CallOption) error {
514 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
515
516 hds = append(c.xGoogHeaders, hds...)
517 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
518 opts = append((*c.CallOptions).DeleteSshPublicKey[0:len((*c.CallOptions).DeleteSshPublicKey):len((*c.CallOptions).DeleteSshPublicKey)], opts...)
519 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
520 var err error
521 _, err = executeRPC(ctx, c.client.DeleteSshPublicKey, req, settings.GRPC, c.logger, "DeleteSshPublicKey")
522 return err
523 }, opts...)
524 return err
525 }
526
527 func (c *gRPCClient) GetLoginProfile(ctx context.Context, req *osloginpb.GetLoginProfileRequest, opts ...gax.CallOption) (*osloginpb.LoginProfile, error) {
528 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
529
530 hds = append(c.xGoogHeaders, hds...)
531 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
532 opts = append((*c.CallOptions).GetLoginProfile[0:len((*c.CallOptions).GetLoginProfile):len((*c.CallOptions).GetLoginProfile)], opts...)
533 var resp *osloginpb.LoginProfile
534 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
535 var err error
536 resp, err = executeRPC(ctx, c.client.GetLoginProfile, req, settings.GRPC, c.logger, "GetLoginProfile")
537 return err
538 }, opts...)
539 if err != nil {
540 return nil, err
541 }
542 return resp, nil
543 }
544
545 func (c *gRPCClient) GetSshPublicKey(ctx context.Context, req *osloginpb.GetSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
546 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
547
548 hds = append(c.xGoogHeaders, hds...)
549 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
550 opts = append((*c.CallOptions).GetSshPublicKey[0:len((*c.CallOptions).GetSshPublicKey):len((*c.CallOptions).GetSshPublicKey)], opts...)
551 var resp *commonpb.SshPublicKey
552 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
553 var err error
554 resp, err = executeRPC(ctx, c.client.GetSshPublicKey, req, settings.GRPC, c.logger, "GetSshPublicKey")
555 return err
556 }, opts...)
557 if err != nil {
558 return nil, err
559 }
560 return resp, nil
561 }
562
563 func (c *gRPCClient) ImportSshPublicKey(ctx context.Context, req *osloginpb.ImportSshPublicKeyRequest, opts ...gax.CallOption) (*osloginpb.ImportSshPublicKeyResponse, error) {
564 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
565
566 hds = append(c.xGoogHeaders, hds...)
567 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
568 opts = append((*c.CallOptions).ImportSshPublicKey[0:len((*c.CallOptions).ImportSshPublicKey):len((*c.CallOptions).ImportSshPublicKey)], opts...)
569 var resp *osloginpb.ImportSshPublicKeyResponse
570 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
571 var err error
572 resp, err = executeRPC(ctx, c.client.ImportSshPublicKey, req, settings.GRPC, c.logger, "ImportSshPublicKey")
573 return err
574 }, opts...)
575 if err != nil {
576 return nil, err
577 }
578 return resp, nil
579 }
580
581 func (c *gRPCClient) UpdateSshPublicKey(ctx context.Context, req *osloginpb.UpdateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
582 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
583
584 hds = append(c.xGoogHeaders, hds...)
585 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
586 opts = append((*c.CallOptions).UpdateSshPublicKey[0:len((*c.CallOptions).UpdateSshPublicKey):len((*c.CallOptions).UpdateSshPublicKey)], opts...)
587 var resp *commonpb.SshPublicKey
588 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
589 var err error
590 resp, err = executeRPC(ctx, c.client.UpdateSshPublicKey, req, settings.GRPC, c.logger, "UpdateSshPublicKey")
591 return err
592 }, opts...)
593 if err != nil {
594 return nil, err
595 }
596 return resp, nil
597 }
598
599 // CreateSshPublicKey create an SSH public key
600 func (c *restClient) CreateSshPublicKey(ctx context.Context, req *osloginpb.CreateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
601 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
602 body := req.GetSshPublicKey()
603 jsonReq, err := m.Marshal(body)
604 if err != nil {
605 return nil, err
606 }
607
608 baseUrl, err := url.Parse(c.endpoint)
609 if err != nil {
610 return nil, err
611 }
612 baseUrl.Path += fmt.Sprintf("/v1/%v/sshPublicKeys", req.GetParent())
613
614 params := url.Values{}
615 params.Add("$alt", "json;enum-encoding=int")
616
617 baseUrl.RawQuery = params.Encode()
618
619 // Build HTTP headers from client and context metadata.
620 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
621
622 hds = append(c.xGoogHeaders, hds...)
623 hds = append(hds, "Content-Type", "application/json")
624 headers := gax.BuildHeaders(ctx, hds...)
625 opts = append((*c.CallOptions).CreateSshPublicKey[0:len((*c.CallOptions).CreateSshPublicKey):len((*c.CallOptions).CreateSshPublicKey)], opts...)
626 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
627 resp := &commonpb.SshPublicKey{}
628 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
629 if settings.Path != "" {
630 baseUrl.Path = settings.Path
631 }
632 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
633 if err != nil {
634 return err
635 }
636 httpReq = httpReq.WithContext(ctx)
637 httpReq.Header = headers
638
639 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateSshPublicKey")
640 if err != nil {
641 return err
642 }
643
644 if err := unm.Unmarshal(buf, resp); err != nil {
645 return err
646 }
647
648 return nil
649 }, opts...)
650 if e != nil {
651 return nil, e
652 }
653 return resp, nil
654 }
655
656 // DeletePosixAccount deletes a POSIX account.
657 func (c *restClient) DeletePosixAccount(ctx context.Context, req *osloginpb.DeletePosixAccountRequest, opts ...gax.CallOption) error {
658 baseUrl, err := url.Parse(c.endpoint)
659 if err != nil {
660 return err
661 }
662 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
663
664 params := url.Values{}
665 params.Add("$alt", "json;enum-encoding=int")
666
667 baseUrl.RawQuery = params.Encode()
668
669 // Build HTTP headers from client and context metadata.
670 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
671
672 hds = append(c.xGoogHeaders, hds...)
673 hds = append(hds, "Content-Type", "application/json")
674 headers := gax.BuildHeaders(ctx, hds...)
675 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
676 if settings.Path != "" {
677 baseUrl.Path = settings.Path
678 }
679 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
680 if err != nil {
681 return err
682 }
683 httpReq = httpReq.WithContext(ctx)
684 httpReq.Header = headers
685
686 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeletePosixAccount")
687 return err
688 }, opts...)
689 }
690
691 // DeleteSshPublicKey deletes an SSH public key.
692 func (c *restClient) DeleteSshPublicKey(ctx context.Context, req *osloginpb.DeleteSshPublicKeyRequest, opts ...gax.CallOption) error {
693 baseUrl, err := url.Parse(c.endpoint)
694 if err != nil {
695 return err
696 }
697 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
698
699 params := url.Values{}
700 params.Add("$alt", "json;enum-encoding=int")
701
702 baseUrl.RawQuery = params.Encode()
703
704 // Build HTTP headers from client and context metadata.
705 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
706
707 hds = append(c.xGoogHeaders, hds...)
708 hds = append(hds, "Content-Type", "application/json")
709 headers := gax.BuildHeaders(ctx, hds...)
710 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
711 if settings.Path != "" {
712 baseUrl.Path = settings.Path
713 }
714 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
715 if err != nil {
716 return err
717 }
718 httpReq = httpReq.WithContext(ctx)
719 httpReq.Header = headers
720
721 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteSshPublicKey")
722 return err
723 }, opts...)
724 }
725
726 // GetLoginProfile retrieves the profile information used for logging in to a virtual machine
727 // on Google Compute Engine.
728 func (c *restClient) GetLoginProfile(ctx context.Context, req *osloginpb.GetLoginProfileRequest, opts ...gax.CallOption) (*osloginpb.LoginProfile, error) {
729 baseUrl, err := url.Parse(c.endpoint)
730 if err != nil {
731 return nil, err
732 }
733 baseUrl.Path += fmt.Sprintf("/v1/%v/loginProfile", req.GetName())
734
735 params := url.Values{}
736 params.Add("$alt", "json;enum-encoding=int")
737 if req.GetProjectId() != "" {
738 params.Add("projectId", fmt.Sprintf("%v", req.GetProjectId()))
739 }
740 if req.GetSystemId() != "" {
741 params.Add("systemId", fmt.Sprintf("%v", req.GetSystemId()))
742 }
743
744 baseUrl.RawQuery = params.Encode()
745
746 // Build HTTP headers from client and context metadata.
747 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
748
749 hds = append(c.xGoogHeaders, hds...)
750 hds = append(hds, "Content-Type", "application/json")
751 headers := gax.BuildHeaders(ctx, hds...)
752 opts = append((*c.CallOptions).GetLoginProfile[0:len((*c.CallOptions).GetLoginProfile):len((*c.CallOptions).GetLoginProfile)], opts...)
753 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
754 resp := &osloginpb.LoginProfile{}
755 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
756 if settings.Path != "" {
757 baseUrl.Path = settings.Path
758 }
759 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
760 if err != nil {
761 return err
762 }
763 httpReq = httpReq.WithContext(ctx)
764 httpReq.Header = headers
765
766 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLoginProfile")
767 if err != nil {
768 return err
769 }
770
771 if err := unm.Unmarshal(buf, resp); err != nil {
772 return err
773 }
774
775 return nil
776 }, opts...)
777 if e != nil {
778 return nil, e
779 }
780 return resp, nil
781 }
782
783 // GetSshPublicKey retrieves an SSH public key.
784 func (c *restClient) GetSshPublicKey(ctx context.Context, req *osloginpb.GetSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
785 baseUrl, err := url.Parse(c.endpoint)
786 if err != nil {
787 return nil, err
788 }
789 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
790
791 params := url.Values{}
792 params.Add("$alt", "json;enum-encoding=int")
793
794 baseUrl.RawQuery = params.Encode()
795
796 // Build HTTP headers from client and context metadata.
797 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
798
799 hds = append(c.xGoogHeaders, hds...)
800 hds = append(hds, "Content-Type", "application/json")
801 headers := gax.BuildHeaders(ctx, hds...)
802 opts = append((*c.CallOptions).GetSshPublicKey[0:len((*c.CallOptions).GetSshPublicKey):len((*c.CallOptions).GetSshPublicKey)], opts...)
803 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
804 resp := &commonpb.SshPublicKey{}
805 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
806 if settings.Path != "" {
807 baseUrl.Path = settings.Path
808 }
809 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
810 if err != nil {
811 return err
812 }
813 httpReq = httpReq.WithContext(ctx)
814 httpReq.Header = headers
815
816 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetSshPublicKey")
817 if err != nil {
818 return err
819 }
820
821 if err := unm.Unmarshal(buf, resp); err != nil {
822 return err
823 }
824
825 return nil
826 }, opts...)
827 if e != nil {
828 return nil, e
829 }
830 return resp, nil
831 }
832
833 // ImportSshPublicKey adds an SSH public key and returns the profile information. Default POSIX
834 // account information is set when no username and UID exist as part of the
835 // login profile.
836 func (c *restClient) ImportSshPublicKey(ctx context.Context, req *osloginpb.ImportSshPublicKeyRequest, opts ...gax.CallOption) (*osloginpb.ImportSshPublicKeyResponse, error) {
837 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
838 body := req.GetSshPublicKey()
839 jsonReq, err := m.Marshal(body)
840 if err != nil {
841 return nil, err
842 }
843
844 baseUrl, err := url.Parse(c.endpoint)
845 if err != nil {
846 return nil, err
847 }
848 baseUrl.Path += fmt.Sprintf("/v1/%v:importSshPublicKey", req.GetParent())
849
850 params := url.Values{}
851 params.Add("$alt", "json;enum-encoding=int")
852 if req.GetProjectId() != "" {
853 params.Add("projectId", fmt.Sprintf("%v", req.GetProjectId()))
854 }
855 if items := req.GetRegions(); len(items) > 0 {
856 for _, item := range items {
857 params.Add("regions", fmt.Sprintf("%v", item))
858 }
859 }
860
861 baseUrl.RawQuery = params.Encode()
862
863 // Build HTTP headers from client and context metadata.
864 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
865
866 hds = append(c.xGoogHeaders, hds...)
867 hds = append(hds, "Content-Type", "application/json")
868 headers := gax.BuildHeaders(ctx, hds...)
869 opts = append((*c.CallOptions).ImportSshPublicKey[0:len((*c.CallOptions).ImportSshPublicKey):len((*c.CallOptions).ImportSshPublicKey)], opts...)
870 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
871 resp := &osloginpb.ImportSshPublicKeyResponse{}
872 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
873 if settings.Path != "" {
874 baseUrl.Path = settings.Path
875 }
876 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
877 if err != nil {
878 return err
879 }
880 httpReq = httpReq.WithContext(ctx)
881 httpReq.Header = headers
882
883 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportSshPublicKey")
884 if err != nil {
885 return err
886 }
887
888 if err := unm.Unmarshal(buf, resp); err != nil {
889 return err
890 }
891
892 return nil
893 }, opts...)
894 if e != nil {
895 return nil, e
896 }
897 return resp, nil
898 }
899
900 // UpdateSshPublicKey updates an SSH public key and returns the profile information. This method
901 // supports patch semantics.
902 func (c *restClient) UpdateSshPublicKey(ctx context.Context, req *osloginpb.UpdateSshPublicKeyRequest, opts ...gax.CallOption) (*commonpb.SshPublicKey, error) {
903 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
904 body := req.GetSshPublicKey()
905 jsonReq, err := m.Marshal(body)
906 if err != nil {
907 return nil, err
908 }
909
910 baseUrl, err := url.Parse(c.endpoint)
911 if err != nil {
912 return nil, err
913 }
914 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
915
916 params := url.Values{}
917 params.Add("$alt", "json;enum-encoding=int")
918 if req.GetUpdateMask() != nil {
919 field, err := protojson.Marshal(req.GetUpdateMask())
920 if err != nil {
921 return nil, err
922 }
923 params.Add("updateMask", string(field[1:len(field)-1]))
924 }
925
926 baseUrl.RawQuery = params.Encode()
927
928 // Build HTTP headers from client and context metadata.
929 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
930
931 hds = append(c.xGoogHeaders, hds...)
932 hds = append(hds, "Content-Type", "application/json")
933 headers := gax.BuildHeaders(ctx, hds...)
934 opts = append((*c.CallOptions).UpdateSshPublicKey[0:len((*c.CallOptions).UpdateSshPublicKey):len((*c.CallOptions).UpdateSshPublicKey)], opts...)
935 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
936 resp := &commonpb.SshPublicKey{}
937 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
938 if settings.Path != "" {
939 baseUrl.Path = settings.Path
940 }
941 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
942 if err != nil {
943 return err
944 }
945 httpReq = httpReq.WithContext(ctx)
946 httpReq.Header = headers
947
948 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateSshPublicKey")
949 if err != nil {
950 return err
951 }
952
953 if err := unm.Unmarshal(buf, resp); err != nil {
954 return err
955 }
956
957 return nil
958 }, opts...)
959 if e != nil {
960 return nil, e
961 }
962 return resp, nil
963 }