Debian Codegraph @

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