Debian Codegraph @

talent/apiv4beta1/tenant_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 talent
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
30 talentpb "cloud.google.com/go/talent/apiv4beta1/talentpb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/grpc/codes"
39 "google.golang.org/protobuf/encoding/protojson"
40 "google.golang.org/protobuf/proto"
41 )
42
43 var newTenantClientHook clientHook
44
45 // TenantCallOptions contains the retry settings for each method of TenantClient.
46 type TenantCallOptions struct {
47 CreateTenant []gax.CallOption
48 GetTenant []gax.CallOption
49 UpdateTenant []gax.CallOption
50 DeleteTenant []gax.CallOption
51 ListTenants []gax.CallOption
52 GetOperation []gax.CallOption
53 }
54
55 func defaultTenantGRPCClientOptions() []option.ClientOption {
56 return []option.ClientOption{
57 internaloption.WithDefaultEndpoint("jobs.googleapis.com:443"),
58 internaloption.WithDefaultEndpointTemplate("jobs.UNIVERSE_DOMAIN:443"),
59 internaloption.WithDefaultMTLSEndpoint("jobs.mtls.googleapis.com:443"),
60 internaloption.WithDefaultUniverseDomain("googleapis.com"),
61 internaloption.WithDefaultAudience("https://jobs.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 defaultTenantCallOptions() *TenantCallOptions {
71 return &TenantCallOptions{
72 CreateTenant: []gax.CallOption{
73 gax.WithTimeout(30000 * time.Millisecond),
74 },
75 GetTenant: []gax.CallOption{
76 gax.WithTimeout(30000 * time.Millisecond),
77 gax.WithRetry(func() gax.Retryer {
78 return gax.OnCodes([]codes.Code{
79 codes.DeadlineExceeded,
80 codes.Unavailable,
81 }, gax.Backoff{
82 Initial: 100 * time.Millisecond,
83 Max: 60000 * time.Millisecond,
84 Multiplier: 1.30,
85 })
86 }),
87 },
88 UpdateTenant: []gax.CallOption{
89 gax.WithTimeout(30000 * time.Millisecond),
90 },
91 DeleteTenant: []gax.CallOption{
92 gax.WithTimeout(30000 * time.Millisecond),
93 gax.WithRetry(func() gax.Retryer {
94 return gax.OnCodes([]codes.Code{
95 codes.DeadlineExceeded,
96 codes.Unavailable,
97 }, gax.Backoff{
98 Initial: 100 * time.Millisecond,
99 Max: 60000 * time.Millisecond,
100 Multiplier: 1.30,
101 })
102 }),
103 },
104 ListTenants: []gax.CallOption{
105 gax.WithTimeout(30000 * time.Millisecond),
106 gax.WithRetry(func() gax.Retryer {
107 return gax.OnCodes([]codes.Code{
108 codes.DeadlineExceeded,
109 codes.Unavailable,
110 }, gax.Backoff{
111 Initial: 100 * time.Millisecond,
112 Max: 60000 * time.Millisecond,
113 Multiplier: 1.30,
114 })
115 }),
116 },
117 GetOperation: []gax.CallOption{},
118 }
119 }
120
121 func defaultTenantRESTCallOptions() *TenantCallOptions {
122 return &TenantCallOptions{
123 CreateTenant: []gax.CallOption{
124 gax.WithTimeout(30000 * time.Millisecond),
125 },
126 GetTenant: []gax.CallOption{
127 gax.WithTimeout(30000 * time.Millisecond),
128 gax.WithRetry(func() gax.Retryer {
129 return gax.OnHTTPCodes(gax.Backoff{
130 Initial: 100 * time.Millisecond,
131 Max: 60000 * time.Millisecond,
132 Multiplier: 1.30,
133 },
134 http.StatusGatewayTimeout,
135 http.StatusServiceUnavailable)
136 }),
137 },
138 UpdateTenant: []gax.CallOption{
139 gax.WithTimeout(30000 * time.Millisecond),
140 },
141 DeleteTenant: []gax.CallOption{
142 gax.WithTimeout(30000 * time.Millisecond),
143 gax.WithRetry(func() gax.Retryer {
144 return gax.OnHTTPCodes(gax.Backoff{
145 Initial: 100 * time.Millisecond,
146 Max: 60000 * time.Millisecond,
147 Multiplier: 1.30,
148 },
149 http.StatusGatewayTimeout,
150 http.StatusServiceUnavailable)
151 }),
152 },
153 ListTenants: []gax.CallOption{
154 gax.WithTimeout(30000 * time.Millisecond),
155 gax.WithRetry(func() gax.Retryer {
156 return gax.OnHTTPCodes(gax.Backoff{
157 Initial: 100 * time.Millisecond,
158 Max: 60000 * time.Millisecond,
159 Multiplier: 1.30,
160 },
161 http.StatusGatewayTimeout,
162 http.StatusServiceUnavailable)
163 }),
164 },
165 GetOperation: []gax.CallOption{},
166 }
167 }
168
169 // internalTenantClient is an interface that defines the methods available from Cloud Talent Solution API.
170 type internalTenantClient interface {
171 Close() error
172 setGoogleClientInfo(...string)
173 Connection() *grpc.ClientConn
174 CreateTenant(context.Context, *talentpb.CreateTenantRequest, ...gax.CallOption) (*talentpb.Tenant, error)
175 GetTenant(context.Context, *talentpb.GetTenantRequest, ...gax.CallOption) (*talentpb.Tenant, error)
176 UpdateTenant(context.Context, *talentpb.UpdateTenantRequest, ...gax.CallOption) (*talentpb.Tenant, error)
177 DeleteTenant(context.Context, *talentpb.DeleteTenantRequest, ...gax.CallOption) error
178 ListTenants(context.Context, *talentpb.ListTenantsRequest, ...gax.CallOption) *TenantIterator
179 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
180 }
181
182 // TenantClient is a client for interacting with Cloud Talent Solution API.
183 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
184 //
185 // A service that handles tenant management, including CRUD and enumeration.
186 type TenantClient struct {
187 // The internal transport-dependent client.
188 internalClient internalTenantClient
189
190 // The call options for this service.
191 CallOptions *TenantCallOptions
192 }
193
194 // Wrapper methods routed to the internal client.
195
196 // Close closes the connection to the API service. The user should invoke this when
197 // the client is no longer required.
198 func (c *TenantClient) Close() error {
199 return c.internalClient.Close()
200 }
201
202 // setGoogleClientInfo sets the name and version of the application in
203 // the `x-goog-api-client` header passed on each request. Intended for
204 // use by Google-written clients.
205 func (c *TenantClient) setGoogleClientInfo(keyval ...string) {
206 c.internalClient.setGoogleClientInfo(keyval...)
207 }
208
209 // Connection returns a connection to the API service.
210 //
211 // Deprecated: Connections are now pooled so this method does not always
212 // return the same resource.
213 func (c *TenantClient) Connection() *grpc.ClientConn {
214 return c.internalClient.Connection()
215 }
216
217 // CreateTenant creates a new tenant entity.
218 func (c *TenantClient) CreateTenant(ctx context.Context, req *talentpb.CreateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
219 return c.internalClient.CreateTenant(ctx, req, opts...)
220 }
221
222 // GetTenant retrieves specified tenant.
223 func (c *TenantClient) GetTenant(ctx context.Context, req *talentpb.GetTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
224 return c.internalClient.GetTenant(ctx, req, opts...)
225 }
226
227 // UpdateTenant updates specified tenant.
228 func (c *TenantClient) UpdateTenant(ctx context.Context, req *talentpb.UpdateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
229 return c.internalClient.UpdateTenant(ctx, req, opts...)
230 }
231
232 // DeleteTenant deletes specified tenant.
233 func (c *TenantClient) DeleteTenant(ctx context.Context, req *talentpb.DeleteTenantRequest, opts ...gax.CallOption) error {
234 return c.internalClient.DeleteTenant(ctx, req, opts...)
235 }
236
237 // ListTenants lists all tenants associated with the project.
238 func (c *TenantClient) ListTenants(ctx context.Context, req *talentpb.ListTenantsRequest, opts ...gax.CallOption) *TenantIterator {
239 return c.internalClient.ListTenants(ctx, req, opts...)
240 }
241
242 // GetOperation is a utility method from google.longrunning.Operations.
243 func (c *TenantClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
244 return c.internalClient.GetOperation(ctx, req, opts...)
245 }
246
247 // tenantGRPCClient is a client for interacting with Cloud Talent Solution API over gRPC transport.
248 //
249 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
250 type tenantGRPCClient struct {
251 // Connection pool of gRPC connections to the service.
252 connPool gtransport.ConnPool
253
254 // Points back to the CallOptions field of the containing TenantClient
255 CallOptions **TenantCallOptions
256
257 // The gRPC API client.
258 tenantClient talentpb.TenantServiceClient
259
260 operationsClient longrunningpb.OperationsClient
261
262 // The x-goog-* metadata to be sent with each request.
263 xGoogHeaders []string
264
265 logger *slog.Logger
266 }
267
268 // NewTenantClient creates a new tenant service client based on gRPC.
269 // The returned client must be Closed when it is done being used to clean up its underlying connections.
270 //
271 // A service that handles tenant management, including CRUD and enumeration.
272 func NewTenantClient(ctx context.Context, opts ...option.ClientOption) (*TenantClient, error) {
273 clientOpts := defaultTenantGRPCClientOptions()
274 if newTenantClientHook != nil {
275 hookOpts, err := newTenantClientHook(ctx, clientHookParams{})
276 if err != nil {
277 return nil, err
278 }
279 clientOpts = append(clientOpts, hookOpts...)
280 }
281
282 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
283 if err != nil {
284 return nil, err
285 }
286 client := TenantClient{CallOptions: defaultTenantCallOptions()}
287
288 c := &tenantGRPCClient{
289 connPool: connPool,
290 tenantClient: talentpb.NewTenantServiceClient(connPool),
291 CallOptions: &client.CallOptions,
292 logger: internaloption.GetLogger(opts),
293 operationsClient: longrunningpb.NewOperationsClient(connPool),
294 }
295 c.setGoogleClientInfo()
296
297 client.internalClient = c
298
299 return &client, nil
300 }
301
302 // Connection returns a connection to the API service.
303 //
304 // Deprecated: Connections are now pooled so this method does not always
305 // return the same resource.
306 func (c *tenantGRPCClient) Connection() *grpc.ClientConn {
307 return c.connPool.Conn()
308 }
309
310 // setGoogleClientInfo sets the name and version of the application in
311 // the `x-goog-api-client` header passed on each request. Intended for
312 // use by Google-written clients.
313 func (c *tenantGRPCClient) setGoogleClientInfo(keyval ...string) {
314 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
315 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
316 c.xGoogHeaders = []string{
317 "x-goog-api-client", gax.XGoogHeader(kv...),
318 }
319 }
320
321 // Close closes the connection to the API service. The user should invoke this when
322 // the client is no longer required.
323 func (c *tenantGRPCClient) Close() error {
324 return c.connPool.Close()
325 }
326
327 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
328 type tenantRESTClient struct {
329 // The http endpoint to connect to.
330 endpoint string
331
332 // The http client.
333 httpClient *http.Client
334
335 // The x-goog-* headers to be sent with each request.
336 xGoogHeaders []string
337
338 // Points back to the CallOptions field of the containing TenantClient
339 CallOptions **TenantCallOptions
340
341 logger *slog.Logger
342 }
343
344 // NewTenantRESTClient creates a new tenant service rest client.
345 //
346 // A service that handles tenant management, including CRUD and enumeration.
347 func NewTenantRESTClient(ctx context.Context, opts ...option.ClientOption) (*TenantClient, error) {
348 clientOpts := append(defaultTenantRESTClientOptions(), opts...)
349 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
350 if err != nil {
351 return nil, err
352 }
353
354 callOpts := defaultTenantRESTCallOptions()
355 c := &tenantRESTClient{
356 endpoint: endpoint,
357 httpClient: httpClient,
358 CallOptions: &callOpts,
359 logger: internaloption.GetLogger(opts),
360 }
361 c.setGoogleClientInfo()
362
363 return &TenantClient{internalClient: c, CallOptions: callOpts}, nil
364 }
365
366 func defaultTenantRESTClientOptions() []option.ClientOption {
367 return []option.ClientOption{
368 internaloption.WithDefaultEndpoint("https://jobs.googleapis.com"),
369 internaloption.WithDefaultEndpointTemplate("https://jobs.UNIVERSE_DOMAIN"),
370 internaloption.WithDefaultMTLSEndpoint("https://jobs.mtls.googleapis.com"),
371 internaloption.WithDefaultUniverseDomain("googleapis.com"),
372 internaloption.WithDefaultAudience("https://jobs.googleapis.com/"),
373 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
374 internaloption.EnableNewAuthLibrary(),
375 }
376 }
377
378 // setGoogleClientInfo sets the name and version of the application in
379 // the `x-goog-api-client` header passed on each request. Intended for
380 // use by Google-written clients.
381 func (c *tenantRESTClient) setGoogleClientInfo(keyval ...string) {
382 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
383 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
384 c.xGoogHeaders = []string{
385 "x-goog-api-client", gax.XGoogHeader(kv...),
386 }
387 }
388
389 // Close closes the connection to the API service. The user should invoke this when
390 // the client is no longer required.
391 func (c *tenantRESTClient) Close() error {
392 // Replace httpClient with nil to force cleanup.
393 c.httpClient = nil
394 return nil
395 }
396
397 // Connection returns a connection to the API service.
398 //
399 // Deprecated: This method always returns nil.
400 func (c *tenantRESTClient) Connection() *grpc.ClientConn {
401 return nil
402 }
403 func (c *tenantGRPCClient) CreateTenant(ctx context.Context, req *talentpb.CreateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
404 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
405
406 hds = append(c.xGoogHeaders, hds...)
407 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
408 opts = append((*c.CallOptions).CreateTenant[0:len((*c.CallOptions).CreateTenant):len((*c.CallOptions).CreateTenant)], opts...)
409 var resp *talentpb.Tenant
410 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
411 var err error
412 resp, err = executeRPC(ctx, c.tenantClient.CreateTenant, req, settings.GRPC, c.logger, "CreateTenant")
413 return err
414 }, opts...)
415 if err != nil {
416 return nil, err
417 }
418 return resp, nil
419 }
420
421 func (c *tenantGRPCClient) GetTenant(ctx context.Context, req *talentpb.GetTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
422 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
423
424 hds = append(c.xGoogHeaders, hds...)
425 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
426 opts = append((*c.CallOptions).GetTenant[0:len((*c.CallOptions).GetTenant):len((*c.CallOptions).GetTenant)], opts...)
427 var resp *talentpb.Tenant
428 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
429 var err error
430 resp, err = executeRPC(ctx, c.tenantClient.GetTenant, req, settings.GRPC, c.logger, "GetTenant")
431 return err
432 }, opts...)
433 if err != nil {
434 return nil, err
435 }
436 return resp, nil
437 }
438
439 func (c *tenantGRPCClient) UpdateTenant(ctx context.Context, req *talentpb.UpdateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
440 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "tenant.name", url.QueryEscape(req.GetTenant().GetName()))}
441
442 hds = append(c.xGoogHeaders, hds...)
443 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
444 opts = append((*c.CallOptions).UpdateTenant[0:len((*c.CallOptions).UpdateTenant):len((*c.CallOptions).UpdateTenant)], opts...)
445 var resp *talentpb.Tenant
446 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
447 var err error
448 resp, err = executeRPC(ctx, c.tenantClient.UpdateTenant, req, settings.GRPC, c.logger, "UpdateTenant")
449 return err
450 }, opts...)
451 if err != nil {
452 return nil, err
453 }
454 return resp, nil
455 }
456
457 func (c *tenantGRPCClient) DeleteTenant(ctx context.Context, req *talentpb.DeleteTenantRequest, opts ...gax.CallOption) error {
458 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
459
460 hds = append(c.xGoogHeaders, hds...)
461 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
462 opts = append((*c.CallOptions).DeleteTenant[0:len((*c.CallOptions).DeleteTenant):len((*c.CallOptions).DeleteTenant)], opts...)
463 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
464 var err error
465 _, err = executeRPC(ctx, c.tenantClient.DeleteTenant, req, settings.GRPC, c.logger, "DeleteTenant")
466 return err
467 }, opts...)
468 return err
469 }
470
471 func (c *tenantGRPCClient) ListTenants(ctx context.Context, req *talentpb.ListTenantsRequest, opts ...gax.CallOption) *TenantIterator {
472 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
473
474 hds = append(c.xGoogHeaders, hds...)
475 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
476 opts = append((*c.CallOptions).ListTenants[0:len((*c.CallOptions).ListTenants):len((*c.CallOptions).ListTenants)], opts...)
477 it := &TenantIterator{}
478 req = proto.Clone(req).(*talentpb.ListTenantsRequest)
479 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Tenant, string, error) {
480 resp := &talentpb.ListTenantsResponse{}
481 if pageToken != "" {
482 req.PageToken = pageToken
483 }
484 if pageSize > math.MaxInt32 {
485 req.PageSize = math.MaxInt32
486 } else if pageSize != 0 {
487 req.PageSize = int32(pageSize)
488 }
489 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
490 var err error
491 resp, err = executeRPC(ctx, c.tenantClient.ListTenants, req, settings.GRPC, c.logger, "ListTenants")
492 return err
493 }, opts...)
494 if err != nil {
495 return nil, "", err
496 }
497
498 it.Response = resp
499 return resp.GetTenants(), resp.GetNextPageToken(), nil
500 }
501 fetch := func(pageSize int, pageToken string) (string, error) {
502 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
503 if err != nil {
504 return "", err
505 }
506 it.items = append(it.items, items...)
507 return nextPageToken, nil
508 }
509
510 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
511 it.pageInfo.MaxSize = int(req.GetPageSize())
512 it.pageInfo.Token = req.GetPageToken()
513
514 return it
515 }
516
517 func (c *tenantGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
518 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
519
520 hds = append(c.xGoogHeaders, hds...)
521 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
522 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
523 var resp *longrunningpb.Operation
524 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
525 var err error
526 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
527 return err
528 }, opts...)
529 if err != nil {
530 return nil, err
531 }
532 return resp, nil
533 }
534
535 // CreateTenant creates a new tenant entity.
536 func (c *tenantRESTClient) CreateTenant(ctx context.Context, req *talentpb.CreateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
537 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
538 jsonReq, err := m.Marshal(req)
539 if err != nil {
540 return nil, err
541 }
542
543 baseUrl, err := url.Parse(c.endpoint)
544 if err != nil {
545 return nil, err
546 }
547 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/tenants", req.GetParent())
548
549 params := url.Values{}
550 params.Add("$alt", "json;enum-encoding=int")
551
552 baseUrl.RawQuery = params.Encode()
553
554 // Build HTTP headers from client and context metadata.
555 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
556
557 hds = append(c.xGoogHeaders, hds...)
558 hds = append(hds, "Content-Type", "application/json")
559 headers := gax.BuildHeaders(ctx, hds...)
560 opts = append((*c.CallOptions).CreateTenant[0:len((*c.CallOptions).CreateTenant):len((*c.CallOptions).CreateTenant)], opts...)
561 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
562 resp := &talentpb.Tenant{}
563 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
564 if settings.Path != "" {
565 baseUrl.Path = settings.Path
566 }
567 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
568 if err != nil {
569 return err
570 }
571 httpReq = httpReq.WithContext(ctx)
572 httpReq.Header = headers
573
574 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTenant")
575 if err != nil {
576 return err
577 }
578
579 if err := unm.Unmarshal(buf, resp); err != nil {
580 return err
581 }
582
583 return nil
584 }, opts...)
585 if e != nil {
586 return nil, e
587 }
588 return resp, nil
589 }
590
591 // GetTenant retrieves specified tenant.
592 func (c *tenantRESTClient) GetTenant(ctx context.Context, req *talentpb.GetTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
593 baseUrl, err := url.Parse(c.endpoint)
594 if err != nil {
595 return nil, err
596 }
597 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName())
598
599 params := url.Values{}
600 params.Add("$alt", "json;enum-encoding=int")
601
602 baseUrl.RawQuery = params.Encode()
603
604 // Build HTTP headers from client and context metadata.
605 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
606
607 hds = append(c.xGoogHeaders, hds...)
608 hds = append(hds, "Content-Type", "application/json")
609 headers := gax.BuildHeaders(ctx, hds...)
610 opts = append((*c.CallOptions).GetTenant[0:len((*c.CallOptions).GetTenant):len((*c.CallOptions).GetTenant)], opts...)
611 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
612 resp := &talentpb.Tenant{}
613 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
614 if settings.Path != "" {
615 baseUrl.Path = settings.Path
616 }
617 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
618 if err != nil {
619 return err
620 }
621 httpReq = httpReq.WithContext(ctx)
622 httpReq.Header = headers
623
624 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTenant")
625 if err != nil {
626 return err
627 }
628
629 if err := unm.Unmarshal(buf, resp); err != nil {
630 return err
631 }
632
633 return nil
634 }, opts...)
635 if e != nil {
636 return nil, e
637 }
638 return resp, nil
639 }
640
641 // UpdateTenant updates specified tenant.
642 func (c *tenantRESTClient) UpdateTenant(ctx context.Context, req *talentpb.UpdateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
643 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
644 jsonReq, err := m.Marshal(req)
645 if err != nil {
646 return nil, err
647 }
648
649 baseUrl, err := url.Parse(c.endpoint)
650 if err != nil {
651 return nil, err
652 }
653 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetTenant().GetName())
654
655 params := url.Values{}
656 params.Add("$alt", "json;enum-encoding=int")
657
658 baseUrl.RawQuery = params.Encode()
659
660 // Build HTTP headers from client and context metadata.
661 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "tenant.name", url.QueryEscape(req.GetTenant().GetName()))}
662
663 hds = append(c.xGoogHeaders, hds...)
664 hds = append(hds, "Content-Type", "application/json")
665 headers := gax.BuildHeaders(ctx, hds...)
666 opts = append((*c.CallOptions).UpdateTenant[0:len((*c.CallOptions).UpdateTenant):len((*c.CallOptions).UpdateTenant)], opts...)
667 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
668 resp := &talentpb.Tenant{}
669 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
670 if settings.Path != "" {
671 baseUrl.Path = settings.Path
672 }
673 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
674 if err != nil {
675 return err
676 }
677 httpReq = httpReq.WithContext(ctx)
678 httpReq.Header = headers
679
680 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateTenant")
681 if err != nil {
682 return err
683 }
684
685 if err := unm.Unmarshal(buf, resp); err != nil {
686 return err
687 }
688
689 return nil
690 }, opts...)
691 if e != nil {
692 return nil, e
693 }
694 return resp, nil
695 }
696
697 // DeleteTenant deletes specified tenant.
698 func (c *tenantRESTClient) DeleteTenant(ctx context.Context, req *talentpb.DeleteTenantRequest, opts ...gax.CallOption) error {
699 baseUrl, err := url.Parse(c.endpoint)
700 if err != nil {
701 return err
702 }
703 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName())
704
705 params := url.Values{}
706 params.Add("$alt", "json;enum-encoding=int")
707
708 baseUrl.RawQuery = params.Encode()
709
710 // Build HTTP headers from client and context metadata.
711 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
712
713 hds = append(c.xGoogHeaders, hds...)
714 hds = append(hds, "Content-Type", "application/json")
715 headers := gax.BuildHeaders(ctx, hds...)
716 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
717 if settings.Path != "" {
718 baseUrl.Path = settings.Path
719 }
720 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
721 if err != nil {
722 return err
723 }
724 httpReq = httpReq.WithContext(ctx)
725 httpReq.Header = headers
726
727 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTenant")
728 return err
729 }, opts...)
730 }
731
732 // ListTenants lists all tenants associated with the project.
733 func (c *tenantRESTClient) ListTenants(ctx context.Context, req *talentpb.ListTenantsRequest, opts ...gax.CallOption) *TenantIterator {
734 it := &TenantIterator{}
735 req = proto.Clone(req).(*talentpb.ListTenantsRequest)
736 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
737 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Tenant, string, error) {
738 resp := &talentpb.ListTenantsResponse{}
739 if pageToken != "" {
740 req.PageToken = pageToken
741 }
742 if pageSize > math.MaxInt32 {
743 req.PageSize = math.MaxInt32
744 } else if pageSize != 0 {
745 req.PageSize = int32(pageSize)
746 }
747 baseUrl, err := url.Parse(c.endpoint)
748 if err != nil {
749 return nil, "", err
750 }
751 baseUrl.Path += fmt.Sprintf("/v4beta1/%v/tenants", req.GetParent())
752
753 params := url.Values{}
754 params.Add("$alt", "json;enum-encoding=int")
755 if req.GetPageSize() != 0 {
756 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
757 }
758 if req.GetPageToken() != "" {
759 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
760 }
761
762 baseUrl.RawQuery = params.Encode()
763
764 // Build HTTP headers from client and context metadata.
765 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
766 headers := gax.BuildHeaders(ctx, hds...)
767 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
768 if settings.Path != "" {
769 baseUrl.Path = settings.Path
770 }
771 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
772 if err != nil {
773 return err
774 }
775 httpReq.Header = headers
776
777 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTenants")
778 if err != nil {
779 return err
780 }
781 if err := unm.Unmarshal(buf, resp); err != nil {
782 return err
783 }
784
785 return nil
786 }, opts...)
787 if e != nil {
788 return nil, "", e
789 }
790 it.Response = resp
791 return resp.GetTenants(), resp.GetNextPageToken(), nil
792 }
793
794 fetch := func(pageSize int, pageToken string) (string, error) {
795 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
796 if err != nil {
797 return "", err
798 }
799 it.items = append(it.items, items...)
800 return nextPageToken, nil
801 }
802
803 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
804 it.pageInfo.MaxSize = int(req.GetPageSize())
805 it.pageInfo.Token = req.GetPageToken()
806
807 return it
808 }
809
810 // GetOperation is a utility method from google.longrunning.Operations.
811 func (c *tenantRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
812 baseUrl, err := url.Parse(c.endpoint)
813 if err != nil {
814 return nil, err
815 }
816 baseUrl.Path += fmt.Sprintf("/v4beta1/%v", req.GetName())
817
818 params := url.Values{}
819 params.Add("$alt", "json;enum-encoding=int")
820
821 baseUrl.RawQuery = params.Encode()
822
823 // Build HTTP headers from client and context metadata.
824 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
825
826 hds = append(c.xGoogHeaders, hds...)
827 hds = append(hds, "Content-Type", "application/json")
828 headers := gax.BuildHeaders(ctx, hds...)
829 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
830 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
831 resp := &longrunningpb.Operation{}
832 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
833 if settings.Path != "" {
834 baseUrl.Path = settings.Path
835 }
836 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
837 if err != nil {
838 return err
839 }
840 httpReq = httpReq.WithContext(ctx)
841 httpReq.Header = headers
842
843 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
844 if err != nil {
845 return err
846 }
847
848 if err := unm.Unmarshal(buf, resp); err != nil {
849 return err
850 }
851
852 return nil
853 }, opts...)
854 if e != nil {
855 return nil, e
856 }
857 return resp, nil
858 }