Debian Codegraph @

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