Debian Codegraph @

talent/apiv4/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/apiv4/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 body := req.GetTenant()
539 jsonReq, err := m.Marshal(body)
540 if err != nil {
541 return nil, err
542 }
543
544 baseUrl, err := url.Parse(c.endpoint)
545 if err != nil {
546 return nil, err
547 }
548 baseUrl.Path += fmt.Sprintf("/v4/%v/tenants", req.GetParent())
549
550 params := url.Values{}
551 params.Add("$alt", "json;enum-encoding=int")
552
553 baseUrl.RawQuery = params.Encode()
554
555 // Build HTTP headers from client and context metadata.
556 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
557
558 hds = append(c.xGoogHeaders, hds...)
559 hds = append(hds, "Content-Type", "application/json")
560 headers := gax.BuildHeaders(ctx, hds...)
561 opts = append((*c.CallOptions).CreateTenant[0:len((*c.CallOptions).CreateTenant):len((*c.CallOptions).CreateTenant)], opts...)
562 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
563 resp := &talentpb.Tenant{}
564 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
565 if settings.Path != "" {
566 baseUrl.Path = settings.Path
567 }
568 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
569 if err != nil {
570 return err
571 }
572 httpReq = httpReq.WithContext(ctx)
573 httpReq.Header = headers
574
575 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateTenant")
576 if err != nil {
577 return err
578 }
579
580 if err := unm.Unmarshal(buf, resp); err != nil {
581 return err
582 }
583
584 return nil
585 }, opts...)
586 if e != nil {
587 return nil, e
588 }
589 return resp, nil
590 }
591
592 // GetTenant retrieves specified tenant.
593 func (c *tenantRESTClient) GetTenant(ctx context.Context, req *talentpb.GetTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
594 baseUrl, err := url.Parse(c.endpoint)
595 if err != nil {
596 return nil, err
597 }
598 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
599
600 params := url.Values{}
601 params.Add("$alt", "json;enum-encoding=int")
602
603 baseUrl.RawQuery = params.Encode()
604
605 // Build HTTP headers from client and context metadata.
606 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
607
608 hds = append(c.xGoogHeaders, hds...)
609 hds = append(hds, "Content-Type", "application/json")
610 headers := gax.BuildHeaders(ctx, hds...)
611 opts = append((*c.CallOptions).GetTenant[0:len((*c.CallOptions).GetTenant):len((*c.CallOptions).GetTenant)], opts...)
612 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
613 resp := &talentpb.Tenant{}
614 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
615 if settings.Path != "" {
616 baseUrl.Path = settings.Path
617 }
618 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
619 if err != nil {
620 return err
621 }
622 httpReq = httpReq.WithContext(ctx)
623 httpReq.Header = headers
624
625 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetTenant")
626 if err != nil {
627 return err
628 }
629
630 if err := unm.Unmarshal(buf, resp); err != nil {
631 return err
632 }
633
634 return nil
635 }, opts...)
636 if e != nil {
637 return nil, e
638 }
639 return resp, nil
640 }
641
642 // UpdateTenant updates specified tenant.
643 func (c *tenantRESTClient) UpdateTenant(ctx context.Context, req *talentpb.UpdateTenantRequest, opts ...gax.CallOption) (*talentpb.Tenant, error) {
644 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
645 body := req.GetTenant()
646 jsonReq, err := m.Marshal(body)
647 if err != nil {
648 return nil, err
649 }
650
651 baseUrl, err := url.Parse(c.endpoint)
652 if err != nil {
653 return nil, err
654 }
655 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetTenant().GetName())
656
657 params := url.Values{}
658 params.Add("$alt", "json;enum-encoding=int")
659 if req.GetUpdateMask() != nil {
660 field, err := protojson.Marshal(req.GetUpdateMask())
661 if err != nil {
662 return nil, err
663 }
664 params.Add("updateMask", string(field[1:len(field)-1]))
665 }
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", "tenant.name", url.QueryEscape(req.GetTenant().GetName()))}
671
672 hds = append(c.xGoogHeaders, hds...)
673 hds = append(hds, "Content-Type", "application/json")
674 headers := gax.BuildHeaders(ctx, hds...)
675 opts = append((*c.CallOptions).UpdateTenant[0:len((*c.CallOptions).UpdateTenant):len((*c.CallOptions).UpdateTenant)], opts...)
676 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
677 resp := &talentpb.Tenant{}
678 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
679 if settings.Path != "" {
680 baseUrl.Path = settings.Path
681 }
682 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
683 if err != nil {
684 return err
685 }
686 httpReq = httpReq.WithContext(ctx)
687 httpReq.Header = headers
688
689 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateTenant")
690 if err != nil {
691 return err
692 }
693
694 if err := unm.Unmarshal(buf, resp); err != nil {
695 return err
696 }
697
698 return nil
699 }, opts...)
700 if e != nil {
701 return nil, e
702 }
703 return resp, nil
704 }
705
706 // DeleteTenant deletes specified tenant.
707 func (c *tenantRESTClient) DeleteTenant(ctx context.Context, req *talentpb.DeleteTenantRequest, opts ...gax.CallOption) error {
708 baseUrl, err := url.Parse(c.endpoint)
709 if err != nil {
710 return err
711 }
712 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
713
714 params := url.Values{}
715 params.Add("$alt", "json;enum-encoding=int")
716
717 baseUrl.RawQuery = params.Encode()
718
719 // Build HTTP headers from client and context metadata.
720 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
721
722 hds = append(c.xGoogHeaders, hds...)
723 hds = append(hds, "Content-Type", "application/json")
724 headers := gax.BuildHeaders(ctx, hds...)
725 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
726 if settings.Path != "" {
727 baseUrl.Path = settings.Path
728 }
729 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
730 if err != nil {
731 return err
732 }
733 httpReq = httpReq.WithContext(ctx)
734 httpReq.Header = headers
735
736 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteTenant")
737 return err
738 }, opts...)
739 }
740
741 // ListTenants lists all tenants associated with the project.
742 func (c *tenantRESTClient) ListTenants(ctx context.Context, req *talentpb.ListTenantsRequest, opts ...gax.CallOption) *TenantIterator {
743 it := &TenantIterator{}
744 req = proto.Clone(req).(*talentpb.ListTenantsRequest)
745 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
746 it.InternalFetch = func(pageSize int, pageToken string) ([]*talentpb.Tenant, string, error) {
747 resp := &talentpb.ListTenantsResponse{}
748 if pageToken != "" {
749 req.PageToken = pageToken
750 }
751 if pageSize > math.MaxInt32 {
752 req.PageSize = math.MaxInt32
753 } else if pageSize != 0 {
754 req.PageSize = int32(pageSize)
755 }
756 baseUrl, err := url.Parse(c.endpoint)
757 if err != nil {
758 return nil, "", err
759 }
760 baseUrl.Path += fmt.Sprintf("/v4/%v/tenants", req.GetParent())
761
762 params := url.Values{}
763 params.Add("$alt", "json;enum-encoding=int")
764 if req.GetPageSize() != 0 {
765 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
766 }
767 if req.GetPageToken() != "" {
768 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
769 }
770
771 baseUrl.RawQuery = params.Encode()
772
773 // Build HTTP headers from client and context metadata.
774 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
775 headers := gax.BuildHeaders(ctx, hds...)
776 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
777 if settings.Path != "" {
778 baseUrl.Path = settings.Path
779 }
780 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
781 if err != nil {
782 return err
783 }
784 httpReq.Header = headers
785
786 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListTenants")
787 if err != nil {
788 return err
789 }
790 if err := unm.Unmarshal(buf, resp); err != nil {
791 return err
792 }
793
794 return nil
795 }, opts...)
796 if e != nil {
797 return nil, "", e
798 }
799 it.Response = resp
800 return resp.GetTenants(), resp.GetNextPageToken(), nil
801 }
802
803 fetch := func(pageSize int, pageToken string) (string, error) {
804 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
805 if err != nil {
806 return "", err
807 }
808 it.items = append(it.items, items...)
809 return nextPageToken, nil
810 }
811
812 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
813 it.pageInfo.MaxSize = int(req.GetPageSize())
814 it.pageInfo.Token = req.GetPageToken()
815
816 return it
817 }
818
819 // GetOperation is a utility method from google.longrunning.Operations.
820 func (c *tenantRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
821 baseUrl, err := url.Parse(c.endpoint)
822 if err != nil {
823 return nil, err
824 }
825 baseUrl.Path += fmt.Sprintf("/v4/%v", req.GetName())
826
827 params := url.Values{}
828 params.Add("$alt", "json;enum-encoding=int")
829
830 baseUrl.RawQuery = params.Encode()
831
832 // Build HTTP headers from client and context metadata.
833 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
834
835 hds = append(c.xGoogHeaders, hds...)
836 hds = append(hds, "Content-Type", "application/json")
837 headers := gax.BuildHeaders(ctx, hds...)
838 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
839 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
840 resp := &longrunningpb.Operation{}
841 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
842 if settings.Path != "" {
843 baseUrl.Path = settings.Path
844 }
845 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
846 if err != nil {
847 return err
848 }
849 httpReq = httpReq.WithContext(ctx)
850 httpReq.Header = headers
851
852 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
853 if err != nil {
854 return err
855 }
856
857 if err := unm.Unmarshal(buf, resp); err != nil {
858 return err
859 }
860
861 return nil
862 }, opts...)
863 if e != nil {
864 return nil, e
865 }
866 return resp, nil
867 }