Debian Codegraph @

shopping/css/apiv1/account_labels_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 css
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 csspb "cloud.google.com/go/shopping/css/apiv1/csspb"
30 gax "github.com/googleapis/gax-go/v2"
31 "google.golang.org/api/iterator"
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 "google.golang.org/protobuf/proto"
40 )
41
42 var newAccountLabelsClientHook clientHook
43
44 // AccountLabelsCallOptions contains the retry settings for each method of AccountLabelsClient.
45 type AccountLabelsCallOptions struct {
46 ListAccountLabels []gax.CallOption
47 CreateAccountLabel []gax.CallOption
48 UpdateAccountLabel []gax.CallOption
49 DeleteAccountLabel []gax.CallOption
50 }
51
52 func defaultAccountLabelsGRPCClientOptions() []option.ClientOption {
53 return []option.ClientOption{
54 internaloption.WithDefaultEndpoint("css.googleapis.com:443"),
55 internaloption.WithDefaultEndpointTemplate("css.UNIVERSE_DOMAIN:443"),
56 internaloption.WithDefaultMTLSEndpoint("css.mtls.googleapis.com:443"),
57 internaloption.WithDefaultUniverseDomain("googleapis.com"),
58 internaloption.WithDefaultAudience("https://css.googleapis.com/"),
59 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
60 internaloption.EnableJwtWithScope(),
61 internaloption.EnableNewAuthLibrary(),
62 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
63 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
64 }
65 }
66
67 func defaultAccountLabelsCallOptions() *AccountLabelsCallOptions {
68 return &AccountLabelsCallOptions{
69 ListAccountLabels: []gax.CallOption{
70 gax.WithTimeout(60000 * time.Millisecond),
71 gax.WithRetry(func() gax.Retryer {
72 return gax.OnCodes([]codes.Code{
73 codes.Unavailable,
74 }, gax.Backoff{
75 Initial: 1000 * time.Millisecond,
76 Max: 10000 * time.Millisecond,
77 Multiplier: 1.30,
78 })
79 }),
80 },
81 CreateAccountLabel: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 },
84 UpdateAccountLabel: []gax.CallOption{
85 gax.WithTimeout(60000 * time.Millisecond),
86 },
87 DeleteAccountLabel: []gax.CallOption{
88 gax.WithTimeout(60000 * time.Millisecond),
89 },
90 }
91 }
92
93 func defaultAccountLabelsRESTCallOptions() *AccountLabelsCallOptions {
94 return &AccountLabelsCallOptions{
95 ListAccountLabels: []gax.CallOption{
96 gax.WithTimeout(60000 * time.Millisecond),
97 gax.WithRetry(func() gax.Retryer {
98 return gax.OnHTTPCodes(gax.Backoff{
99 Initial: 1000 * time.Millisecond,
100 Max: 10000 * time.Millisecond,
101 Multiplier: 1.30,
102 },
103 http.StatusServiceUnavailable)
104 }),
105 },
106 CreateAccountLabel: []gax.CallOption{
107 gax.WithTimeout(60000 * time.Millisecond),
108 },
109 UpdateAccountLabel: []gax.CallOption{
110 gax.WithTimeout(60000 * time.Millisecond),
111 },
112 DeleteAccountLabel: []gax.CallOption{
113 gax.WithTimeout(60000 * time.Millisecond),
114 },
115 }
116 }
117
118 // internalAccountLabelsClient is an interface that defines the methods available from CSS API.
119 type internalAccountLabelsClient interface {
120 Close() error
121 setGoogleClientInfo(...string)
122 Connection() *grpc.ClientConn
123 ListAccountLabels(context.Context, *csspb.ListAccountLabelsRequest, ...gax.CallOption) *AccountLabelIterator
124 CreateAccountLabel(context.Context, *csspb.CreateAccountLabelRequest, ...gax.CallOption) (*csspb.AccountLabel, error)
125 UpdateAccountLabel(context.Context, *csspb.UpdateAccountLabelRequest, ...gax.CallOption) (*csspb.AccountLabel, error)
126 DeleteAccountLabel(context.Context, *csspb.DeleteAccountLabelRequest, ...gax.CallOption) error
127 }
128
129 // AccountLabelsClient is a client for interacting with CSS API.
130 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
131 //
132 // Manages Merchant Center and CSS accounts labels.
133 type AccountLabelsClient struct {
134 // The internal transport-dependent client.
135 internalClient internalAccountLabelsClient
136
137 // The call options for this service.
138 CallOptions *AccountLabelsCallOptions
139 }
140
141 // Wrapper methods routed to the internal client.
142
143 // Close closes the connection to the API service. The user should invoke this when
144 // the client is no longer required.
145 func (c *AccountLabelsClient) Close() error {
146 return c.internalClient.Close()
147 }
148
149 // setGoogleClientInfo sets the name and version of the application in
150 // the `x-goog-api-client` header passed on each request. Intended for
151 // use by Google-written clients.
152 func (c *AccountLabelsClient) setGoogleClientInfo(keyval ...string) {
153 c.internalClient.setGoogleClientInfo(keyval...)
154 }
155
156 // Connection returns a connection to the API service.
157 //
158 // Deprecated: Connections are now pooled so this method does not always
159 // return the same resource.
160 func (c *AccountLabelsClient) Connection() *grpc.ClientConn {
161 return c.internalClient.Connection()
162 }
163
164 // ListAccountLabels lists the labels owned by an account.
165 func (c *AccountLabelsClient) ListAccountLabels(ctx context.Context, req *csspb.ListAccountLabelsRequest, opts ...gax.CallOption) *AccountLabelIterator {
166 return c.internalClient.ListAccountLabels(ctx, req, opts...)
167 }
168
169 // CreateAccountLabel creates a new label, not assigned to any account.
170 func (c *AccountLabelsClient) CreateAccountLabel(ctx context.Context, req *csspb.CreateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
171 return c.internalClient.CreateAccountLabel(ctx, req, opts...)
172 }
173
174 // UpdateAccountLabel updates a label.
175 func (c *AccountLabelsClient) UpdateAccountLabel(ctx context.Context, req *csspb.UpdateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
176 return c.internalClient.UpdateAccountLabel(ctx, req, opts...)
177 }
178
179 // DeleteAccountLabel deletes a label and removes it from all accounts to which it was assigned.
180 func (c *AccountLabelsClient) DeleteAccountLabel(ctx context.Context, req *csspb.DeleteAccountLabelRequest, opts ...gax.CallOption) error {
181 return c.internalClient.DeleteAccountLabel(ctx, req, opts...)
182 }
183
184 // accountLabelsGRPCClient is a client for interacting with CSS API over gRPC transport.
185 //
186 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
187 type accountLabelsGRPCClient struct {
188 // Connection pool of gRPC connections to the service.
189 connPool gtransport.ConnPool
190
191 // Points back to the CallOptions field of the containing AccountLabelsClient
192 CallOptions **AccountLabelsCallOptions
193
194 // The gRPC API client.
195 accountLabelsClient csspb.AccountLabelsServiceClient
196
197 // The x-goog-* metadata to be sent with each request.
198 xGoogHeaders []string
199
200 logger *slog.Logger
201 }
202
203 // NewAccountLabelsClient creates a new account labels service client based on gRPC.
204 // The returned client must be Closed when it is done being used to clean up its underlying connections.
205 //
206 // Manages Merchant Center and CSS accounts labels.
207 func NewAccountLabelsClient(ctx context.Context, opts ...option.ClientOption) (*AccountLabelsClient, error) {
208 clientOpts := defaultAccountLabelsGRPCClientOptions()
209 if newAccountLabelsClientHook != nil {
210 hookOpts, err := newAccountLabelsClientHook(ctx, clientHookParams{})
211 if err != nil {
212 return nil, err
213 }
214 clientOpts = append(clientOpts, hookOpts...)
215 }
216
217 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
218 if err != nil {
219 return nil, err
220 }
221 client := AccountLabelsClient{CallOptions: defaultAccountLabelsCallOptions()}
222
223 c := &accountLabelsGRPCClient{
224 connPool: connPool,
225 accountLabelsClient: csspb.NewAccountLabelsServiceClient(connPool),
226 CallOptions: &client.CallOptions,
227 logger: internaloption.GetLogger(opts),
228 }
229 c.setGoogleClientInfo()
230
231 client.internalClient = c
232
233 return &client, nil
234 }
235
236 // Connection returns a connection to the API service.
237 //
238 // Deprecated: Connections are now pooled so this method does not always
239 // return the same resource.
240 func (c *accountLabelsGRPCClient) Connection() *grpc.ClientConn {
241 return c.connPool.Conn()
242 }
243
244 // setGoogleClientInfo sets the name and version of the application in
245 // the `x-goog-api-client` header passed on each request. Intended for
246 // use by Google-written clients.
247 func (c *accountLabelsGRPCClient) setGoogleClientInfo(keyval ...string) {
248 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
249 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
250 c.xGoogHeaders = []string{
251 "x-goog-api-client", gax.XGoogHeader(kv...),
252 }
253 }
254
255 // Close closes the connection to the API service. The user should invoke this when
256 // the client is no longer required.
257 func (c *accountLabelsGRPCClient) Close() error {
258 return c.connPool.Close()
259 }
260
261 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
262 type accountLabelsRESTClient struct {
263 // The http endpoint to connect to.
264 endpoint string
265
266 // The http client.
267 httpClient *http.Client
268
269 // The x-goog-* headers to be sent with each request.
270 xGoogHeaders []string
271
272 // Points back to the CallOptions field of the containing AccountLabelsClient
273 CallOptions **AccountLabelsCallOptions
274
275 logger *slog.Logger
276 }
277
278 // NewAccountLabelsRESTClient creates a new account labels service rest client.
279 //
280 // Manages Merchant Center and CSS accounts labels.
281 func NewAccountLabelsRESTClient(ctx context.Context, opts ...option.ClientOption) (*AccountLabelsClient, error) {
282 clientOpts := append(defaultAccountLabelsRESTClientOptions(), opts...)
283 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
284 if err != nil {
285 return nil, err
286 }
287
288 callOpts := defaultAccountLabelsRESTCallOptions()
289 c := &accountLabelsRESTClient{
290 endpoint: endpoint,
291 httpClient: httpClient,
292 CallOptions: &callOpts,
293 logger: internaloption.GetLogger(opts),
294 }
295 c.setGoogleClientInfo()
296
297 return &AccountLabelsClient{internalClient: c, CallOptions: callOpts}, nil
298 }
299
300 func defaultAccountLabelsRESTClientOptions() []option.ClientOption {
301 return []option.ClientOption{
302 internaloption.WithDefaultEndpoint("https://css.googleapis.com"),
303 internaloption.WithDefaultEndpointTemplate("https://css.UNIVERSE_DOMAIN"),
304 internaloption.WithDefaultMTLSEndpoint("https://css.mtls.googleapis.com"),
305 internaloption.WithDefaultUniverseDomain("googleapis.com"),
306 internaloption.WithDefaultAudience("https://css.googleapis.com/"),
307 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
308 internaloption.EnableNewAuthLibrary(),
309 }
310 }
311
312 // setGoogleClientInfo sets the name and version of the application in
313 // the `x-goog-api-client` header passed on each request. Intended for
314 // use by Google-written clients.
315 func (c *accountLabelsRESTClient) setGoogleClientInfo(keyval ...string) {
316 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
317 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
318 c.xGoogHeaders = []string{
319 "x-goog-api-client", gax.XGoogHeader(kv...),
320 }
321 }
322
323 // Close closes the connection to the API service. The user should invoke this when
324 // the client is no longer required.
325 func (c *accountLabelsRESTClient) Close() error {
326 // Replace httpClient with nil to force cleanup.
327 c.httpClient = nil
328 return nil
329 }
330
331 // Connection returns a connection to the API service.
332 //
333 // Deprecated: This method always returns nil.
334 func (c *accountLabelsRESTClient) Connection() *grpc.ClientConn {
335 return nil
336 }
337 func (c *accountLabelsGRPCClient) ListAccountLabels(ctx context.Context, req *csspb.ListAccountLabelsRequest, opts ...gax.CallOption) *AccountLabelIterator {
338 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
339
340 hds = append(c.xGoogHeaders, hds...)
341 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
342 opts = append((*c.CallOptions).ListAccountLabels[0:len((*c.CallOptions).ListAccountLabels):len((*c.CallOptions).ListAccountLabels)], opts...)
343 it := &AccountLabelIterator{}
344 req = proto.Clone(req).(*csspb.ListAccountLabelsRequest)
345 it.InternalFetch = func(pageSize int, pageToken string) ([]*csspb.AccountLabel, string, error) {
346 resp := &csspb.ListAccountLabelsResponse{}
347 if pageToken != "" {
348 req.PageToken = pageToken
349 }
350 if pageSize > math.MaxInt32 {
351 req.PageSize = math.MaxInt32
352 } else if pageSize != 0 {
353 req.PageSize = int32(pageSize)
354 }
355 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
356 var err error
357 resp, err = executeRPC(ctx, c.accountLabelsClient.ListAccountLabels, req, settings.GRPC, c.logger, "ListAccountLabels")
358 return err
359 }, opts...)
360 if err != nil {
361 return nil, "", err
362 }
363
364 it.Response = resp
365 return resp.GetAccountLabels(), resp.GetNextPageToken(), nil
366 }
367 fetch := func(pageSize int, pageToken string) (string, error) {
368 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
369 if err != nil {
370 return "", err
371 }
372 it.items = append(it.items, items...)
373 return nextPageToken, nil
374 }
375
376 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
377 it.pageInfo.MaxSize = int(req.GetPageSize())
378 it.pageInfo.Token = req.GetPageToken()
379
380 return it
381 }
382
383 func (c *accountLabelsGRPCClient) CreateAccountLabel(ctx context.Context, req *csspb.CreateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
384 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
385
386 hds = append(c.xGoogHeaders, hds...)
387 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
388 opts = append((*c.CallOptions).CreateAccountLabel[0:len((*c.CallOptions).CreateAccountLabel):len((*c.CallOptions).CreateAccountLabel)], opts...)
389 var resp *csspb.AccountLabel
390 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
391 var err error
392 resp, err = executeRPC(ctx, c.accountLabelsClient.CreateAccountLabel, req, settings.GRPC, c.logger, "CreateAccountLabel")
393 return err
394 }, opts...)
395 if err != nil {
396 return nil, err
397 }
398 return resp, nil
399 }
400
401 func (c *accountLabelsGRPCClient) UpdateAccountLabel(ctx context.Context, req *csspb.UpdateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
402 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_label.name", url.QueryEscape(req.GetAccountLabel().GetName()))}
403
404 hds = append(c.xGoogHeaders, hds...)
405 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
406 opts = append((*c.CallOptions).UpdateAccountLabel[0:len((*c.CallOptions).UpdateAccountLabel):len((*c.CallOptions).UpdateAccountLabel)], opts...)
407 var resp *csspb.AccountLabel
408 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
409 var err error
410 resp, err = executeRPC(ctx, c.accountLabelsClient.UpdateAccountLabel, req, settings.GRPC, c.logger, "UpdateAccountLabel")
411 return err
412 }, opts...)
413 if err != nil {
414 return nil, err
415 }
416 return resp, nil
417 }
418
419 func (c *accountLabelsGRPCClient) DeleteAccountLabel(ctx context.Context, req *csspb.DeleteAccountLabelRequest, opts ...gax.CallOption) error {
420 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
421
422 hds = append(c.xGoogHeaders, hds...)
423 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
424 opts = append((*c.CallOptions).DeleteAccountLabel[0:len((*c.CallOptions).DeleteAccountLabel):len((*c.CallOptions).DeleteAccountLabel)], opts...)
425 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
426 var err error
427 _, err = executeRPC(ctx, c.accountLabelsClient.DeleteAccountLabel, req, settings.GRPC, c.logger, "DeleteAccountLabel")
428 return err
429 }, opts...)
430 return err
431 }
432
433 // ListAccountLabels lists the labels owned by an account.
434 func (c *accountLabelsRESTClient) ListAccountLabels(ctx context.Context, req *csspb.ListAccountLabelsRequest, opts ...gax.CallOption) *AccountLabelIterator {
435 it := &AccountLabelIterator{}
436 req = proto.Clone(req).(*csspb.ListAccountLabelsRequest)
437 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
438 it.InternalFetch = func(pageSize int, pageToken string) ([]*csspb.AccountLabel, string, error) {
439 resp := &csspb.ListAccountLabelsResponse{}
440 if pageToken != "" {
441 req.PageToken = pageToken
442 }
443 if pageSize > math.MaxInt32 {
444 req.PageSize = math.MaxInt32
445 } else if pageSize != 0 {
446 req.PageSize = int32(pageSize)
447 }
448 baseUrl, err := url.Parse(c.endpoint)
449 if err != nil {
450 return nil, "", err
451 }
452 baseUrl.Path += fmt.Sprintf("/v1/%v/labels", req.GetParent())
453
454 params := url.Values{}
455 params.Add("$alt", "json;enum-encoding=int")
456 if req.GetPageSize() != 0 {
457 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
458 }
459 if req.GetPageToken() != "" {
460 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
461 }
462
463 baseUrl.RawQuery = params.Encode()
464
465 // Build HTTP headers from client and context metadata.
466 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
467 headers := gax.BuildHeaders(ctx, hds...)
468 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
469 if settings.Path != "" {
470 baseUrl.Path = settings.Path
471 }
472 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
473 if err != nil {
474 return err
475 }
476 httpReq.Header = headers
477
478 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListAccountLabels")
479 if err != nil {
480 return err
481 }
482 if err := unm.Unmarshal(buf, resp); err != nil {
483 return err
484 }
485
486 return nil
487 }, opts...)
488 if e != nil {
489 return nil, "", e
490 }
491 it.Response = resp
492 return resp.GetAccountLabels(), resp.GetNextPageToken(), nil
493 }
494
495 fetch := func(pageSize int, pageToken string) (string, error) {
496 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
497 if err != nil {
498 return "", err
499 }
500 it.items = append(it.items, items...)
501 return nextPageToken, nil
502 }
503
504 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
505 it.pageInfo.MaxSize = int(req.GetPageSize())
506 it.pageInfo.Token = req.GetPageToken()
507
508 return it
509 }
510
511 // CreateAccountLabel creates a new label, not assigned to any account.
512 func (c *accountLabelsRESTClient) CreateAccountLabel(ctx context.Context, req *csspb.CreateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
513 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
514 body := req.GetAccountLabel()
515 jsonReq, err := m.Marshal(body)
516 if err != nil {
517 return nil, err
518 }
519
520 baseUrl, err := url.Parse(c.endpoint)
521 if err != nil {
522 return nil, err
523 }
524 baseUrl.Path += fmt.Sprintf("/v1/%v/labels", req.GetParent())
525
526 params := url.Values{}
527 params.Add("$alt", "json;enum-encoding=int")
528
529 baseUrl.RawQuery = params.Encode()
530
531 // Build HTTP headers from client and context metadata.
532 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
533
534 hds = append(c.xGoogHeaders, hds...)
535 hds = append(hds, "Content-Type", "application/json")
536 headers := gax.BuildHeaders(ctx, hds...)
537 opts = append((*c.CallOptions).CreateAccountLabel[0:len((*c.CallOptions).CreateAccountLabel):len((*c.CallOptions).CreateAccountLabel)], opts...)
538 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
539 resp := &csspb.AccountLabel{}
540 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
541 if settings.Path != "" {
542 baseUrl.Path = settings.Path
543 }
544 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
545 if err != nil {
546 return err
547 }
548 httpReq = httpReq.WithContext(ctx)
549 httpReq.Header = headers
550
551 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateAccountLabel")
552 if err != nil {
553 return err
554 }
555
556 if err := unm.Unmarshal(buf, resp); err != nil {
557 return err
558 }
559
560 return nil
561 }, opts...)
562 if e != nil {
563 return nil, e
564 }
565 return resp, nil
566 }
567
568 // UpdateAccountLabel updates a label.
569 func (c *accountLabelsRESTClient) UpdateAccountLabel(ctx context.Context, req *csspb.UpdateAccountLabelRequest, opts ...gax.CallOption) (*csspb.AccountLabel, error) {
570 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
571 body := req.GetAccountLabel()
572 jsonReq, err := m.Marshal(body)
573 if err != nil {
574 return nil, err
575 }
576
577 baseUrl, err := url.Parse(c.endpoint)
578 if err != nil {
579 return nil, err
580 }
581 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetAccountLabel().GetName())
582
583 params := url.Values{}
584 params.Add("$alt", "json;enum-encoding=int")
585
586 baseUrl.RawQuery = params.Encode()
587
588 // Build HTTP headers from client and context metadata.
589 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "account_label.name", url.QueryEscape(req.GetAccountLabel().GetName()))}
590
591 hds = append(c.xGoogHeaders, hds...)
592 hds = append(hds, "Content-Type", "application/json")
593 headers := gax.BuildHeaders(ctx, hds...)
594 opts = append((*c.CallOptions).UpdateAccountLabel[0:len((*c.CallOptions).UpdateAccountLabel):len((*c.CallOptions).UpdateAccountLabel)], opts...)
595 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
596 resp := &csspb.AccountLabel{}
597 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
598 if settings.Path != "" {
599 baseUrl.Path = settings.Path
600 }
601 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
602 if err != nil {
603 return err
604 }
605 httpReq = httpReq.WithContext(ctx)
606 httpReq.Header = headers
607
608 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateAccountLabel")
609 if err != nil {
610 return err
611 }
612
613 if err := unm.Unmarshal(buf, resp); err != nil {
614 return err
615 }
616
617 return nil
618 }, opts...)
619 if e != nil {
620 return nil, e
621 }
622 return resp, nil
623 }
624
625 // DeleteAccountLabel deletes a label and removes it from all accounts to which it was assigned.
626 func (c *accountLabelsRESTClient) DeleteAccountLabel(ctx context.Context, req *csspb.DeleteAccountLabelRequest, opts ...gax.CallOption) error {
627 baseUrl, err := url.Parse(c.endpoint)
628 if err != nil {
629 return err
630 }
631 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
632
633 params := url.Values{}
634 params.Add("$alt", "json;enum-encoding=int")
635
636 baseUrl.RawQuery = params.Encode()
637
638 // Build HTTP headers from client and context metadata.
639 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
640
641 hds = append(c.xGoogHeaders, hds...)
642 hds = append(hds, "Content-Type", "application/json")
643 headers := gax.BuildHeaders(ctx, hds...)
644 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
645 if settings.Path != "" {
646 baseUrl.Path = settings.Path
647 }
648 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
649 if err != nil {
650 return err
651 }
652 httpReq = httpReq.WithContext(ctx)
653 httpReq.Header = headers
654
655 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteAccountLabel")
656 return err
657 }, opts...)
658 }