Debian Codegraph @

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