Debian Codegraph @

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