Debian Codegraph @

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