Debian Codegraph @

apihub/apiv1/api_hub_dependencies_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 "time"
28
29 apihubpb "cloud.google.com/go/apihub/apiv1/apihubpb"
30 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
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 httptransport "google.golang.org/api/transport/http"
36 locationpb "google.golang.org/genproto/googleapis/cloud/location"
37 "google.golang.org/grpc"
38 "google.golang.org/protobuf/encoding/protojson"
39 "google.golang.org/protobuf/proto"
40 )
41
42 var newApiHubDependenciesClientHook clientHook
43
44 // ApiHubDependenciesCallOptions contains the retry settings for each method of ApiHubDependenciesClient.
45 type ApiHubDependenciesCallOptions struct {
46 CreateDependency []gax.CallOption
47 GetDependency []gax.CallOption
48 UpdateDependency []gax.CallOption
49 DeleteDependency []gax.CallOption
50 ListDependencies []gax.CallOption
51 GetLocation []gax.CallOption
52 ListLocations []gax.CallOption
53 CancelOperation []gax.CallOption
54 DeleteOperation []gax.CallOption
55 GetOperation []gax.CallOption
56 ListOperations []gax.CallOption
57 }
58
59 func defaultApiHubDependenciesRESTCallOptions() *ApiHubDependenciesCallOptions {
60 return &ApiHubDependenciesCallOptions{
61 CreateDependency: []gax.CallOption{
62 gax.WithTimeout(60000 * time.Millisecond),
63 },
64 GetDependency: []gax.CallOption{
65 gax.WithTimeout(60000 * time.Millisecond),
66 gax.WithRetry(func() gax.Retryer {
67 return gax.OnHTTPCodes(gax.Backoff{
68 Initial: 1000 * time.Millisecond,
69 Max: 10000 * time.Millisecond,
70 Multiplier: 1.30,
71 },
72 http.StatusServiceUnavailable)
73 }),
74 },
75 UpdateDependency: []gax.CallOption{
76 gax.WithTimeout(60000 * time.Millisecond),
77 },
78 DeleteDependency: []gax.CallOption{
79 gax.WithTimeout(60000 * time.Millisecond),
80 },
81 ListDependencies: []gax.CallOption{
82 gax.WithTimeout(60000 * time.Millisecond),
83 gax.WithRetry(func() gax.Retryer {
84 return gax.OnHTTPCodes(gax.Backoff{
85 Initial: 1000 * time.Millisecond,
86 Max: 10000 * time.Millisecond,
87 Multiplier: 1.30,
88 },
89 http.StatusServiceUnavailable)
90 }),
91 },
92 GetLocation: []gax.CallOption{},
93 ListLocations: []gax.CallOption{},
94 CancelOperation: []gax.CallOption{},
95 DeleteOperation: []gax.CallOption{},
96 GetOperation: []gax.CallOption{},
97 ListOperations: []gax.CallOption{},
98 }
99 }
100
101 // internalApiHubDependenciesClient is an interface that defines the methods available from API hub API.
102 type internalApiHubDependenciesClient interface {
103 Close() error
104 setGoogleClientInfo(...string)
105 Connection() *grpc.ClientConn
106 CreateDependency(context.Context, *apihubpb.CreateDependencyRequest, ...gax.CallOption) (*apihubpb.Dependency, error)
107 GetDependency(context.Context, *apihubpb.GetDependencyRequest, ...gax.CallOption) (*apihubpb.Dependency, error)
108 UpdateDependency(context.Context, *apihubpb.UpdateDependencyRequest, ...gax.CallOption) (*apihubpb.Dependency, error)
109 DeleteDependency(context.Context, *apihubpb.DeleteDependencyRequest, ...gax.CallOption) error
110 ListDependencies(context.Context, *apihubpb.ListDependenciesRequest, ...gax.CallOption) *DependencyIterator
111 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
112 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
113 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
114 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
115 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
116 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
117 }
118
119 // ApiHubDependenciesClient is a client for interacting with API hub API.
120 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
121 //
122 // This service provides methods for various operations related to a
123 // Dependency in the API hub.
124 type ApiHubDependenciesClient struct {
125 // The internal transport-dependent client.
126 internalClient internalApiHubDependenciesClient
127
128 // The call options for this service.
129 CallOptions *ApiHubDependenciesCallOptions
130 }
131
132 // Wrapper methods routed to the internal client.
133
134 // Close closes the connection to the API service. The user should invoke this when
135 // the client is no longer required.
136 func (c *ApiHubDependenciesClient) Close() error {
137 return c.internalClient.Close()
138 }
139
140 // setGoogleClientInfo sets the name and version of the application in
141 // the `x-goog-api-client` header passed on each request. Intended for
142 // use by Google-written clients.
143 func (c *ApiHubDependenciesClient) setGoogleClientInfo(keyval ...string) {
144 c.internalClient.setGoogleClientInfo(keyval...)
145 }
146
147 // Connection returns a connection to the API service.
148 //
149 // Deprecated: Connections are now pooled so this method does not always
150 // return the same resource.
151 func (c *ApiHubDependenciesClient) Connection() *grpc.ClientConn {
152 return c.internalClient.Connection()
153 }
154
155 // CreateDependency create a dependency between two entities in the API hub.
156 func (c *ApiHubDependenciesClient) CreateDependency(ctx context.Context, req *apihubpb.CreateDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
157 return c.internalClient.CreateDependency(ctx, req, opts...)
158 }
159
160 // GetDependency get details about a dependency resource in the API hub.
161 func (c *ApiHubDependenciesClient) GetDependency(ctx context.Context, req *apihubpb.GetDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
162 return c.internalClient.GetDependency(ctx, req, opts...)
163 }
164
165 // UpdateDependency update a dependency based on the
166 // update_mask
167 // provided in the request.
168 //
169 // The following fields in the dependency
170 // can be updated:
171 //
172 // description
173 func (c *ApiHubDependenciesClient) UpdateDependency(ctx context.Context, req *apihubpb.UpdateDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
174 return c.internalClient.UpdateDependency(ctx, req, opts...)
175 }
176
177 // DeleteDependency delete the dependency resource.
178 func (c *ApiHubDependenciesClient) DeleteDependency(ctx context.Context, req *apihubpb.DeleteDependencyRequest, opts ...gax.CallOption) error {
179 return c.internalClient.DeleteDependency(ctx, req, opts...)
180 }
181
182 // ListDependencies list dependencies based on the provided filter and pagination parameters.
183 func (c *ApiHubDependenciesClient) ListDependencies(ctx context.Context, req *apihubpb.ListDependenciesRequest, opts ...gax.CallOption) *DependencyIterator {
184 return c.internalClient.ListDependencies(ctx, req, opts...)
185 }
186
187 // GetLocation gets information about a location.
188 func (c *ApiHubDependenciesClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
189 return c.internalClient.GetLocation(ctx, req, opts...)
190 }
191
192 // ListLocations lists information about the supported locations for this service.
193 func (c *ApiHubDependenciesClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
194 return c.internalClient.ListLocations(ctx, req, opts...)
195 }
196
197 // CancelOperation is a utility method from google.longrunning.Operations.
198 func (c *ApiHubDependenciesClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
199 return c.internalClient.CancelOperation(ctx, req, opts...)
200 }
201
202 // DeleteOperation is a utility method from google.longrunning.Operations.
203 func (c *ApiHubDependenciesClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
204 return c.internalClient.DeleteOperation(ctx, req, opts...)
205 }
206
207 // GetOperation is a utility method from google.longrunning.Operations.
208 func (c *ApiHubDependenciesClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
209 return c.internalClient.GetOperation(ctx, req, opts...)
210 }
211
212 // ListOperations is a utility method from google.longrunning.Operations.
213 func (c *ApiHubDependenciesClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
214 return c.internalClient.ListOperations(ctx, req, opts...)
215 }
216
217 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
218 type apiHubDependenciesRESTClient struct {
219 // The http endpoint to connect to.
220 endpoint string
221
222 // The http client.
223 httpClient *http.Client
224
225 // The x-goog-* headers to be sent with each request.
226 xGoogHeaders []string
227
228 // Points back to the CallOptions field of the containing ApiHubDependenciesClient
229 CallOptions **ApiHubDependenciesCallOptions
230
231 logger *slog.Logger
232 }
233
234 // NewApiHubDependenciesRESTClient creates a new api hub dependencies rest client.
235 //
236 // This service provides methods for various operations related to a
237 // Dependency in the API hub.
238 func NewApiHubDependenciesRESTClient(ctx context.Context, opts ...option.ClientOption) (*ApiHubDependenciesClient, error) {
239 clientOpts := append(defaultApiHubDependenciesRESTClientOptions(), opts...)
240 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
241 if err != nil {
242 return nil, err
243 }
244
245 callOpts := defaultApiHubDependenciesRESTCallOptions()
246 c := &apiHubDependenciesRESTClient{
247 endpoint: endpoint,
248 httpClient: httpClient,
249 CallOptions: &callOpts,
250 logger: internaloption.GetLogger(opts),
251 }
252 c.setGoogleClientInfo()
253
254 return &ApiHubDependenciesClient{internalClient: c, CallOptions: callOpts}, nil
255 }
256
257 func defaultApiHubDependenciesRESTClientOptions() []option.ClientOption {
258 return []option.ClientOption{
259 internaloption.WithDefaultEndpoint("https://apihub.googleapis.com"),
260 internaloption.WithDefaultEndpointTemplate("https://apihub.UNIVERSE_DOMAIN"),
261 internaloption.WithDefaultMTLSEndpoint("https://apihub.mtls.googleapis.com"),
262 internaloption.WithDefaultUniverseDomain("googleapis.com"),
263 internaloption.WithDefaultAudience("https://apihub.googleapis.com/"),
264 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
265 internaloption.EnableNewAuthLibrary(),
266 }
267 }
268
269 // setGoogleClientInfo sets the name and version of the application in
270 // the `x-goog-api-client` header passed on each request. Intended for
271 // use by Google-written clients.
272 func (c *apiHubDependenciesRESTClient) setGoogleClientInfo(keyval ...string) {
273 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
274 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
275 c.xGoogHeaders = []string{
276 "x-goog-api-client", gax.XGoogHeader(kv...),
277 }
278 }
279
280 // Close closes the connection to the API service. The user should invoke this when
281 // the client is no longer required.
282 func (c *apiHubDependenciesRESTClient) Close() error {
283 // Replace httpClient with nil to force cleanup.
284 c.httpClient = nil
285 return nil
286 }
287
288 // Connection returns a connection to the API service.
289 //
290 // Deprecated: This method always returns nil.
291 func (c *apiHubDependenciesRESTClient) Connection() *grpc.ClientConn {
292 return nil
293 }
294
295 // CreateDependency create a dependency between two entities in the API hub.
296 func (c *apiHubDependenciesRESTClient) CreateDependency(ctx context.Context, req *apihubpb.CreateDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
297 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
298 body := req.GetDependency()
299 jsonReq, err := m.Marshal(body)
300 if err != nil {
301 return nil, err
302 }
303
304 baseUrl, err := url.Parse(c.endpoint)
305 if err != nil {
306 return nil, err
307 }
308 baseUrl.Path += fmt.Sprintf("/v1/%v/dependencies", req.GetParent())
309
310 params := url.Values{}
311 params.Add("$alt", "json;enum-encoding=int")
312 if req.GetDependencyId() != "" {
313 params.Add("dependencyId", fmt.Sprintf("%v", req.GetDependencyId()))
314 }
315
316 baseUrl.RawQuery = params.Encode()
317
318 // Build HTTP headers from client and context metadata.
319 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
320
321 hds = append(c.xGoogHeaders, hds...)
322 hds = append(hds, "Content-Type", "application/json")
323 headers := gax.BuildHeaders(ctx, hds...)
324 opts = append((*c.CallOptions).CreateDependency[0:len((*c.CallOptions).CreateDependency):len((*c.CallOptions).CreateDependency)], opts...)
325 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
326 resp := &apihubpb.Dependency{}
327 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
328 if settings.Path != "" {
329 baseUrl.Path = settings.Path
330 }
331 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
332 if err != nil {
333 return err
334 }
335 httpReq = httpReq.WithContext(ctx)
336 httpReq.Header = headers
337
338 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateDependency")
339 if err != nil {
340 return err
341 }
342
343 if err := unm.Unmarshal(buf, resp); err != nil {
344 return err
345 }
346
347 return nil
348 }, opts...)
349 if e != nil {
350 return nil, e
351 }
352 return resp, nil
353 }
354
355 // GetDependency get details about a dependency resource in the API hub.
356 func (c *apiHubDependenciesRESTClient) GetDependency(ctx context.Context, req *apihubpb.GetDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
357 baseUrl, err := url.Parse(c.endpoint)
358 if err != nil {
359 return nil, err
360 }
361 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
362
363 params := url.Values{}
364 params.Add("$alt", "json;enum-encoding=int")
365
366 baseUrl.RawQuery = params.Encode()
367
368 // Build HTTP headers from client and context metadata.
369 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
370
371 hds = append(c.xGoogHeaders, hds...)
372 hds = append(hds, "Content-Type", "application/json")
373 headers := gax.BuildHeaders(ctx, hds...)
374 opts = append((*c.CallOptions).GetDependency[0:len((*c.CallOptions).GetDependency):len((*c.CallOptions).GetDependency)], opts...)
375 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
376 resp := &apihubpb.Dependency{}
377 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
378 if settings.Path != "" {
379 baseUrl.Path = settings.Path
380 }
381 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
382 if err != nil {
383 return err
384 }
385 httpReq = httpReq.WithContext(ctx)
386 httpReq.Header = headers
387
388 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetDependency")
389 if err != nil {
390 return err
391 }
392
393 if err := unm.Unmarshal(buf, resp); err != nil {
394 return err
395 }
396
397 return nil
398 }, opts...)
399 if e != nil {
400 return nil, e
401 }
402 return resp, nil
403 }
404
405 // UpdateDependency update a dependency based on the
406 // update_mask
407 // provided in the request.
408 //
409 // The following fields in the dependency
410 // can be updated:
411 //
412 // description
413 func (c *apiHubDependenciesRESTClient) UpdateDependency(ctx context.Context, req *apihubpb.UpdateDependencyRequest, opts ...gax.CallOption) (*apihubpb.Dependency, error) {
414 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
415 body := req.GetDependency()
416 jsonReq, err := m.Marshal(body)
417 if err != nil {
418 return nil, err
419 }
420
421 baseUrl, err := url.Parse(c.endpoint)
422 if err != nil {
423 return nil, err
424 }
425 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetDependency().GetName())
426
427 params := url.Values{}
428 params.Add("$alt", "json;enum-encoding=int")
429 if req.GetUpdateMask() != nil {
430 field, err := protojson.Marshal(req.GetUpdateMask())
431 if err != nil {
432 return nil, err
433 }
434 params.Add("updateMask", string(field[1:len(field)-1]))
435 }
436
437 baseUrl.RawQuery = params.Encode()
438
439 // Build HTTP headers from client and context metadata.
440 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "dependency.name", url.QueryEscape(req.GetDependency().GetName()))}
441
442 hds = append(c.xGoogHeaders, hds...)
443 hds = append(hds, "Content-Type", "application/json")
444 headers := gax.BuildHeaders(ctx, hds...)
445 opts = append((*c.CallOptions).UpdateDependency[0:len((*c.CallOptions).UpdateDependency):len((*c.CallOptions).UpdateDependency)], opts...)
446 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
447 resp := &apihubpb.Dependency{}
448 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
449 if settings.Path != "" {
450 baseUrl.Path = settings.Path
451 }
452 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
453 if err != nil {
454 return err
455 }
456 httpReq = httpReq.WithContext(ctx)
457 httpReq.Header = headers
458
459 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateDependency")
460 if err != nil {
461 return err
462 }
463
464 if err := unm.Unmarshal(buf, resp); err != nil {
465 return err
466 }
467
468 return nil
469 }, opts...)
470 if e != nil {
471 return nil, e
472 }
473 return resp, nil
474 }
475
476 // DeleteDependency delete the dependency resource.
477 func (c *apiHubDependenciesRESTClient) DeleteDependency(ctx context.Context, req *apihubpb.DeleteDependencyRequest, opts ...gax.CallOption) error {
478 baseUrl, err := url.Parse(c.endpoint)
479 if err != nil {
480 return err
481 }
482 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
483
484 params := url.Values{}
485 params.Add("$alt", "json;enum-encoding=int")
486
487 baseUrl.RawQuery = params.Encode()
488
489 // Build HTTP headers from client and context metadata.
490 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
491
492 hds = append(c.xGoogHeaders, hds...)
493 hds = append(hds, "Content-Type", "application/json")
494 headers := gax.BuildHeaders(ctx, hds...)
495 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
496 if settings.Path != "" {
497 baseUrl.Path = settings.Path
498 }
499 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
500 if err != nil {
501 return err
502 }
503 httpReq = httpReq.WithContext(ctx)
504 httpReq.Header = headers
505
506 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteDependency")
507 return err
508 }, opts...)
509 }
510
511 // ListDependencies list dependencies based on the provided filter and pagination parameters.
512 func (c *apiHubDependenciesRESTClient) ListDependencies(ctx context.Context, req *apihubpb.ListDependenciesRequest, opts ...gax.CallOption) *DependencyIterator {
513 it := &DependencyIterator{}
514 req = proto.Clone(req).(*apihubpb.ListDependenciesRequest)
515 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
516 it.InternalFetch = func(pageSize int, pageToken string) ([]*apihubpb.Dependency, string, error) {
517 resp := &apihubpb.ListDependenciesResponse{}
518 if pageToken != "" {
519 req.PageToken = pageToken
520 }
521 if pageSize > math.MaxInt32 {
522 req.PageSize = math.MaxInt32
523 } else if pageSize != 0 {
524 req.PageSize = int32(pageSize)
525 }
526 baseUrl, err := url.Parse(c.endpoint)
527 if err != nil {
528 return nil, "", err
529 }
530 baseUrl.Path += fmt.Sprintf("/v1/%v/dependencies", req.GetParent())
531
532 params := url.Values{}
533 params.Add("$alt", "json;enum-encoding=int")
534 if req.GetFilter() != "" {
535 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
536 }
537 if req.GetPageSize() != 0 {
538 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
539 }
540 if req.GetPageToken() != "" {
541 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
542 }
543
544 baseUrl.RawQuery = params.Encode()
545
546 // Build HTTP headers from client and context metadata.
547 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
548 headers := gax.BuildHeaders(ctx, hds...)
549 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
550 if settings.Path != "" {
551 baseUrl.Path = settings.Path
552 }
553 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
554 if err != nil {
555 return err
556 }
557 httpReq.Header = headers
558
559 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListDependencies")
560 if err != nil {
561 return err
562 }
563 if err := unm.Unmarshal(buf, resp); err != nil {
564 return err
565 }
566
567 return nil
568 }, opts...)
569 if e != nil {
570 return nil, "", e
571 }
572 it.Response = resp
573 return resp.GetDependencies(), resp.GetNextPageToken(), nil
574 }
575
576 fetch := func(pageSize int, pageToken string) (string, error) {
577 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
578 if err != nil {
579 return "", err
580 }
581 it.items = append(it.items, items...)
582 return nextPageToken, nil
583 }
584
585 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
586 it.pageInfo.MaxSize = int(req.GetPageSize())
587 it.pageInfo.Token = req.GetPageToken()
588
589 return it
590 }
591
592 // GetLocation gets information about a location.
593 func (c *apiHubDependenciesRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
594 baseUrl, err := url.Parse(c.endpoint)
595 if err != nil {
596 return nil, err
597 }
598 baseUrl.Path += fmt.Sprintf("/v1/%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).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
612 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
613 resp := &locationpb.Location{}
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, "GetLocation")
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 // ListLocations lists information about the supported locations for this service.
643 func (c *apiHubDependenciesRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
644 it := &LocationIterator{}
645 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
646 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
647 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
648 resp := &locationpb.ListLocationsResponse{}
649 if pageToken != "" {
650 req.PageToken = pageToken
651 }
652 if pageSize > math.MaxInt32 {
653 req.PageSize = math.MaxInt32
654 } else if pageSize != 0 {
655 req.PageSize = int32(pageSize)
656 }
657 baseUrl, err := url.Parse(c.endpoint)
658 if err != nil {
659 return nil, "", err
660 }
661 baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName())
662
663 params := url.Values{}
664 params.Add("$alt", "json;enum-encoding=int")
665 if req.GetFilter() != "" {
666 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
667 }
668 if req.GetPageSize() != 0 {
669 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
670 }
671 if req.GetPageToken() != "" {
672 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
673 }
674
675 baseUrl.RawQuery = params.Encode()
676
677 // Build HTTP headers from client and context metadata.
678 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
679 headers := gax.BuildHeaders(ctx, hds...)
680 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
681 if settings.Path != "" {
682 baseUrl.Path = settings.Path
683 }
684 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
685 if err != nil {
686 return err
687 }
688 httpReq.Header = headers
689
690 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
691 if err != nil {
692 return err
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 it.Response = resp
704 return resp.GetLocations(), resp.GetNextPageToken(), nil
705 }
706
707 fetch := func(pageSize int, pageToken string) (string, error) {
708 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
709 if err != nil {
710 return "", err
711 }
712 it.items = append(it.items, items...)
713 return nextPageToken, nil
714 }
715
716 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
717 it.pageInfo.MaxSize = int(req.GetPageSize())
718 it.pageInfo.Token = req.GetPageToken()
719
720 return it
721 }
722
723 // CancelOperation is a utility method from google.longrunning.Operations.
724 func (c *apiHubDependenciesRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
725 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
726 jsonReq, err := m.Marshal(req)
727 if err != nil {
728 return err
729 }
730
731 baseUrl, err := url.Parse(c.endpoint)
732 if err != nil {
733 return err
734 }
735 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
736
737 params := url.Values{}
738 params.Add("$alt", "json;enum-encoding=int")
739
740 baseUrl.RawQuery = params.Encode()
741
742 // Build HTTP headers from client and context metadata.
743 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
744
745 hds = append(c.xGoogHeaders, hds...)
746 hds = append(hds, "Content-Type", "application/json")
747 headers := gax.BuildHeaders(ctx, hds...)
748 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
749 if settings.Path != "" {
750 baseUrl.Path = settings.Path
751 }
752 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
753 if err != nil {
754 return err
755 }
756 httpReq = httpReq.WithContext(ctx)
757 httpReq.Header = headers
758
759 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
760 return err
761 }, opts...)
762 }
763
764 // DeleteOperation is a utility method from google.longrunning.Operations.
765 func (c *apiHubDependenciesRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
766 baseUrl, err := url.Parse(c.endpoint)
767 if err != nil {
768 return err
769 }
770 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
771
772 params := url.Values{}
773 params.Add("$alt", "json;enum-encoding=int")
774
775 baseUrl.RawQuery = params.Encode()
776
777 // Build HTTP headers from client and context metadata.
778 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
779
780 hds = append(c.xGoogHeaders, hds...)
781 hds = append(hds, "Content-Type", "application/json")
782 headers := gax.BuildHeaders(ctx, hds...)
783 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
784 if settings.Path != "" {
785 baseUrl.Path = settings.Path
786 }
787 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
788 if err != nil {
789 return err
790 }
791 httpReq = httpReq.WithContext(ctx)
792 httpReq.Header = headers
793
794 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
795 return err
796 }, opts...)
797 }
798
799 // GetOperation is a utility method from google.longrunning.Operations.
800 func (c *apiHubDependenciesRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
801 baseUrl, err := url.Parse(c.endpoint)
802 if err != nil {
803 return nil, err
804 }
805 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
806
807 params := url.Values{}
808 params.Add("$alt", "json;enum-encoding=int")
809
810 baseUrl.RawQuery = params.Encode()
811
812 // Build HTTP headers from client and context metadata.
813 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
814
815 hds = append(c.xGoogHeaders, hds...)
816 hds = append(hds, "Content-Type", "application/json")
817 headers := gax.BuildHeaders(ctx, hds...)
818 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
819 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
820 resp := &longrunningpb.Operation{}
821 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
822 if settings.Path != "" {
823 baseUrl.Path = settings.Path
824 }
825 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
826 if err != nil {
827 return err
828 }
829 httpReq = httpReq.WithContext(ctx)
830 httpReq.Header = headers
831
832 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
833 if err != nil {
834 return err
835 }
836
837 if err := unm.Unmarshal(buf, resp); err != nil {
838 return err
839 }
840
841 return nil
842 }, opts...)
843 if e != nil {
844 return nil, e
845 }
846 return resp, nil
847 }
848
849 // ListOperations is a utility method from google.longrunning.Operations.
850 func (c *apiHubDependenciesRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
851 it := &OperationIterator{}
852 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
853 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
854 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
855 resp := &longrunningpb.ListOperationsResponse{}
856 if pageToken != "" {
857 req.PageToken = pageToken
858 }
859 if pageSize > math.MaxInt32 {
860 req.PageSize = math.MaxInt32
861 } else if pageSize != 0 {
862 req.PageSize = int32(pageSize)
863 }
864 baseUrl, err := url.Parse(c.endpoint)
865 if err != nil {
866 return nil, "", err
867 }
868 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
869
870 params := url.Values{}
871 params.Add("$alt", "json;enum-encoding=int")
872 if req.GetFilter() != "" {
873 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
874 }
875 if req.GetPageSize() != 0 {
876 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
877 }
878 if req.GetPageToken() != "" {
879 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
880 }
881
882 baseUrl.RawQuery = params.Encode()
883
884 // Build HTTP headers from client and context metadata.
885 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
886 headers := gax.BuildHeaders(ctx, hds...)
887 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
888 if settings.Path != "" {
889 baseUrl.Path = settings.Path
890 }
891 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
892 if err != nil {
893 return err
894 }
895 httpReq.Header = headers
896
897 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
898 if err != nil {
899 return err
900 }
901 if err := unm.Unmarshal(buf, resp); err != nil {
902 return err
903 }
904
905 return nil
906 }, opts...)
907 if e != nil {
908 return nil, "", e
909 }
910 it.Response = resp
911 return resp.GetOperations(), resp.GetNextPageToken(), nil
912 }
913
914 fetch := func(pageSize int, pageToken string) (string, error) {
915 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
916 if err != nil {
917 return "", err
918 }
919 it.items = append(it.items, items...)
920 return nextPageToken, nil
921 }
922
923 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
924 it.pageInfo.MaxSize = int(req.GetPageSize())
925 it.pageInfo.Token = req.GetPageToken()
926
927 return it
928 }