Debian Codegraph @

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