Debian Codegraph @

licensemanager/apiv1/license_manager_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 licensemanager
18
19 import (
20 "bytes"
21 "context"
22 "fmt"
23 "log/slog"
24 "math"
25 "net/http"
26 "net/url"
27 "time"
28
29 licensemanagerpb "cloud.google.com/go/licensemanager/apiv1/licensemanagerpb"
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 gtransport "google.golang.org/api/transport/grpc"
38 httptransport "google.golang.org/api/transport/http"
39 locationpb "google.golang.org/genproto/googleapis/cloud/location"
40 "google.golang.org/grpc"
41 "google.golang.org/grpc/codes"
42 "google.golang.org/protobuf/encoding/protojson"
43 "google.golang.org/protobuf/proto"
44 )
45
46 var newClientHook clientHook
47
48 // CallOptions contains the retry settings for each method of Client.
49 type CallOptions struct {
50 ListConfigurations []gax.CallOption
51 GetConfiguration []gax.CallOption
52 CreateConfiguration []gax.CallOption
53 UpdateConfiguration []gax.CallOption
54 DeleteConfiguration []gax.CallOption
55 ListInstances []gax.CallOption
56 GetInstance []gax.CallOption
57 DeactivateConfiguration []gax.CallOption
58 ReactivateConfiguration []gax.CallOption
59 QueryConfigurationLicenseUsage []gax.CallOption
60 AggregateUsage []gax.CallOption
61 ListProducts []gax.CallOption
62 GetProduct []gax.CallOption
63 GetLocation []gax.CallOption
64 ListLocations []gax.CallOption
65 CancelOperation []gax.CallOption
66 DeleteOperation []gax.CallOption
67 GetOperation []gax.CallOption
68 ListOperations []gax.CallOption
69 }
70
71 func defaultGRPCClientOptions() []option.ClientOption {
72 return []option.ClientOption{
73 internaloption.WithDefaultEndpoint("licensemanager.googleapis.com:443"),
74 internaloption.WithDefaultEndpointTemplate("licensemanager.UNIVERSE_DOMAIN:443"),
75 internaloption.WithDefaultMTLSEndpoint("licensemanager.mtls.googleapis.com:443"),
76 internaloption.WithDefaultUniverseDomain("googleapis.com"),
77 internaloption.WithDefaultAudience("https://licensemanager.googleapis.com/"),
78 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
79 internaloption.EnableJwtWithScope(),
80 internaloption.EnableNewAuthLibrary(),
81 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
82 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
83 }
84 }
85
86 func defaultCallOptions() *CallOptions {
87 return &CallOptions{
88 ListConfigurations: []gax.CallOption{
89 gax.WithTimeout(60000 * time.Millisecond),
90 gax.WithRetry(func() gax.Retryer {
91 return gax.OnCodes([]codes.Code{
92 codes.Unavailable,
93 }, gax.Backoff{
94 Initial: 1000 * time.Millisecond,
95 Max: 10000 * time.Millisecond,
96 Multiplier: 1.30,
97 })
98 }),
99 },
100 GetConfiguration: []gax.CallOption{
101 gax.WithTimeout(60000 * time.Millisecond),
102 gax.WithRetry(func() gax.Retryer {
103 return gax.OnCodes([]codes.Code{
104 codes.Unavailable,
105 }, gax.Backoff{
106 Initial: 1000 * time.Millisecond,
107 Max: 10000 * time.Millisecond,
108 Multiplier: 1.30,
109 })
110 }),
111 },
112 CreateConfiguration: []gax.CallOption{
113 gax.WithTimeout(60000 * time.Millisecond),
114 },
115 UpdateConfiguration: []gax.CallOption{
116 gax.WithTimeout(60000 * time.Millisecond),
117 },
118 DeleteConfiguration: []gax.CallOption{
119 gax.WithTimeout(60000 * time.Millisecond),
120 },
121 ListInstances: []gax.CallOption{
122 gax.WithTimeout(60000 * time.Millisecond),
123 gax.WithRetry(func() gax.Retryer {
124 return gax.OnCodes([]codes.Code{
125 codes.Unavailable,
126 }, gax.Backoff{
127 Initial: 1000 * time.Millisecond,
128 Max: 10000 * time.Millisecond,
129 Multiplier: 1.30,
130 })
131 }),
132 },
133 GetInstance: []gax.CallOption{
134 gax.WithTimeout(60000 * time.Millisecond),
135 gax.WithRetry(func() gax.Retryer {
136 return gax.OnCodes([]codes.Code{
137 codes.Unavailable,
138 }, gax.Backoff{
139 Initial: 1000 * time.Millisecond,
140 Max: 10000 * time.Millisecond,
141 Multiplier: 1.30,
142 })
143 }),
144 },
145 DeactivateConfiguration: []gax.CallOption{},
146 ReactivateConfiguration: []gax.CallOption{},
147 QueryConfigurationLicenseUsage: []gax.CallOption{
148 gax.WithTimeout(60000 * time.Millisecond),
149 gax.WithRetry(func() gax.Retryer {
150 return gax.OnCodes([]codes.Code{
151 codes.Unavailable,
152 }, gax.Backoff{
153 Initial: 1000 * time.Millisecond,
154 Max: 10000 * time.Millisecond,
155 Multiplier: 1.30,
156 })
157 }),
158 },
159 AggregateUsage: []gax.CallOption{
160 gax.WithTimeout(60000 * time.Millisecond),
161 },
162 ListProducts: []gax.CallOption{
163 gax.WithTimeout(60000 * time.Millisecond),
164 gax.WithRetry(func() gax.Retryer {
165 return gax.OnCodes([]codes.Code{
166 codes.Unavailable,
167 }, gax.Backoff{
168 Initial: 1000 * time.Millisecond,
169 Max: 10000 * time.Millisecond,
170 Multiplier: 1.30,
171 })
172 }),
173 },
174 GetProduct: []gax.CallOption{
175 gax.WithTimeout(60000 * time.Millisecond),
176 gax.WithRetry(func() gax.Retryer {
177 return gax.OnCodes([]codes.Code{
178 codes.Unavailable,
179 }, gax.Backoff{
180 Initial: 1000 * time.Millisecond,
181 Max: 10000 * time.Millisecond,
182 Multiplier: 1.30,
183 })
184 }),
185 },
186 GetLocation: []gax.CallOption{},
187 ListLocations: []gax.CallOption{},
188 CancelOperation: []gax.CallOption{},
189 DeleteOperation: []gax.CallOption{},
190 GetOperation: []gax.CallOption{},
191 ListOperations: []gax.CallOption{},
192 }
193 }
194
195 func defaultRESTCallOptions() *CallOptions {
196 return &CallOptions{
197 ListConfigurations: []gax.CallOption{
198 gax.WithTimeout(60000 * time.Millisecond),
199 gax.WithRetry(func() gax.Retryer {
200 return gax.OnHTTPCodes(gax.Backoff{
201 Initial: 1000 * time.Millisecond,
202 Max: 10000 * time.Millisecond,
203 Multiplier: 1.30,
204 },
205 http.StatusServiceUnavailable)
206 }),
207 },
208 GetConfiguration: []gax.CallOption{
209 gax.WithTimeout(60000 * time.Millisecond),
210 gax.WithRetry(func() gax.Retryer {
211 return gax.OnHTTPCodes(gax.Backoff{
212 Initial: 1000 * time.Millisecond,
213 Max: 10000 * time.Millisecond,
214 Multiplier: 1.30,
215 },
216 http.StatusServiceUnavailable)
217 }),
218 },
219 CreateConfiguration: []gax.CallOption{
220 gax.WithTimeout(60000 * time.Millisecond),
221 },
222 UpdateConfiguration: []gax.CallOption{
223 gax.WithTimeout(60000 * time.Millisecond),
224 },
225 DeleteConfiguration: []gax.CallOption{
226 gax.WithTimeout(60000 * time.Millisecond),
227 },
228 ListInstances: []gax.CallOption{
229 gax.WithTimeout(60000 * time.Millisecond),
230 gax.WithRetry(func() gax.Retryer {
231 return gax.OnHTTPCodes(gax.Backoff{
232 Initial: 1000 * time.Millisecond,
233 Max: 10000 * time.Millisecond,
234 Multiplier: 1.30,
235 },
236 http.StatusServiceUnavailable)
237 }),
238 },
239 GetInstance: []gax.CallOption{
240 gax.WithTimeout(60000 * time.Millisecond),
241 gax.WithRetry(func() gax.Retryer {
242 return gax.OnHTTPCodes(gax.Backoff{
243 Initial: 1000 * time.Millisecond,
244 Max: 10000 * time.Millisecond,
245 Multiplier: 1.30,
246 },
247 http.StatusServiceUnavailable)
248 }),
249 },
250 DeactivateConfiguration: []gax.CallOption{},
251 ReactivateConfiguration: []gax.CallOption{},
252 QueryConfigurationLicenseUsage: []gax.CallOption{
253 gax.WithTimeout(60000 * time.Millisecond),
254 gax.WithRetry(func() gax.Retryer {
255 return gax.OnHTTPCodes(gax.Backoff{
256 Initial: 1000 * time.Millisecond,
257 Max: 10000 * time.Millisecond,
258 Multiplier: 1.30,
259 },
260 http.StatusServiceUnavailable)
261 }),
262 },
263 AggregateUsage: []gax.CallOption{
264 gax.WithTimeout(60000 * time.Millisecond),
265 },
266 ListProducts: []gax.CallOption{
267 gax.WithTimeout(60000 * time.Millisecond),
268 gax.WithRetry(func() gax.Retryer {
269 return gax.OnHTTPCodes(gax.Backoff{
270 Initial: 1000 * time.Millisecond,
271 Max: 10000 * time.Millisecond,
272 Multiplier: 1.30,
273 },
274 http.StatusServiceUnavailable)
275 }),
276 },
277 GetProduct: []gax.CallOption{
278 gax.WithTimeout(60000 * time.Millisecond),
279 gax.WithRetry(func() gax.Retryer {
280 return gax.OnHTTPCodes(gax.Backoff{
281 Initial: 1000 * time.Millisecond,
282 Max: 10000 * time.Millisecond,
283 Multiplier: 1.30,
284 },
285 http.StatusServiceUnavailable)
286 }),
287 },
288 GetLocation: []gax.CallOption{},
289 ListLocations: []gax.CallOption{},
290 CancelOperation: []gax.CallOption{},
291 DeleteOperation: []gax.CallOption{},
292 GetOperation: []gax.CallOption{},
293 ListOperations: []gax.CallOption{},
294 }
295 }
296
297 // internalClient is an interface that defines the methods available from License Manager API.
298 type internalClient interface {
299 Close() error
300 setGoogleClientInfo(...string)
301 Connection() *grpc.ClientConn
302 ListConfigurations(context.Context, *licensemanagerpb.ListConfigurationsRequest, ...gax.CallOption) *ConfigurationIterator
303 GetConfiguration(context.Context, *licensemanagerpb.GetConfigurationRequest, ...gax.CallOption) (*licensemanagerpb.Configuration, error)
304 CreateConfiguration(context.Context, *licensemanagerpb.CreateConfigurationRequest, ...gax.CallOption) (*CreateConfigurationOperation, error)
305 CreateConfigurationOperation(name string) *CreateConfigurationOperation
306 UpdateConfiguration(context.Context, *licensemanagerpb.UpdateConfigurationRequest, ...gax.CallOption) (*UpdateConfigurationOperation, error)
307 UpdateConfigurationOperation(name string) *UpdateConfigurationOperation
308 DeleteConfiguration(context.Context, *licensemanagerpb.DeleteConfigurationRequest, ...gax.CallOption) (*DeleteConfigurationOperation, error)
309 DeleteConfigurationOperation(name string) *DeleteConfigurationOperation
310 ListInstances(context.Context, *licensemanagerpb.ListInstancesRequest, ...gax.CallOption) *InstanceIterator
311 GetInstance(context.Context, *licensemanagerpb.GetInstanceRequest, ...gax.CallOption) (*licensemanagerpb.Instance, error)
312 DeactivateConfiguration(context.Context, *licensemanagerpb.DeactivateConfigurationRequest, ...gax.CallOption) (*DeactivateConfigurationOperation, error)
313 DeactivateConfigurationOperation(name string) *DeactivateConfigurationOperation
314 ReactivateConfiguration(context.Context, *licensemanagerpb.ReactivateConfigurationRequest, ...gax.CallOption) (*ReactivateConfigurationOperation, error)
315 ReactivateConfigurationOperation(name string) *ReactivateConfigurationOperation
316 QueryConfigurationLicenseUsage(context.Context, *licensemanagerpb.QueryConfigurationLicenseUsageRequest, ...gax.CallOption) (*licensemanagerpb.QueryConfigurationLicenseUsageResponse, error)
317 AggregateUsage(context.Context, *licensemanagerpb.AggregateUsageRequest, ...gax.CallOption) *UsageIterator
318 ListProducts(context.Context, *licensemanagerpb.ListProductsRequest, ...gax.CallOption) *ProductIterator
319 GetProduct(context.Context, *licensemanagerpb.GetProductRequest, ...gax.CallOption) (*licensemanagerpb.Product, error)
320 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error)
321 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator
322 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
323 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
324 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
325 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
326 }
327
328 // Client is a client for interacting with License Manager API.
329 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
330 //
331 // Service describing handlers for resources
332 type Client struct {
333 // The internal transport-dependent client.
334 internalClient internalClient
335
336 // The call options for this service.
337 CallOptions *CallOptions
338
339 // LROClient is used internally to handle long-running operations.
340 // It is exposed so that its CallOptions can be modified if required.
341 // Users should not Close this client.
342 LROClient *lroauto.OperationsClient
343 }
344
345 // Wrapper methods routed to the internal client.
346
347 // Close closes the connection to the API service. The user should invoke this when
348 // the client is no longer required.
349 func (c *Client) Close() error {
350 return c.internalClient.Close()
351 }
352
353 // setGoogleClientInfo sets the name and version of the application in
354 // the `x-goog-api-client` header passed on each request. Intended for
355 // use by Google-written clients.
356 func (c *Client) setGoogleClientInfo(keyval ...string) {
357 c.internalClient.setGoogleClientInfo(keyval...)
358 }
359
360 // Connection returns a connection to the API service.
361 //
362 // Deprecated: Connections are now pooled so this method does not always
363 // return the same resource.
364 func (c *Client) Connection() *grpc.ClientConn {
365 return c.internalClient.Connection()
366 }
367
368 // ListConfigurations lists Configurations in a given project and location.
369 func (c *Client) ListConfigurations(ctx context.Context, req *licensemanagerpb.ListConfigurationsRequest, opts ...gax.CallOption) *ConfigurationIterator {
370 return c.internalClient.ListConfigurations(ctx, req, opts...)
371 }
372
373 // GetConfiguration gets details of a single Configuration.
374 func (c *Client) GetConfiguration(ctx context.Context, req *licensemanagerpb.GetConfigurationRequest, opts ...gax.CallOption) (*licensemanagerpb.Configuration, error) {
375 return c.internalClient.GetConfiguration(ctx, req, opts...)
376 }
377
378 // CreateConfiguration creates a new Configuration in a given project and location.
379 func (c *Client) CreateConfiguration(ctx context.Context, req *licensemanagerpb.CreateConfigurationRequest, opts ...gax.CallOption) (*CreateConfigurationOperation, error) {
380 return c.internalClient.CreateConfiguration(ctx, req, opts...)
381 }
382
383 // CreateConfigurationOperation returns a new CreateConfigurationOperation from a given name.
384 // The name must be that of a previously created CreateConfigurationOperation, possibly from a different process.
385 func (c *Client) CreateConfigurationOperation(name string) *CreateConfigurationOperation {
386 return c.internalClient.CreateConfigurationOperation(name)
387 }
388
389 // UpdateConfiguration updates the parameters of a single Configuration.
390 func (c *Client) UpdateConfiguration(ctx context.Context, req *licensemanagerpb.UpdateConfigurationRequest, opts ...gax.CallOption) (*UpdateConfigurationOperation, error) {
391 return c.internalClient.UpdateConfiguration(ctx, req, opts...)
392 }
393
394 // UpdateConfigurationOperation returns a new UpdateConfigurationOperation from a given name.
395 // The name must be that of a previously created UpdateConfigurationOperation, possibly from a different process.
396 func (c *Client) UpdateConfigurationOperation(name string) *UpdateConfigurationOperation {
397 return c.internalClient.UpdateConfigurationOperation(name)
398 }
399
400 // DeleteConfiguration deletes a single Configuration.
401 func (c *Client) DeleteConfiguration(ctx context.Context, req *licensemanagerpb.DeleteConfigurationRequest, opts ...gax.CallOption) (*DeleteConfigurationOperation, error) {
402 return c.internalClient.DeleteConfiguration(ctx, req, opts...)
403 }
404
405 // DeleteConfigurationOperation returns a new DeleteConfigurationOperation from a given name.
406 // The name must be that of a previously created DeleteConfigurationOperation, possibly from a different process.
407 func (c *Client) DeleteConfigurationOperation(name string) *DeleteConfigurationOperation {
408 return c.internalClient.DeleteConfigurationOperation(name)
409 }
410
411 // ListInstances lists Instances in a given project and location.
412 func (c *Client) ListInstances(ctx context.Context, req *licensemanagerpb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator {
413 return c.internalClient.ListInstances(ctx, req, opts...)
414 }
415
416 // GetInstance gets details of a single Instance.
417 func (c *Client) GetInstance(ctx context.Context, req *licensemanagerpb.GetInstanceRequest, opts ...gax.CallOption) (*licensemanagerpb.Instance, error) {
418 return c.internalClient.GetInstance(ctx, req, opts...)
419 }
420
421 // DeactivateConfiguration deactivates the given configuration.
422 func (c *Client) DeactivateConfiguration(ctx context.Context, req *licensemanagerpb.DeactivateConfigurationRequest, opts ...gax.CallOption) (*DeactivateConfigurationOperation, error) {
423 return c.internalClient.DeactivateConfiguration(ctx, req, opts...)
424 }
425
426 // DeactivateConfigurationOperation returns a new DeactivateConfigurationOperation from a given name.
427 // The name must be that of a previously created DeactivateConfigurationOperation, possibly from a different process.
428 func (c *Client) DeactivateConfigurationOperation(name string) *DeactivateConfigurationOperation {
429 return c.internalClient.DeactivateConfigurationOperation(name)
430 }
431
432 // ReactivateConfiguration reactivates the given configuration.
433 func (c *Client) ReactivateConfiguration(ctx context.Context, req *licensemanagerpb.ReactivateConfigurationRequest, opts ...gax.CallOption) (*ReactivateConfigurationOperation, error) {
434 return c.internalClient.ReactivateConfiguration(ctx, req, opts...)
435 }
436
437 // ReactivateConfigurationOperation returns a new ReactivateConfigurationOperation from a given name.
438 // The name must be that of a previously created ReactivateConfigurationOperation, possibly from a different process.
439 func (c *Client) ReactivateConfigurationOperation(name string) *ReactivateConfigurationOperation {
440 return c.internalClient.ReactivateConfigurationOperation(name)
441 }
442
443 // QueryConfigurationLicenseUsage license Usage information for a Configuration.
444 func (c *Client) QueryConfigurationLicenseUsage(ctx context.Context, req *licensemanagerpb.QueryConfigurationLicenseUsageRequest, opts ...gax.CallOption) (*licensemanagerpb.QueryConfigurationLicenseUsageResponse, error) {
445 return c.internalClient.QueryConfigurationLicenseUsage(ctx, req, opts...)
446 }
447
448 // AggregateUsage aggregates Usage per Instance for a Configuration.
449 func (c *Client) AggregateUsage(ctx context.Context, req *licensemanagerpb.AggregateUsageRequest, opts ...gax.CallOption) *UsageIterator {
450 return c.internalClient.AggregateUsage(ctx, req, opts...)
451 }
452
453 // ListProducts lists Products in a given project and location.
454 func (c *Client) ListProducts(ctx context.Context, req *licensemanagerpb.ListProductsRequest, opts ...gax.CallOption) *ProductIterator {
455 return c.internalClient.ListProducts(ctx, req, opts...)
456 }
457
458 // GetProduct gets details of a single Product.
459 func (c *Client) GetProduct(ctx context.Context, req *licensemanagerpb.GetProductRequest, opts ...gax.CallOption) (*licensemanagerpb.Product, error) {
460 return c.internalClient.GetProduct(ctx, req, opts...)
461 }
462
463 // GetLocation gets information about a location.
464 func (c *Client) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
465 return c.internalClient.GetLocation(ctx, req, opts...)
466 }
467
468 // ListLocations lists information about the supported locations for this service.
469 func (c *Client) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
470 return c.internalClient.ListLocations(ctx, req, opts...)
471 }
472
473 // CancelOperation is a utility method from google.longrunning.Operations.
474 func (c *Client) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
475 return c.internalClient.CancelOperation(ctx, req, opts...)
476 }
477
478 // DeleteOperation is a utility method from google.longrunning.Operations.
479 func (c *Client) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
480 return c.internalClient.DeleteOperation(ctx, req, opts...)
481 }
482
483 // GetOperation is a utility method from google.longrunning.Operations.
484 func (c *Client) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
485 return c.internalClient.GetOperation(ctx, req, opts...)
486 }
487
488 // ListOperations is a utility method from google.longrunning.Operations.
489 func (c *Client) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
490 return c.internalClient.ListOperations(ctx, req, opts...)
491 }
492
493 // gRPCClient is a client for interacting with License Manager API over gRPC transport.
494 //
495 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
496 type gRPCClient struct {
497 // Connection pool of gRPC connections to the service.
498 connPool gtransport.ConnPool
499
500 // Points back to the CallOptions field of the containing Client
501 CallOptions **CallOptions
502
503 // The gRPC API client.
504 client licensemanagerpb.LicenseManagerClient
505
506 // LROClient is used internally to handle long-running operations.
507 // It is exposed so that its CallOptions can be modified if required.
508 // Users should not Close this client.
509 LROClient **lroauto.OperationsClient
510
511 operationsClient longrunningpb.OperationsClient
512
513 locationsClient locationpb.LocationsClient
514
515 // The x-goog-* metadata to be sent with each request.
516 xGoogHeaders []string
517
518 logger *slog.Logger
519 }
520
521 // NewClient creates a new license manager client based on gRPC.
522 // The returned client must be Closed when it is done being used to clean up its underlying connections.
523 //
524 // Service describing handlers for resources
525 func NewClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
526 clientOpts := defaultGRPCClientOptions()
527 if newClientHook != nil {
528 hookOpts, err := newClientHook(ctx, clientHookParams{})
529 if err != nil {
530 return nil, err
531 }
532 clientOpts = append(clientOpts, hookOpts...)
533 }
534
535 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
536 if err != nil {
537 return nil, err
538 }
539 client := Client{CallOptions: defaultCallOptions()}
540
541 c := &gRPCClient{
542 connPool: connPool,
543 client: licensemanagerpb.NewLicenseManagerClient(connPool),
544 CallOptions: &client.CallOptions,
545 logger: internaloption.GetLogger(opts),
546 operationsClient: longrunningpb.NewOperationsClient(connPool),
547 locationsClient: locationpb.NewLocationsClient(connPool),
548 }
549 c.setGoogleClientInfo()
550
551 client.internalClient = c
552
553 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
554 if err != nil {
555 // This error "should not happen", since we are just reusing old connection pool
556 // and never actually need to dial.
557 // If this does happen, we could leak connp. However, we cannot close conn:
558 // If the user invoked the constructor with option.WithGRPCConn,
559 // we would close a connection that's still in use.
560 // TODO: investigate error conditions.
561 return nil, err
562 }
563 c.LROClient = &client.LROClient
564 return &client, nil
565 }
566
567 // Connection returns a connection to the API service.
568 //
569 // Deprecated: Connections are now pooled so this method does not always
570 // return the same resource.
571 func (c *gRPCClient) Connection() *grpc.ClientConn {
572 return c.connPool.Conn()
573 }
574
575 // setGoogleClientInfo sets the name and version of the application in
576 // the `x-goog-api-client` header passed on each request. Intended for
577 // use by Google-written clients.
578 func (c *gRPCClient) setGoogleClientInfo(keyval ...string) {
579 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
580 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
581 c.xGoogHeaders = []string{
582 "x-goog-api-client", gax.XGoogHeader(kv...),
583 }
584 }
585
586 // Close closes the connection to the API service. The user should invoke this when
587 // the client is no longer required.
588 func (c *gRPCClient) Close() error {
589 return c.connPool.Close()
590 }
591
592 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
593 type restClient struct {
594 // The http endpoint to connect to.
595 endpoint string
596
597 // The http client.
598 httpClient *http.Client
599
600 // LROClient is used internally to handle long-running operations.
601 // It is exposed so that its CallOptions can be modified if required.
602 // Users should not Close this client.
603 LROClient **lroauto.OperationsClient
604
605 // The x-goog-* headers to be sent with each request.
606 xGoogHeaders []string
607
608 // Points back to the CallOptions field of the containing Client
609 CallOptions **CallOptions
610
611 logger *slog.Logger
612 }
613
614 // NewRESTClient creates a new license manager rest client.
615 //
616 // Service describing handlers for resources
617 func NewRESTClient(ctx context.Context, opts ...option.ClientOption) (*Client, error) {
618 clientOpts := append(defaultRESTClientOptions(), opts...)
619 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
620 if err != nil {
621 return nil, err
622 }
623
624 callOpts := defaultRESTCallOptions()
625 c := &restClient{
626 endpoint: endpoint,
627 httpClient: httpClient,
628 CallOptions: &callOpts,
629 logger: internaloption.GetLogger(opts),
630 }
631 c.setGoogleClientInfo()
632
633 lroOpts := []option.ClientOption{
634 option.WithHTTPClient(httpClient),
635 option.WithEndpoint(endpoint),
636 }
637 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
638 if err != nil {
639 return nil, err
640 }
641 c.LROClient = &opClient
642
643 return &Client{internalClient: c, CallOptions: callOpts}, nil
644 }
645
646 func defaultRESTClientOptions() []option.ClientOption {
647 return []option.ClientOption{
648 internaloption.WithDefaultEndpoint("https://licensemanager.googleapis.com"),
649 internaloption.WithDefaultEndpointTemplate("https://licensemanager.UNIVERSE_DOMAIN"),
650 internaloption.WithDefaultMTLSEndpoint("https://licensemanager.mtls.googleapis.com"),
651 internaloption.WithDefaultUniverseDomain("googleapis.com"),
652 internaloption.WithDefaultAudience("https://licensemanager.googleapis.com/"),
653 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
654 internaloption.EnableNewAuthLibrary(),
655 }
656 }
657
658 // setGoogleClientInfo sets the name and version of the application in
659 // the `x-goog-api-client` header passed on each request. Intended for
660 // use by Google-written clients.
661 func (c *restClient) setGoogleClientInfo(keyval ...string) {
662 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
663 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
664 c.xGoogHeaders = []string{
665 "x-goog-api-client", gax.XGoogHeader(kv...),
666 }
667 }
668
669 // Close closes the connection to the API service. The user should invoke this when
670 // the client is no longer required.
671 func (c *restClient) Close() error {
672 // Replace httpClient with nil to force cleanup.
673 c.httpClient = nil
674 return nil
675 }
676
677 // Connection returns a connection to the API service.
678 //
679 // Deprecated: This method always returns nil.
680 func (c *restClient) Connection() *grpc.ClientConn {
681 return nil
682 }
683 func (c *gRPCClient) ListConfigurations(ctx context.Context, req *licensemanagerpb.ListConfigurationsRequest, opts ...gax.CallOption) *ConfigurationIterator {
684 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
685
686 hds = append(c.xGoogHeaders, hds...)
687 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
688 opts = append((*c.CallOptions).ListConfigurations[0:len((*c.CallOptions).ListConfigurations):len((*c.CallOptions).ListConfigurations)], opts...)
689 it := &ConfigurationIterator{}
690 req = proto.Clone(req).(*licensemanagerpb.ListConfigurationsRequest)
691 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Configuration, string, error) {
692 resp := &licensemanagerpb.ListConfigurationsResponse{}
693 if pageToken != "" {
694 req.PageToken = pageToken
695 }
696 if pageSize > math.MaxInt32 {
697 req.PageSize = math.MaxInt32
698 } else if pageSize != 0 {
699 req.PageSize = int32(pageSize)
700 }
701 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
702 var err error
703 resp, err = executeRPC(ctx, c.client.ListConfigurations, req, settings.GRPC, c.logger, "ListConfigurations")
704 return err
705 }, opts...)
706 if err != nil {
707 return nil, "", err
708 }
709
710 it.Response = resp
711 return resp.GetConfigurations(), resp.GetNextPageToken(), nil
712 }
713 fetch := func(pageSize int, pageToken string) (string, error) {
714 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
715 if err != nil {
716 return "", err
717 }
718 it.items = append(it.items, items...)
719 return nextPageToken, nil
720 }
721
722 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
723 it.pageInfo.MaxSize = int(req.GetPageSize())
724 it.pageInfo.Token = req.GetPageToken()
725
726 return it
727 }
728
729 func (c *gRPCClient) GetConfiguration(ctx context.Context, req *licensemanagerpb.GetConfigurationRequest, opts ...gax.CallOption) (*licensemanagerpb.Configuration, error) {
730 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
731
732 hds = append(c.xGoogHeaders, hds...)
733 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
734 opts = append((*c.CallOptions).GetConfiguration[0:len((*c.CallOptions).GetConfiguration):len((*c.CallOptions).GetConfiguration)], opts...)
735 var resp *licensemanagerpb.Configuration
736 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
737 var err error
738 resp, err = executeRPC(ctx, c.client.GetConfiguration, req, settings.GRPC, c.logger, "GetConfiguration")
739 return err
740 }, opts...)
741 if err != nil {
742 return nil, err
743 }
744 return resp, nil
745 }
746
747 func (c *gRPCClient) CreateConfiguration(ctx context.Context, req *licensemanagerpb.CreateConfigurationRequest, opts ...gax.CallOption) (*CreateConfigurationOperation, error) {
748 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
749
750 hds = append(c.xGoogHeaders, hds...)
751 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
752 opts = append((*c.CallOptions).CreateConfiguration[0:len((*c.CallOptions).CreateConfiguration):len((*c.CallOptions).CreateConfiguration)], opts...)
753 var resp *longrunningpb.Operation
754 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
755 var err error
756 resp, err = executeRPC(ctx, c.client.CreateConfiguration, req, settings.GRPC, c.logger, "CreateConfiguration")
757 return err
758 }, opts...)
759 if err != nil {
760 return nil, err
761 }
762 return &CreateConfigurationOperation{
763 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
764 }, nil
765 }
766
767 func (c *gRPCClient) UpdateConfiguration(ctx context.Context, req *licensemanagerpb.UpdateConfigurationRequest, opts ...gax.CallOption) (*UpdateConfigurationOperation, error) {
768 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "configuration.name", url.QueryEscape(req.GetConfiguration().GetName()))}
769
770 hds = append(c.xGoogHeaders, hds...)
771 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
772 opts = append((*c.CallOptions).UpdateConfiguration[0:len((*c.CallOptions).UpdateConfiguration):len((*c.CallOptions).UpdateConfiguration)], opts...)
773 var resp *longrunningpb.Operation
774 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
775 var err error
776 resp, err = executeRPC(ctx, c.client.UpdateConfiguration, req, settings.GRPC, c.logger, "UpdateConfiguration")
777 return err
778 }, opts...)
779 if err != nil {
780 return nil, err
781 }
782 return &UpdateConfigurationOperation{
783 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
784 }, nil
785 }
786
787 func (c *gRPCClient) DeleteConfiguration(ctx context.Context, req *licensemanagerpb.DeleteConfigurationRequest, opts ...gax.CallOption) (*DeleteConfigurationOperation, error) {
788 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
789
790 hds = append(c.xGoogHeaders, hds...)
791 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
792 opts = append((*c.CallOptions).DeleteConfiguration[0:len((*c.CallOptions).DeleteConfiguration):len((*c.CallOptions).DeleteConfiguration)], opts...)
793 var resp *longrunningpb.Operation
794 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
795 var err error
796 resp, err = executeRPC(ctx, c.client.DeleteConfiguration, req, settings.GRPC, c.logger, "DeleteConfiguration")
797 return err
798 }, opts...)
799 if err != nil {
800 return nil, err
801 }
802 return &DeleteConfigurationOperation{
803 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
804 }, nil
805 }
806
807 func (c *gRPCClient) ListInstances(ctx context.Context, req *licensemanagerpb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator {
808 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
809
810 hds = append(c.xGoogHeaders, hds...)
811 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
812 opts = append((*c.CallOptions).ListInstances[0:len((*c.CallOptions).ListInstances):len((*c.CallOptions).ListInstances)], opts...)
813 it := &InstanceIterator{}
814 req = proto.Clone(req).(*licensemanagerpb.ListInstancesRequest)
815 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Instance, string, error) {
816 resp := &licensemanagerpb.ListInstancesResponse{}
817 if pageToken != "" {
818 req.PageToken = pageToken
819 }
820 if pageSize > math.MaxInt32 {
821 req.PageSize = math.MaxInt32
822 } else if pageSize != 0 {
823 req.PageSize = int32(pageSize)
824 }
825 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
826 var err error
827 resp, err = executeRPC(ctx, c.client.ListInstances, req, settings.GRPC, c.logger, "ListInstances")
828 return err
829 }, opts...)
830 if err != nil {
831 return nil, "", err
832 }
833
834 it.Response = resp
835 return resp.GetInstances(), resp.GetNextPageToken(), nil
836 }
837 fetch := func(pageSize int, pageToken string) (string, error) {
838 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
839 if err != nil {
840 return "", err
841 }
842 it.items = append(it.items, items...)
843 return nextPageToken, nil
844 }
845
846 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
847 it.pageInfo.MaxSize = int(req.GetPageSize())
848 it.pageInfo.Token = req.GetPageToken()
849
850 return it
851 }
852
853 func (c *gRPCClient) GetInstance(ctx context.Context, req *licensemanagerpb.GetInstanceRequest, opts ...gax.CallOption) (*licensemanagerpb.Instance, error) {
854 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
855
856 hds = append(c.xGoogHeaders, hds...)
857 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
858 opts = append((*c.CallOptions).GetInstance[0:len((*c.CallOptions).GetInstance):len((*c.CallOptions).GetInstance)], opts...)
859 var resp *licensemanagerpb.Instance
860 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
861 var err error
862 resp, err = executeRPC(ctx, c.client.GetInstance, req, settings.GRPC, c.logger, "GetInstance")
863 return err
864 }, opts...)
865 if err != nil {
866 return nil, err
867 }
868 return resp, nil
869 }
870
871 func (c *gRPCClient) DeactivateConfiguration(ctx context.Context, req *licensemanagerpb.DeactivateConfigurationRequest, opts ...gax.CallOption) (*DeactivateConfigurationOperation, error) {
872 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
873
874 hds = append(c.xGoogHeaders, hds...)
875 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
876 opts = append((*c.CallOptions).DeactivateConfiguration[0:len((*c.CallOptions).DeactivateConfiguration):len((*c.CallOptions).DeactivateConfiguration)], opts...)
877 var resp *longrunningpb.Operation
878 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
879 var err error
880 resp, err = executeRPC(ctx, c.client.DeactivateConfiguration, req, settings.GRPC, c.logger, "DeactivateConfiguration")
881 return err
882 }, opts...)
883 if err != nil {
884 return nil, err
885 }
886 return &DeactivateConfigurationOperation{
887 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
888 }, nil
889 }
890
891 func (c *gRPCClient) ReactivateConfiguration(ctx context.Context, req *licensemanagerpb.ReactivateConfigurationRequest, opts ...gax.CallOption) (*ReactivateConfigurationOperation, error) {
892 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
893
894 hds = append(c.xGoogHeaders, hds...)
895 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
896 opts = append((*c.CallOptions).ReactivateConfiguration[0:len((*c.CallOptions).ReactivateConfiguration):len((*c.CallOptions).ReactivateConfiguration)], opts...)
897 var resp *longrunningpb.Operation
898 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
899 var err error
900 resp, err = executeRPC(ctx, c.client.ReactivateConfiguration, req, settings.GRPC, c.logger, "ReactivateConfiguration")
901 return err
902 }, opts...)
903 if err != nil {
904 return nil, err
905 }
906 return &ReactivateConfigurationOperation{
907 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
908 }, nil
909 }
910
911 func (c *gRPCClient) QueryConfigurationLicenseUsage(ctx context.Context, req *licensemanagerpb.QueryConfigurationLicenseUsageRequest, opts ...gax.CallOption) (*licensemanagerpb.QueryConfigurationLicenseUsageResponse, error) {
912 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
913
914 hds = append(c.xGoogHeaders, hds...)
915 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
916 opts = append((*c.CallOptions).QueryConfigurationLicenseUsage[0:len((*c.CallOptions).QueryConfigurationLicenseUsage):len((*c.CallOptions).QueryConfigurationLicenseUsage)], opts...)
917 var resp *licensemanagerpb.QueryConfigurationLicenseUsageResponse
918 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
919 var err error
920 resp, err = executeRPC(ctx, c.client.QueryConfigurationLicenseUsage, req, settings.GRPC, c.logger, "QueryConfigurationLicenseUsage")
921 return err
922 }, opts...)
923 if err != nil {
924 return nil, err
925 }
926 return resp, nil
927 }
928
929 func (c *gRPCClient) AggregateUsage(ctx context.Context, req *licensemanagerpb.AggregateUsageRequest, opts ...gax.CallOption) *UsageIterator {
930 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
931
932 hds = append(c.xGoogHeaders, hds...)
933 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
934 opts = append((*c.CallOptions).AggregateUsage[0:len((*c.CallOptions).AggregateUsage):len((*c.CallOptions).AggregateUsage)], opts...)
935 it := &UsageIterator{}
936 req = proto.Clone(req).(*licensemanagerpb.AggregateUsageRequest)
937 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Usage, string, error) {
938 resp := &licensemanagerpb.AggregateUsageResponse{}
939 if pageToken != "" {
940 req.PageToken = pageToken
941 }
942 if pageSize > math.MaxInt32 {
943 req.PageSize = math.MaxInt32
944 } else if pageSize != 0 {
945 req.PageSize = int32(pageSize)
946 }
947 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
948 var err error
949 resp, err = executeRPC(ctx, c.client.AggregateUsage, req, settings.GRPC, c.logger, "AggregateUsage")
950 return err
951 }, opts...)
952 if err != nil {
953 return nil, "", err
954 }
955
956 it.Response = resp
957 return resp.GetUsages(), resp.GetNextPageToken(), nil
958 }
959 fetch := func(pageSize int, pageToken string) (string, error) {
960 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
961 if err != nil {
962 return "", err
963 }
964 it.items = append(it.items, items...)
965 return nextPageToken, nil
966 }
967
968 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
969 it.pageInfo.MaxSize = int(req.GetPageSize())
970 it.pageInfo.Token = req.GetPageToken()
971
972 return it
973 }
974
975 func (c *gRPCClient) ListProducts(ctx context.Context, req *licensemanagerpb.ListProductsRequest, opts ...gax.CallOption) *ProductIterator {
976 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
977
978 hds = append(c.xGoogHeaders, hds...)
979 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
980 opts = append((*c.CallOptions).ListProducts[0:len((*c.CallOptions).ListProducts):len((*c.CallOptions).ListProducts)], opts...)
981 it := &ProductIterator{}
982 req = proto.Clone(req).(*licensemanagerpb.ListProductsRequest)
983 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Product, string, error) {
984 resp := &licensemanagerpb.ListProductsResponse{}
985 if pageToken != "" {
986 req.PageToken = pageToken
987 }
988 if pageSize > math.MaxInt32 {
989 req.PageSize = math.MaxInt32
990 } else if pageSize != 0 {
991 req.PageSize = int32(pageSize)
992 }
993 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
994 var err error
995 resp, err = executeRPC(ctx, c.client.ListProducts, req, settings.GRPC, c.logger, "ListProducts")
996 return err
997 }, opts...)
998 if err != nil {
999 return nil, "", err
1000 }
1001
1002 it.Response = resp
1003 return resp.GetProducts(), resp.GetNextPageToken(), nil
1004 }
1005 fetch := func(pageSize int, pageToken string) (string, error) {
1006 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1007 if err != nil {
1008 return "", err
1009 }
1010 it.items = append(it.items, items...)
1011 return nextPageToken, nil
1012 }
1013
1014 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1015 it.pageInfo.MaxSize = int(req.GetPageSize())
1016 it.pageInfo.Token = req.GetPageToken()
1017
1018 return it
1019 }
1020
1021 func (c *gRPCClient) GetProduct(ctx context.Context, req *licensemanagerpb.GetProductRequest, opts ...gax.CallOption) (*licensemanagerpb.Product, error) {
1022 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1023
1024 hds = append(c.xGoogHeaders, hds...)
1025 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1026 opts = append((*c.CallOptions).GetProduct[0:len((*c.CallOptions).GetProduct):len((*c.CallOptions).GetProduct)], opts...)
1027 var resp *licensemanagerpb.Product
1028 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1029 var err error
1030 resp, err = executeRPC(ctx, c.client.GetProduct, req, settings.GRPC, c.logger, "GetProduct")
1031 return err
1032 }, opts...)
1033 if err != nil {
1034 return nil, err
1035 }
1036 return resp, nil
1037 }
1038
1039 func (c *gRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
1040 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1041
1042 hds = append(c.xGoogHeaders, hds...)
1043 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1044 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
1045 var resp *locationpb.Location
1046 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1047 var err error
1048 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation")
1049 return err
1050 }, opts...)
1051 if err != nil {
1052 return nil, err
1053 }
1054 return resp, nil
1055 }
1056
1057 func (c *gRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
1058 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1059
1060 hds = append(c.xGoogHeaders, hds...)
1061 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1062 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...)
1063 it := &LocationIterator{}
1064 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
1065 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
1066 resp := &locationpb.ListLocationsResponse{}
1067 if pageToken != "" {
1068 req.PageToken = pageToken
1069 }
1070 if pageSize > math.MaxInt32 {
1071 req.PageSize = math.MaxInt32
1072 } else if pageSize != 0 {
1073 req.PageSize = int32(pageSize)
1074 }
1075 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1076 var err error
1077 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations")
1078 return err
1079 }, opts...)
1080 if err != nil {
1081 return nil, "", err
1082 }
1083
1084 it.Response = resp
1085 return resp.GetLocations(), resp.GetNextPageToken(), nil
1086 }
1087 fetch := func(pageSize int, pageToken string) (string, error) {
1088 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1089 if err != nil {
1090 return "", err
1091 }
1092 it.items = append(it.items, items...)
1093 return nextPageToken, nil
1094 }
1095
1096 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1097 it.pageInfo.MaxSize = int(req.GetPageSize())
1098 it.pageInfo.Token = req.GetPageToken()
1099
1100 return it
1101 }
1102
1103 func (c *gRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
1104 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1105
1106 hds = append(c.xGoogHeaders, hds...)
1107 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1108 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
1109 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1110 var err error
1111 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
1112 return err
1113 }, opts...)
1114 return err
1115 }
1116
1117 func (c *gRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
1118 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1119
1120 hds = append(c.xGoogHeaders, hds...)
1121 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1122 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
1123 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1124 var err error
1125 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
1126 return err
1127 }, opts...)
1128 return err
1129 }
1130
1131 func (c *gRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
1132 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1133
1134 hds = append(c.xGoogHeaders, hds...)
1135 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1136 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
1137 var resp *longrunningpb.Operation
1138 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1139 var err error
1140 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
1141 return err
1142 }, opts...)
1143 if err != nil {
1144 return nil, err
1145 }
1146 return resp, nil
1147 }
1148
1149 func (c *gRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
1150 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1151
1152 hds = append(c.xGoogHeaders, hds...)
1153 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
1154 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
1155 it := &OperationIterator{}
1156 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
1157 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
1158 resp := &longrunningpb.ListOperationsResponse{}
1159 if pageToken != "" {
1160 req.PageToken = pageToken
1161 }
1162 if pageSize > math.MaxInt32 {
1163 req.PageSize = math.MaxInt32
1164 } else if pageSize != 0 {
1165 req.PageSize = int32(pageSize)
1166 }
1167 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1168 var err error
1169 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
1170 return err
1171 }, opts...)
1172 if err != nil {
1173 return nil, "", err
1174 }
1175
1176 it.Response = resp
1177 return resp.GetOperations(), resp.GetNextPageToken(), nil
1178 }
1179 fetch := func(pageSize int, pageToken string) (string, error) {
1180 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1181 if err != nil {
1182 return "", err
1183 }
1184 it.items = append(it.items, items...)
1185 return nextPageToken, nil
1186 }
1187
1188 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1189 it.pageInfo.MaxSize = int(req.GetPageSize())
1190 it.pageInfo.Token = req.GetPageToken()
1191
1192 return it
1193 }
1194
1195 // ListConfigurations lists Configurations in a given project and location.
1196 func (c *restClient) ListConfigurations(ctx context.Context, req *licensemanagerpb.ListConfigurationsRequest, opts ...gax.CallOption) *ConfigurationIterator {
1197 it := &ConfigurationIterator{}
1198 req = proto.Clone(req).(*licensemanagerpb.ListConfigurationsRequest)
1199 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1200 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Configuration, string, error) {
1201 resp := &licensemanagerpb.ListConfigurationsResponse{}
1202 if pageToken != "" {
1203 req.PageToken = pageToken
1204 }
1205 if pageSize > math.MaxInt32 {
1206 req.PageSize = math.MaxInt32
1207 } else if pageSize != 0 {
1208 req.PageSize = int32(pageSize)
1209 }
1210 baseUrl, err := url.Parse(c.endpoint)
1211 if err != nil {
1212 return nil, "", err
1213 }
1214 baseUrl.Path += fmt.Sprintf("/v1/%v/configurations", req.GetParent())
1215
1216 params := url.Values{}
1217 params.Add("$alt", "json;enum-encoding=int")
1218 if req.GetFilter() != "" {
1219 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1220 }
1221 if req.GetOrderBy() != "" {
1222 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
1223 }
1224 if req.GetPageSize() != 0 {
1225 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1226 }
1227 if req.GetPageToken() != "" {
1228 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1229 }
1230
1231 baseUrl.RawQuery = params.Encode()
1232
1233 // Build HTTP headers from client and context metadata.
1234 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1235 headers := gax.BuildHeaders(ctx, hds...)
1236 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1237 if settings.Path != "" {
1238 baseUrl.Path = settings.Path
1239 }
1240 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1241 if err != nil {
1242 return err
1243 }
1244 httpReq.Header = headers
1245
1246 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListConfigurations")
1247 if err != nil {
1248 return err
1249 }
1250 if err := unm.Unmarshal(buf, resp); err != nil {
1251 return err
1252 }
1253
1254 return nil
1255 }, opts...)
1256 if e != nil {
1257 return nil, "", e
1258 }
1259 it.Response = resp
1260 return resp.GetConfigurations(), resp.GetNextPageToken(), nil
1261 }
1262
1263 fetch := func(pageSize int, pageToken string) (string, error) {
1264 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1265 if err != nil {
1266 return "", err
1267 }
1268 it.items = append(it.items, items...)
1269 return nextPageToken, nil
1270 }
1271
1272 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1273 it.pageInfo.MaxSize = int(req.GetPageSize())
1274 it.pageInfo.Token = req.GetPageToken()
1275
1276 return it
1277 }
1278
1279 // GetConfiguration gets details of a single Configuration.
1280 func (c *restClient) GetConfiguration(ctx context.Context, req *licensemanagerpb.GetConfigurationRequest, opts ...gax.CallOption) (*licensemanagerpb.Configuration, error) {
1281 baseUrl, err := url.Parse(c.endpoint)
1282 if err != nil {
1283 return nil, err
1284 }
1285 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1286
1287 params := url.Values{}
1288 params.Add("$alt", "json;enum-encoding=int")
1289
1290 baseUrl.RawQuery = params.Encode()
1291
1292 // Build HTTP headers from client and context metadata.
1293 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1294
1295 hds = append(c.xGoogHeaders, hds...)
1296 hds = append(hds, "Content-Type", "application/json")
1297 headers := gax.BuildHeaders(ctx, hds...)
1298 opts = append((*c.CallOptions).GetConfiguration[0:len((*c.CallOptions).GetConfiguration):len((*c.CallOptions).GetConfiguration)], opts...)
1299 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1300 resp := &licensemanagerpb.Configuration{}
1301 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1302 if settings.Path != "" {
1303 baseUrl.Path = settings.Path
1304 }
1305 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1306 if err != nil {
1307 return err
1308 }
1309 httpReq = httpReq.WithContext(ctx)
1310 httpReq.Header = headers
1311
1312 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetConfiguration")
1313 if err != nil {
1314 return err
1315 }
1316
1317 if err := unm.Unmarshal(buf, resp); err != nil {
1318 return err
1319 }
1320
1321 return nil
1322 }, opts...)
1323 if e != nil {
1324 return nil, e
1325 }
1326 return resp, nil
1327 }
1328
1329 // CreateConfiguration creates a new Configuration in a given project and location.
1330 func (c *restClient) CreateConfiguration(ctx context.Context, req *licensemanagerpb.CreateConfigurationRequest, opts ...gax.CallOption) (*CreateConfigurationOperation, error) {
1331 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1332 body := req.GetConfiguration()
1333 jsonReq, err := m.Marshal(body)
1334 if err != nil {
1335 return nil, err
1336 }
1337
1338 baseUrl, err := url.Parse(c.endpoint)
1339 if err != nil {
1340 return nil, err
1341 }
1342 baseUrl.Path += fmt.Sprintf("/v1/%v/configurations", req.GetParent())
1343
1344 params := url.Values{}
1345 params.Add("$alt", "json;enum-encoding=int")
1346 params.Add("configurationId", fmt.Sprintf("%v", req.GetConfigurationId()))
1347 if req.GetRequestId() != "" {
1348 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1349 }
1350
1351 baseUrl.RawQuery = params.Encode()
1352
1353 // Build HTTP headers from client and context metadata.
1354 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
1355
1356 hds = append(c.xGoogHeaders, hds...)
1357 hds = append(hds, "Content-Type", "application/json")
1358 headers := gax.BuildHeaders(ctx, hds...)
1359 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1360 resp := &longrunningpb.Operation{}
1361 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1362 if settings.Path != "" {
1363 baseUrl.Path = settings.Path
1364 }
1365 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1366 if err != nil {
1367 return err
1368 }
1369 httpReq = httpReq.WithContext(ctx)
1370 httpReq.Header = headers
1371
1372 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateConfiguration")
1373 if err != nil {
1374 return err
1375 }
1376 if err := unm.Unmarshal(buf, resp); err != nil {
1377 return err
1378 }
1379
1380 return nil
1381 }, opts...)
1382 if e != nil {
1383 return nil, e
1384 }
1385
1386 override := fmt.Sprintf("/v1/%s", resp.GetName())
1387 return &CreateConfigurationOperation{
1388 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1389 pollPath: override,
1390 }, nil
1391 }
1392
1393 // UpdateConfiguration updates the parameters of a single Configuration.
1394 func (c *restClient) UpdateConfiguration(ctx context.Context, req *licensemanagerpb.UpdateConfigurationRequest, opts ...gax.CallOption) (*UpdateConfigurationOperation, error) {
1395 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1396 body := req.GetConfiguration()
1397 jsonReq, err := m.Marshal(body)
1398 if err != nil {
1399 return nil, err
1400 }
1401
1402 baseUrl, err := url.Parse(c.endpoint)
1403 if err != nil {
1404 return nil, err
1405 }
1406 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetConfiguration().GetName())
1407
1408 params := url.Values{}
1409 params.Add("$alt", "json;enum-encoding=int")
1410 if req.GetRequestId() != "" {
1411 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1412 }
1413 if req.GetUpdateMask() != nil {
1414 field, err := protojson.Marshal(req.GetUpdateMask())
1415 if err != nil {
1416 return nil, err
1417 }
1418 params.Add("updateMask", string(field[1:len(field)-1]))
1419 }
1420
1421 baseUrl.RawQuery = params.Encode()
1422
1423 // Build HTTP headers from client and context metadata.
1424 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "configuration.name", url.QueryEscape(req.GetConfiguration().GetName()))}
1425
1426 hds = append(c.xGoogHeaders, hds...)
1427 hds = append(hds, "Content-Type", "application/json")
1428 headers := gax.BuildHeaders(ctx, hds...)
1429 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1430 resp := &longrunningpb.Operation{}
1431 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1432 if settings.Path != "" {
1433 baseUrl.Path = settings.Path
1434 }
1435 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
1436 if err != nil {
1437 return err
1438 }
1439 httpReq = httpReq.WithContext(ctx)
1440 httpReq.Header = headers
1441
1442 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateConfiguration")
1443 if err != nil {
1444 return err
1445 }
1446 if err := unm.Unmarshal(buf, resp); err != nil {
1447 return err
1448 }
1449
1450 return nil
1451 }, opts...)
1452 if e != nil {
1453 return nil, e
1454 }
1455
1456 override := fmt.Sprintf("/v1/%s", resp.GetName())
1457 return &UpdateConfigurationOperation{
1458 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1459 pollPath: override,
1460 }, nil
1461 }
1462
1463 // DeleteConfiguration deletes a single Configuration.
1464 func (c *restClient) DeleteConfiguration(ctx context.Context, req *licensemanagerpb.DeleteConfigurationRequest, opts ...gax.CallOption) (*DeleteConfigurationOperation, error) {
1465 baseUrl, err := url.Parse(c.endpoint)
1466 if err != nil {
1467 return nil, err
1468 }
1469 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1470
1471 params := url.Values{}
1472 params.Add("$alt", "json;enum-encoding=int")
1473 if req.GetRequestId() != "" {
1474 params.Add("requestId", fmt.Sprintf("%v", req.GetRequestId()))
1475 }
1476
1477 baseUrl.RawQuery = params.Encode()
1478
1479 // Build HTTP headers from client and context metadata.
1480 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1481
1482 hds = append(c.xGoogHeaders, hds...)
1483 hds = append(hds, "Content-Type", "application/json")
1484 headers := gax.BuildHeaders(ctx, hds...)
1485 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1486 resp := &longrunningpb.Operation{}
1487 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1488 if settings.Path != "" {
1489 baseUrl.Path = settings.Path
1490 }
1491 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
1492 if err != nil {
1493 return err
1494 }
1495 httpReq = httpReq.WithContext(ctx)
1496 httpReq.Header = headers
1497
1498 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteConfiguration")
1499 if err != nil {
1500 return err
1501 }
1502 if err := unm.Unmarshal(buf, resp); err != nil {
1503 return err
1504 }
1505
1506 return nil
1507 }, opts...)
1508 if e != nil {
1509 return nil, e
1510 }
1511
1512 override := fmt.Sprintf("/v1/%s", resp.GetName())
1513 return &DeleteConfigurationOperation{
1514 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1515 pollPath: override,
1516 }, nil
1517 }
1518
1519 // ListInstances lists Instances in a given project and location.
1520 func (c *restClient) ListInstances(ctx context.Context, req *licensemanagerpb.ListInstancesRequest, opts ...gax.CallOption) *InstanceIterator {
1521 it := &InstanceIterator{}
1522 req = proto.Clone(req).(*licensemanagerpb.ListInstancesRequest)
1523 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1524 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Instance, string, error) {
1525 resp := &licensemanagerpb.ListInstancesResponse{}
1526 if pageToken != "" {
1527 req.PageToken = pageToken
1528 }
1529 if pageSize > math.MaxInt32 {
1530 req.PageSize = math.MaxInt32
1531 } else if pageSize != 0 {
1532 req.PageSize = int32(pageSize)
1533 }
1534 baseUrl, err := url.Parse(c.endpoint)
1535 if err != nil {
1536 return nil, "", err
1537 }
1538 baseUrl.Path += fmt.Sprintf("/v1/%v/instances", req.GetParent())
1539
1540 params := url.Values{}
1541 params.Add("$alt", "json;enum-encoding=int")
1542 if req.GetFilter() != "" {
1543 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1544 }
1545 if req.GetOrderBy() != "" {
1546 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
1547 }
1548 if req.GetPageSize() != 0 {
1549 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1550 }
1551 if req.GetPageToken() != "" {
1552 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1553 }
1554
1555 baseUrl.RawQuery = params.Encode()
1556
1557 // Build HTTP headers from client and context metadata.
1558 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1559 headers := gax.BuildHeaders(ctx, hds...)
1560 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1561 if settings.Path != "" {
1562 baseUrl.Path = settings.Path
1563 }
1564 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1565 if err != nil {
1566 return err
1567 }
1568 httpReq.Header = headers
1569
1570 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListInstances")
1571 if err != nil {
1572 return err
1573 }
1574 if err := unm.Unmarshal(buf, resp); err != nil {
1575 return err
1576 }
1577
1578 return nil
1579 }, opts...)
1580 if e != nil {
1581 return nil, "", e
1582 }
1583 it.Response = resp
1584 return resp.GetInstances(), resp.GetNextPageToken(), nil
1585 }
1586
1587 fetch := func(pageSize int, pageToken string) (string, error) {
1588 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1589 if err != nil {
1590 return "", err
1591 }
1592 it.items = append(it.items, items...)
1593 return nextPageToken, nil
1594 }
1595
1596 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1597 it.pageInfo.MaxSize = int(req.GetPageSize())
1598 it.pageInfo.Token = req.GetPageToken()
1599
1600 return it
1601 }
1602
1603 // GetInstance gets details of a single Instance.
1604 func (c *restClient) GetInstance(ctx context.Context, req *licensemanagerpb.GetInstanceRequest, opts ...gax.CallOption) (*licensemanagerpb.Instance, error) {
1605 baseUrl, err := url.Parse(c.endpoint)
1606 if err != nil {
1607 return nil, err
1608 }
1609 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
1610
1611 params := url.Values{}
1612 params.Add("$alt", "json;enum-encoding=int")
1613
1614 baseUrl.RawQuery = params.Encode()
1615
1616 // Build HTTP headers from client and context metadata.
1617 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1618
1619 hds = append(c.xGoogHeaders, hds...)
1620 hds = append(hds, "Content-Type", "application/json")
1621 headers := gax.BuildHeaders(ctx, hds...)
1622 opts = append((*c.CallOptions).GetInstance[0:len((*c.CallOptions).GetInstance):len((*c.CallOptions).GetInstance)], opts...)
1623 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1624 resp := &licensemanagerpb.Instance{}
1625 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1626 if settings.Path != "" {
1627 baseUrl.Path = settings.Path
1628 }
1629 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1630 if err != nil {
1631 return err
1632 }
1633 httpReq = httpReq.WithContext(ctx)
1634 httpReq.Header = headers
1635
1636 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetInstance")
1637 if err != nil {
1638 return err
1639 }
1640
1641 if err := unm.Unmarshal(buf, resp); err != nil {
1642 return err
1643 }
1644
1645 return nil
1646 }, opts...)
1647 if e != nil {
1648 return nil, e
1649 }
1650 return resp, nil
1651 }
1652
1653 // DeactivateConfiguration deactivates the given configuration.
1654 func (c *restClient) DeactivateConfiguration(ctx context.Context, req *licensemanagerpb.DeactivateConfigurationRequest, opts ...gax.CallOption) (*DeactivateConfigurationOperation, error) {
1655 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1656 jsonReq, err := m.Marshal(req)
1657 if err != nil {
1658 return nil, err
1659 }
1660
1661 baseUrl, err := url.Parse(c.endpoint)
1662 if err != nil {
1663 return nil, err
1664 }
1665 baseUrl.Path += fmt.Sprintf("/v1/%v:deactivate", req.GetName())
1666
1667 params := url.Values{}
1668 params.Add("$alt", "json;enum-encoding=int")
1669
1670 baseUrl.RawQuery = params.Encode()
1671
1672 // Build HTTP headers from client and context metadata.
1673 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1674
1675 hds = append(c.xGoogHeaders, hds...)
1676 hds = append(hds, "Content-Type", "application/json")
1677 headers := gax.BuildHeaders(ctx, hds...)
1678 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1679 resp := &longrunningpb.Operation{}
1680 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1681 if settings.Path != "" {
1682 baseUrl.Path = settings.Path
1683 }
1684 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1685 if err != nil {
1686 return err
1687 }
1688 httpReq = httpReq.WithContext(ctx)
1689 httpReq.Header = headers
1690
1691 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "DeactivateConfiguration")
1692 if err != nil {
1693 return err
1694 }
1695 if err := unm.Unmarshal(buf, resp); err != nil {
1696 return err
1697 }
1698
1699 return nil
1700 }, opts...)
1701 if e != nil {
1702 return nil, e
1703 }
1704
1705 override := fmt.Sprintf("/v1/%s", resp.GetName())
1706 return &DeactivateConfigurationOperation{
1707 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1708 pollPath: override,
1709 }, nil
1710 }
1711
1712 // ReactivateConfiguration reactivates the given configuration.
1713 func (c *restClient) ReactivateConfiguration(ctx context.Context, req *licensemanagerpb.ReactivateConfigurationRequest, opts ...gax.CallOption) (*ReactivateConfigurationOperation, error) {
1714 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
1715 jsonReq, err := m.Marshal(req)
1716 if err != nil {
1717 return nil, err
1718 }
1719
1720 baseUrl, err := url.Parse(c.endpoint)
1721 if err != nil {
1722 return nil, err
1723 }
1724 baseUrl.Path += fmt.Sprintf("/v1/%v:reactivate", req.GetName())
1725
1726 params := url.Values{}
1727 params.Add("$alt", "json;enum-encoding=int")
1728
1729 baseUrl.RawQuery = params.Encode()
1730
1731 // Build HTTP headers from client and context metadata.
1732 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1733
1734 hds = append(c.xGoogHeaders, hds...)
1735 hds = append(hds, "Content-Type", "application/json")
1736 headers := gax.BuildHeaders(ctx, hds...)
1737 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1738 resp := &longrunningpb.Operation{}
1739 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1740 if settings.Path != "" {
1741 baseUrl.Path = settings.Path
1742 }
1743 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
1744 if err != nil {
1745 return err
1746 }
1747 httpReq = httpReq.WithContext(ctx)
1748 httpReq.Header = headers
1749
1750 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ReactivateConfiguration")
1751 if err != nil {
1752 return err
1753 }
1754 if err := unm.Unmarshal(buf, resp); err != nil {
1755 return err
1756 }
1757
1758 return nil
1759 }, opts...)
1760 if e != nil {
1761 return nil, e
1762 }
1763
1764 override := fmt.Sprintf("/v1/%s", resp.GetName())
1765 return &ReactivateConfigurationOperation{
1766 lro: longrunning.InternalNewOperation(*c.LROClient, resp),
1767 pollPath: override,
1768 }, nil
1769 }
1770
1771 // QueryConfigurationLicenseUsage license Usage information for a Configuration.
1772 func (c *restClient) QueryConfigurationLicenseUsage(ctx context.Context, req *licensemanagerpb.QueryConfigurationLicenseUsageRequest, opts ...gax.CallOption) (*licensemanagerpb.QueryConfigurationLicenseUsageResponse, error) {
1773 baseUrl, err := url.Parse(c.endpoint)
1774 if err != nil {
1775 return nil, err
1776 }
1777 baseUrl.Path += fmt.Sprintf("/v1/%v:queryLicenseUsage", req.GetName())
1778
1779 params := url.Values{}
1780 params.Add("$alt", "json;enum-encoding=int")
1781 if req.GetEndTime() != nil {
1782 field, err := protojson.Marshal(req.GetEndTime())
1783 if err != nil {
1784 return nil, err
1785 }
1786 params.Add("endTime", string(field[1:len(field)-1]))
1787 }
1788 if req.GetStartTime() != nil {
1789 field, err := protojson.Marshal(req.GetStartTime())
1790 if err != nil {
1791 return nil, err
1792 }
1793 params.Add("startTime", string(field[1:len(field)-1]))
1794 }
1795
1796 baseUrl.RawQuery = params.Encode()
1797
1798 // Build HTTP headers from client and context metadata.
1799 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
1800
1801 hds = append(c.xGoogHeaders, hds...)
1802 hds = append(hds, "Content-Type", "application/json")
1803 headers := gax.BuildHeaders(ctx, hds...)
1804 opts = append((*c.CallOptions).QueryConfigurationLicenseUsage[0:len((*c.CallOptions).QueryConfigurationLicenseUsage):len((*c.CallOptions).QueryConfigurationLicenseUsage)], opts...)
1805 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1806 resp := &licensemanagerpb.QueryConfigurationLicenseUsageResponse{}
1807 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1808 if settings.Path != "" {
1809 baseUrl.Path = settings.Path
1810 }
1811 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1812 if err != nil {
1813 return err
1814 }
1815 httpReq = httpReq.WithContext(ctx)
1816 httpReq.Header = headers
1817
1818 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "QueryConfigurationLicenseUsage")
1819 if err != nil {
1820 return err
1821 }
1822
1823 if err := unm.Unmarshal(buf, resp); err != nil {
1824 return err
1825 }
1826
1827 return nil
1828 }, opts...)
1829 if e != nil {
1830 return nil, e
1831 }
1832 return resp, nil
1833 }
1834
1835 // AggregateUsage aggregates Usage per Instance for a Configuration.
1836 func (c *restClient) AggregateUsage(ctx context.Context, req *licensemanagerpb.AggregateUsageRequest, opts ...gax.CallOption) *UsageIterator {
1837 it := &UsageIterator{}
1838 req = proto.Clone(req).(*licensemanagerpb.AggregateUsageRequest)
1839 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1840 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Usage, string, error) {
1841 resp := &licensemanagerpb.AggregateUsageResponse{}
1842 if pageToken != "" {
1843 req.PageToken = pageToken
1844 }
1845 if pageSize > math.MaxInt32 {
1846 req.PageSize = math.MaxInt32
1847 } else if pageSize != 0 {
1848 req.PageSize = int32(pageSize)
1849 }
1850 baseUrl, err := url.Parse(c.endpoint)
1851 if err != nil {
1852 return nil, "", err
1853 }
1854 baseUrl.Path += fmt.Sprintf("/v1/%v:aggregateUsage", req.GetName())
1855
1856 params := url.Values{}
1857 params.Add("$alt", "json;enum-encoding=int")
1858 if req.GetEndTime() != nil {
1859 field, err := protojson.Marshal(req.GetEndTime())
1860 if err != nil {
1861 return nil, "", err
1862 }
1863 params.Add("endTime", string(field[1:len(field)-1]))
1864 }
1865 if req.GetFilter() != "" {
1866 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1867 }
1868 if req.GetOrderBy() != "" {
1869 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
1870 }
1871 if req.GetPageSize() != 0 {
1872 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1873 }
1874 if req.GetPageToken() != "" {
1875 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1876 }
1877 if req.GetStartTime() != nil {
1878 field, err := protojson.Marshal(req.GetStartTime())
1879 if err != nil {
1880 return nil, "", err
1881 }
1882 params.Add("startTime", string(field[1:len(field)-1]))
1883 }
1884
1885 baseUrl.RawQuery = params.Encode()
1886
1887 // Build HTTP headers from client and context metadata.
1888 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1889 headers := gax.BuildHeaders(ctx, hds...)
1890 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1891 if settings.Path != "" {
1892 baseUrl.Path = settings.Path
1893 }
1894 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1895 if err != nil {
1896 return err
1897 }
1898 httpReq.Header = headers
1899
1900 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "AggregateUsage")
1901 if err != nil {
1902 return err
1903 }
1904 if err := unm.Unmarshal(buf, resp); err != nil {
1905 return err
1906 }
1907
1908 return nil
1909 }, opts...)
1910 if e != nil {
1911 return nil, "", e
1912 }
1913 it.Response = resp
1914 return resp.GetUsages(), resp.GetNextPageToken(), nil
1915 }
1916
1917 fetch := func(pageSize int, pageToken string) (string, error) {
1918 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
1919 if err != nil {
1920 return "", err
1921 }
1922 it.items = append(it.items, items...)
1923 return nextPageToken, nil
1924 }
1925
1926 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
1927 it.pageInfo.MaxSize = int(req.GetPageSize())
1928 it.pageInfo.Token = req.GetPageToken()
1929
1930 return it
1931 }
1932
1933 // ListProducts lists Products in a given project and location.
1934 func (c *restClient) ListProducts(ctx context.Context, req *licensemanagerpb.ListProductsRequest, opts ...gax.CallOption) *ProductIterator {
1935 it := &ProductIterator{}
1936 req = proto.Clone(req).(*licensemanagerpb.ListProductsRequest)
1937 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
1938 it.InternalFetch = func(pageSize int, pageToken string) ([]*licensemanagerpb.Product, string, error) {
1939 resp := &licensemanagerpb.ListProductsResponse{}
1940 if pageToken != "" {
1941 req.PageToken = pageToken
1942 }
1943 if pageSize > math.MaxInt32 {
1944 req.PageSize = math.MaxInt32
1945 } else if pageSize != 0 {
1946 req.PageSize = int32(pageSize)
1947 }
1948 baseUrl, err := url.Parse(c.endpoint)
1949 if err != nil {
1950 return nil, "", err
1951 }
1952 baseUrl.Path += fmt.Sprintf("/v1/%v/products", req.GetParent())
1953
1954 params := url.Values{}
1955 params.Add("$alt", "json;enum-encoding=int")
1956 if req.GetFilter() != "" {
1957 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
1958 }
1959 if req.GetOrderBy() != "" {
1960 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy()))
1961 }
1962 if req.GetPageSize() != 0 {
1963 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
1964 }
1965 if req.GetPageToken() != "" {
1966 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
1967 }
1968
1969 baseUrl.RawQuery = params.Encode()
1970
1971 // Build HTTP headers from client and context metadata.
1972 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
1973 headers := gax.BuildHeaders(ctx, hds...)
1974 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
1975 if settings.Path != "" {
1976 baseUrl.Path = settings.Path
1977 }
1978 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
1979 if err != nil {
1980 return err
1981 }
1982 httpReq.Header = headers
1983
1984 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListProducts")
1985 if err != nil {
1986 return err
1987 }
1988 if err := unm.Unmarshal(buf, resp); err != nil {
1989 return err
1990 }
1991
1992 return nil
1993 }, opts...)
1994 if e != nil {
1995 return nil, "", e
1996 }
1997 it.Response = resp
1998 return resp.GetProducts(), resp.GetNextPageToken(), nil
1999 }
2000
2001 fetch := func(pageSize int, pageToken string) (string, error) {
2002 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2003 if err != nil {
2004 return "", err
2005 }
2006 it.items = append(it.items, items...)
2007 return nextPageToken, nil
2008 }
2009
2010 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2011 it.pageInfo.MaxSize = int(req.GetPageSize())
2012 it.pageInfo.Token = req.GetPageToken()
2013
2014 return it
2015 }
2016
2017 // GetProduct gets details of a single Product.
2018 func (c *restClient) GetProduct(ctx context.Context, req *licensemanagerpb.GetProductRequest, opts ...gax.CallOption) (*licensemanagerpb.Product, error) {
2019 baseUrl, err := url.Parse(c.endpoint)
2020 if err != nil {
2021 return nil, err
2022 }
2023 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2024
2025 params := url.Values{}
2026 params.Add("$alt", "json;enum-encoding=int")
2027
2028 baseUrl.RawQuery = params.Encode()
2029
2030 // Build HTTP headers from client and context metadata.
2031 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2032
2033 hds = append(c.xGoogHeaders, hds...)
2034 hds = append(hds, "Content-Type", "application/json")
2035 headers := gax.BuildHeaders(ctx, hds...)
2036 opts = append((*c.CallOptions).GetProduct[0:len((*c.CallOptions).GetProduct):len((*c.CallOptions).GetProduct)], opts...)
2037 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2038 resp := &licensemanagerpb.Product{}
2039 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2040 if settings.Path != "" {
2041 baseUrl.Path = settings.Path
2042 }
2043 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2044 if err != nil {
2045 return err
2046 }
2047 httpReq = httpReq.WithContext(ctx)
2048 httpReq.Header = headers
2049
2050 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetProduct")
2051 if err != nil {
2052 return err
2053 }
2054
2055 if err := unm.Unmarshal(buf, resp); err != nil {
2056 return err
2057 }
2058
2059 return nil
2060 }, opts...)
2061 if e != nil {
2062 return nil, e
2063 }
2064 return resp, nil
2065 }
2066
2067 // GetLocation gets information about a location.
2068 func (c *restClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) {
2069 baseUrl, err := url.Parse(c.endpoint)
2070 if err != nil {
2071 return nil, err
2072 }
2073 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2074
2075 params := url.Values{}
2076 params.Add("$alt", "json;enum-encoding=int")
2077
2078 baseUrl.RawQuery = params.Encode()
2079
2080 // Build HTTP headers from client and context metadata.
2081 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2082
2083 hds = append(c.xGoogHeaders, hds...)
2084 hds = append(hds, "Content-Type", "application/json")
2085 headers := gax.BuildHeaders(ctx, hds...)
2086 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...)
2087 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2088 resp := &locationpb.Location{}
2089 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2090 if settings.Path != "" {
2091 baseUrl.Path = settings.Path
2092 }
2093 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2094 if err != nil {
2095 return err
2096 }
2097 httpReq = httpReq.WithContext(ctx)
2098 httpReq.Header = headers
2099
2100 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation")
2101 if err != nil {
2102 return err
2103 }
2104
2105 if err := unm.Unmarshal(buf, resp); err != nil {
2106 return err
2107 }
2108
2109 return nil
2110 }, opts...)
2111 if e != nil {
2112 return nil, e
2113 }
2114 return resp, nil
2115 }
2116
2117 // ListLocations lists information about the supported locations for this service.
2118 func (c *restClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator {
2119 it := &LocationIterator{}
2120 req = proto.Clone(req).(*locationpb.ListLocationsRequest)
2121 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2122 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) {
2123 resp := &locationpb.ListLocationsResponse{}
2124 if pageToken != "" {
2125 req.PageToken = pageToken
2126 }
2127 if pageSize > math.MaxInt32 {
2128 req.PageSize = math.MaxInt32
2129 } else if pageSize != 0 {
2130 req.PageSize = int32(pageSize)
2131 }
2132 baseUrl, err := url.Parse(c.endpoint)
2133 if err != nil {
2134 return nil, "", err
2135 }
2136 baseUrl.Path += fmt.Sprintf("/v1/%v/locations", req.GetName())
2137
2138 params := url.Values{}
2139 params.Add("$alt", "json;enum-encoding=int")
2140 if req.GetFilter() != "" {
2141 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2142 }
2143 if req.GetPageSize() != 0 {
2144 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2145 }
2146 if req.GetPageToken() != "" {
2147 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2148 }
2149
2150 baseUrl.RawQuery = params.Encode()
2151
2152 // Build HTTP headers from client and context metadata.
2153 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2154 headers := gax.BuildHeaders(ctx, hds...)
2155 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2156 if settings.Path != "" {
2157 baseUrl.Path = settings.Path
2158 }
2159 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2160 if err != nil {
2161 return err
2162 }
2163 httpReq.Header = headers
2164
2165 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations")
2166 if err != nil {
2167 return err
2168 }
2169 if err := unm.Unmarshal(buf, resp); err != nil {
2170 return err
2171 }
2172
2173 return nil
2174 }, opts...)
2175 if e != nil {
2176 return nil, "", e
2177 }
2178 it.Response = resp
2179 return resp.GetLocations(), resp.GetNextPageToken(), nil
2180 }
2181
2182 fetch := func(pageSize int, pageToken string) (string, error) {
2183 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2184 if err != nil {
2185 return "", err
2186 }
2187 it.items = append(it.items, items...)
2188 return nextPageToken, nil
2189 }
2190
2191 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2192 it.pageInfo.MaxSize = int(req.GetPageSize())
2193 it.pageInfo.Token = req.GetPageToken()
2194
2195 return it
2196 }
2197
2198 // CancelOperation is a utility method from google.longrunning.Operations.
2199 func (c *restClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
2200 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
2201 jsonReq, err := m.Marshal(req)
2202 if err != nil {
2203 return err
2204 }
2205
2206 baseUrl, err := url.Parse(c.endpoint)
2207 if err != nil {
2208 return err
2209 }
2210 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
2211
2212 params := url.Values{}
2213 params.Add("$alt", "json;enum-encoding=int")
2214
2215 baseUrl.RawQuery = params.Encode()
2216
2217 // Build HTTP headers from client and context metadata.
2218 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2219
2220 hds = append(c.xGoogHeaders, hds...)
2221 hds = append(hds, "Content-Type", "application/json")
2222 headers := gax.BuildHeaders(ctx, hds...)
2223 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2224 if settings.Path != "" {
2225 baseUrl.Path = settings.Path
2226 }
2227 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
2228 if err != nil {
2229 return err
2230 }
2231 httpReq = httpReq.WithContext(ctx)
2232 httpReq.Header = headers
2233
2234 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
2235 return err
2236 }, opts...)
2237 }
2238
2239 // DeleteOperation is a utility method from google.longrunning.Operations.
2240 func (c *restClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
2241 baseUrl, err := url.Parse(c.endpoint)
2242 if err != nil {
2243 return err
2244 }
2245 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2246
2247 params := url.Values{}
2248 params.Add("$alt", "json;enum-encoding=int")
2249
2250 baseUrl.RawQuery = params.Encode()
2251
2252 // Build HTTP headers from client and context metadata.
2253 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2254
2255 hds = append(c.xGoogHeaders, hds...)
2256 hds = append(hds, "Content-Type", "application/json")
2257 headers := gax.BuildHeaders(ctx, hds...)
2258 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2259 if settings.Path != "" {
2260 baseUrl.Path = settings.Path
2261 }
2262 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
2263 if err != nil {
2264 return err
2265 }
2266 httpReq = httpReq.WithContext(ctx)
2267 httpReq.Header = headers
2268
2269 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
2270 return err
2271 }, opts...)
2272 }
2273
2274 // GetOperation is a utility method from google.longrunning.Operations.
2275 func (c *restClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
2276 baseUrl, err := url.Parse(c.endpoint)
2277 if err != nil {
2278 return nil, err
2279 }
2280 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
2281
2282 params := url.Values{}
2283 params.Add("$alt", "json;enum-encoding=int")
2284
2285 baseUrl.RawQuery = params.Encode()
2286
2287 // Build HTTP headers from client and context metadata.
2288 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
2289
2290 hds = append(c.xGoogHeaders, hds...)
2291 hds = append(hds, "Content-Type", "application/json")
2292 headers := gax.BuildHeaders(ctx, hds...)
2293 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
2294 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2295 resp := &longrunningpb.Operation{}
2296 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2297 if settings.Path != "" {
2298 baseUrl.Path = settings.Path
2299 }
2300 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2301 if err != nil {
2302 return err
2303 }
2304 httpReq = httpReq.WithContext(ctx)
2305 httpReq.Header = headers
2306
2307 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
2308 if err != nil {
2309 return err
2310 }
2311
2312 if err := unm.Unmarshal(buf, resp); err != nil {
2313 return err
2314 }
2315
2316 return nil
2317 }, opts...)
2318 if e != nil {
2319 return nil, e
2320 }
2321 return resp, nil
2322 }
2323
2324 // ListOperations is a utility method from google.longrunning.Operations.
2325 func (c *restClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
2326 it := &OperationIterator{}
2327 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
2328 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
2329 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
2330 resp := &longrunningpb.ListOperationsResponse{}
2331 if pageToken != "" {
2332 req.PageToken = pageToken
2333 }
2334 if pageSize > math.MaxInt32 {
2335 req.PageSize = math.MaxInt32
2336 } else if pageSize != 0 {
2337 req.PageSize = int32(pageSize)
2338 }
2339 baseUrl, err := url.Parse(c.endpoint)
2340 if err != nil {
2341 return nil, "", err
2342 }
2343 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
2344
2345 params := url.Values{}
2346 params.Add("$alt", "json;enum-encoding=int")
2347 if req.GetFilter() != "" {
2348 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
2349 }
2350 if req.GetPageSize() != 0 {
2351 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
2352 }
2353 if req.GetPageToken() != "" {
2354 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
2355 }
2356
2357 baseUrl.RawQuery = params.Encode()
2358
2359 // Build HTTP headers from client and context metadata.
2360 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
2361 headers := gax.BuildHeaders(ctx, hds...)
2362 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
2363 if settings.Path != "" {
2364 baseUrl.Path = settings.Path
2365 }
2366 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
2367 if err != nil {
2368 return err
2369 }
2370 httpReq.Header = headers
2371
2372 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
2373 if err != nil {
2374 return err
2375 }
2376 if err := unm.Unmarshal(buf, resp); err != nil {
2377 return err
2378 }
2379
2380 return nil
2381 }, opts...)
2382 if e != nil {
2383 return nil, "", e
2384 }
2385 it.Response = resp
2386 return resp.GetOperations(), resp.GetNextPageToken(), nil
2387 }
2388
2389 fetch := func(pageSize int, pageToken string) (string, error) {
2390 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
2391 if err != nil {
2392 return "", err
2393 }
2394 it.items = append(it.items, items...)
2395 return nextPageToken, nil
2396 }
2397
2398 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
2399 it.pageInfo.MaxSize = int(req.GetPageSize())
2400 it.pageInfo.Token = req.GetPageToken()
2401
2402 return it
2403 }
2404
2405 // CreateConfigurationOperation returns a new CreateConfigurationOperation from a given name.
2406 // The name must be that of a previously created CreateConfigurationOperation, possibly from a different process.
2407 func (c *gRPCClient) CreateConfigurationOperation(name string) *CreateConfigurationOperation {
2408 return &CreateConfigurationOperation{
2409 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2410 }
2411 }
2412
2413 // CreateConfigurationOperation returns a new CreateConfigurationOperation from a given name.
2414 // The name must be that of a previously created CreateConfigurationOperation, possibly from a different process.
2415 func (c *restClient) CreateConfigurationOperation(name string) *CreateConfigurationOperation {
2416 override := fmt.Sprintf("/v1/%s", name)
2417 return &CreateConfigurationOperation{
2418 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2419 pollPath: override,
2420 }
2421 }
2422
2423 // DeactivateConfigurationOperation returns a new DeactivateConfigurationOperation from a given name.
2424 // The name must be that of a previously created DeactivateConfigurationOperation, possibly from a different process.
2425 func (c *gRPCClient) DeactivateConfigurationOperation(name string) *DeactivateConfigurationOperation {
2426 return &DeactivateConfigurationOperation{
2427 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2428 }
2429 }
2430
2431 // DeactivateConfigurationOperation returns a new DeactivateConfigurationOperation from a given name.
2432 // The name must be that of a previously created DeactivateConfigurationOperation, possibly from a different process.
2433 func (c *restClient) DeactivateConfigurationOperation(name string) *DeactivateConfigurationOperation {
2434 override := fmt.Sprintf("/v1/%s", name)
2435 return &DeactivateConfigurationOperation{
2436 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2437 pollPath: override,
2438 }
2439 }
2440
2441 // DeleteConfigurationOperation returns a new DeleteConfigurationOperation from a given name.
2442 // The name must be that of a previously created DeleteConfigurationOperation, possibly from a different process.
2443 func (c *gRPCClient) DeleteConfigurationOperation(name string) *DeleteConfigurationOperation {
2444 return &DeleteConfigurationOperation{
2445 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2446 }
2447 }
2448
2449 // DeleteConfigurationOperation returns a new DeleteConfigurationOperation from a given name.
2450 // The name must be that of a previously created DeleteConfigurationOperation, possibly from a different process.
2451 func (c *restClient) DeleteConfigurationOperation(name string) *DeleteConfigurationOperation {
2452 override := fmt.Sprintf("/v1/%s", name)
2453 return &DeleteConfigurationOperation{
2454 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2455 pollPath: override,
2456 }
2457 }
2458
2459 // ReactivateConfigurationOperation returns a new ReactivateConfigurationOperation from a given name.
2460 // The name must be that of a previously created ReactivateConfigurationOperation, possibly from a different process.
2461 func (c *gRPCClient) ReactivateConfigurationOperation(name string) *ReactivateConfigurationOperation {
2462 return &ReactivateConfigurationOperation{
2463 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2464 }
2465 }
2466
2467 // ReactivateConfigurationOperation returns a new ReactivateConfigurationOperation from a given name.
2468 // The name must be that of a previously created ReactivateConfigurationOperation, possibly from a different process.
2469 func (c *restClient) ReactivateConfigurationOperation(name string) *ReactivateConfigurationOperation {
2470 override := fmt.Sprintf("/v1/%s", name)
2471 return &ReactivateConfigurationOperation{
2472 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2473 pollPath: override,
2474 }
2475 }
2476
2477 // UpdateConfigurationOperation returns a new UpdateConfigurationOperation from a given name.
2478 // The name must be that of a previously created UpdateConfigurationOperation, possibly from a different process.
2479 func (c *gRPCClient) UpdateConfigurationOperation(name string) *UpdateConfigurationOperation {
2480 return &UpdateConfigurationOperation{
2481 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2482 }
2483 }
2484
2485 // UpdateConfigurationOperation returns a new UpdateConfigurationOperation from a given name.
2486 // The name must be that of a previously created UpdateConfigurationOperation, possibly from a different process.
2487 func (c *restClient) UpdateConfigurationOperation(name string) *UpdateConfigurationOperation {
2488 override := fmt.Sprintf("/v1/%s", name)
2489 return &UpdateConfigurationOperation{
2490 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}),
2491 pollPath: override,
2492 }
2493 }