| 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 service |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"fmt" |
| 22 |
"log/slog" |
| 23 |
"math" |
| 24 |
"net/http" |
| 25 |
"net/url" |
| 26 |
|
| 27 |
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb" |
| 28 |
servicepb "cloud.google.com/go/orchestration/airflow/service/apiv1/servicepb" |
| 29 |
gax "github.com/googleapis/gax-go/v2" |
| 30 |
"google.golang.org/api/iterator" |
| 31 |
"google.golang.org/api/option" |
| 32 |
"google.golang.org/api/option/internaloption" |
| 33 |
gtransport "google.golang.org/api/transport/grpc" |
| 34 |
httptransport "google.golang.org/api/transport/http" |
| 35 |
"google.golang.org/grpc" |
| 36 |
"google.golang.org/protobuf/encoding/protojson" |
| 37 |
"google.golang.org/protobuf/proto" |
| 38 |
) |
| 39 |
|
| 40 |
var newImageVersionsClientHook clientHook |
| 41 |
|
| 42 |
// ImageVersionsCallOptions contains the retry settings for each method of ImageVersionsClient. |
| 43 |
type ImageVersionsCallOptions struct { |
| 44 |
ListImageVersions []gax.CallOption |
| 45 |
DeleteOperation []gax.CallOption |
| 46 |
GetOperation []gax.CallOption |
| 47 |
ListOperations []gax.CallOption |
| 48 |
} |
| 49 |
|
| 50 |
func defaultImageVersionsGRPCClientOptions() []option.ClientOption { |
| 51 |
return []option.ClientOption{ |
| 52 |
internaloption.WithDefaultEndpoint("composer.googleapis.com:443"), |
| 53 |
internaloption.WithDefaultEndpointTemplate("composer.UNIVERSE_DOMAIN:443"), |
| 54 |
internaloption.WithDefaultMTLSEndpoint("composer.mtls.googleapis.com:443"), |
| 55 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 56 |
internaloption.WithDefaultAudience("https://composer.googleapis.com/"), |
| 57 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 58 |
internaloption.EnableJwtWithScope(), |
| 59 |
internaloption.EnableNewAuthLibrary(), |
| 60 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 61 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 62 |
} |
| 63 |
} |
| 64 |
|
| 65 |
func defaultImageVersionsCallOptions() *ImageVersionsCallOptions { |
| 66 |
return &ImageVersionsCallOptions{ |
| 67 |
ListImageVersions: []gax.CallOption{}, |
| 68 |
DeleteOperation: []gax.CallOption{}, |
| 69 |
GetOperation: []gax.CallOption{}, |
| 70 |
ListOperations: []gax.CallOption{}, |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
func defaultImageVersionsRESTCallOptions() *ImageVersionsCallOptions { |
| 75 |
return &ImageVersionsCallOptions{ |
| 76 |
ListImageVersions: []gax.CallOption{}, |
| 77 |
DeleteOperation: []gax.CallOption{}, |
| 78 |
GetOperation: []gax.CallOption{}, |
| 79 |
ListOperations: []gax.CallOption{}, |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
// internalImageVersionsClient is an interface that defines the methods available from Cloud Composer API. |
| 84 |
type internalImageVersionsClient interface { |
| 85 |
Close() error |
| 86 |
setGoogleClientInfo(...string) |
| 87 |
Connection() *grpc.ClientConn |
| 88 |
ListImageVersions(context.Context, *servicepb.ListImageVersionsRequest, ...gax.CallOption) *ImageVersionIterator |
| 89 |
DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error |
| 90 |
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) |
| 91 |
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator |
| 92 |
} |
| 93 |
|
| 94 |
// ImageVersionsClient is a client for interacting with Cloud Composer API. |
| 95 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 96 |
// |
| 97 |
// Readonly service to query available ImageVersions. |
| 98 |
type ImageVersionsClient struct { |
| 99 |
// The internal transport-dependent client. |
| 100 |
internalClient internalImageVersionsClient |
| 101 |
|
| 102 |
// The call options for this service. |
| 103 |
CallOptions *ImageVersionsCallOptions |
| 104 |
} |
| 105 |
|
| 106 |
// Wrapper methods routed to the internal client. |
| 107 |
|
| 108 |
// Close closes the connection to the API service. The user should invoke this when |
| 109 |
// the client is no longer required. |
| 110 |
func (c *ImageVersionsClient) Close() error { |
| 111 |
return c.internalClient.Close() |
| 112 |
} |
| 113 |
|
| 114 |
// setGoogleClientInfo sets the name and version of the application in |
| 115 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 116 |
// use by Google-written clients. |
| 117 |
func (c *ImageVersionsClient) setGoogleClientInfo(keyval ...string) { |
| 118 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 119 |
} |
| 120 |
|
| 121 |
// Connection returns a connection to the API service. |
| 122 |
// |
| 123 |
// Deprecated: Connections are now pooled so this method does not always |
| 124 |
// return the same resource. |
| 125 |
func (c *ImageVersionsClient) Connection() *grpc.ClientConn { |
| 126 |
return c.internalClient.Connection() |
| 127 |
} |
| 128 |
|
| 129 |
// ListImageVersions list ImageVersions for provided location. |
| 130 |
func (c *ImageVersionsClient) ListImageVersions(ctx context.Context, req *servicepb.ListImageVersionsRequest, opts ...gax.CallOption) *ImageVersionIterator { |
| 131 |
return c.internalClient.ListImageVersions(ctx, req, opts...) |
| 132 |
} |
| 133 |
|
| 134 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 135 |
func (c *ImageVersionsClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 136 |
return c.internalClient.DeleteOperation(ctx, req, opts...) |
| 137 |
} |
| 138 |
|
| 139 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 140 |
func (c *ImageVersionsClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 141 |
return c.internalClient.GetOperation(ctx, req, opts...) |
| 142 |
} |
| 143 |
|
| 144 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 145 |
func (c *ImageVersionsClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 146 |
return c.internalClient.ListOperations(ctx, req, opts...) |
| 147 |
} |
| 148 |
|
| 149 |
// imageVersionsGRPCClient is a client for interacting with Cloud Composer API over gRPC transport. |
| 150 |
// |
| 151 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 152 |
type imageVersionsGRPCClient struct { |
| 153 |
// Connection pool of gRPC connections to the service. |
| 154 |
connPool gtransport.ConnPool |
| 155 |
|
| 156 |
// Points back to the CallOptions field of the containing ImageVersionsClient |
| 157 |
CallOptions **ImageVersionsCallOptions |
| 158 |
|
| 159 |
// The gRPC API client. |
| 160 |
imageVersionsClient servicepb.ImageVersionsClient |
| 161 |
|
| 162 |
operationsClient longrunningpb.OperationsClient |
| 163 |
|
| 164 |
// The x-goog-* metadata to be sent with each request. |
| 165 |
xGoogHeaders []string |
| 166 |
|
| 167 |
logger *slog.Logger |
| 168 |
} |
| 169 |
|
| 170 |
// NewImageVersionsClient creates a new image versions client based on gRPC. |
| 171 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 172 |
// |
| 173 |
// Readonly service to query available ImageVersions. |
| 174 |
func NewImageVersionsClient(ctx context.Context, opts ...option.ClientOption) (*ImageVersionsClient, error) { |
| 175 |
clientOpts := defaultImageVersionsGRPCClientOptions() |
| 176 |
if newImageVersionsClientHook != nil { |
| 177 |
hookOpts, err := newImageVersionsClientHook(ctx, clientHookParams{}) |
| 178 |
if err != nil { |
| 179 |
return nil, err |
| 180 |
} |
| 181 |
clientOpts = append(clientOpts, hookOpts...) |
| 182 |
} |
| 183 |
|
| 184 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 185 |
if err != nil { |
| 186 |
return nil, err |
| 187 |
} |
| 188 |
client := ImageVersionsClient{CallOptions: defaultImageVersionsCallOptions()} |
| 189 |
|
| 190 |
c := &imageVersionsGRPCClient{ |
| 191 |
connPool: connPool, |
| 192 |
imageVersionsClient: servicepb.NewImageVersionsClient(connPool), |
| 193 |
CallOptions: &client.CallOptions, |
| 194 |
logger: internaloption.GetLogger(opts), |
| 195 |
operationsClient: longrunningpb.NewOperationsClient(connPool), |
| 196 |
} |
| 197 |
c.setGoogleClientInfo() |
| 198 |
|
| 199 |
client.internalClient = c |
| 200 |
|
| 201 |
return &client, nil |
| 202 |
} |
| 203 |
|
| 204 |
// Connection returns a connection to the API service. |
| 205 |
// |
| 206 |
// Deprecated: Connections are now pooled so this method does not always |
| 207 |
// return the same resource. |
| 208 |
func (c *imageVersionsGRPCClient) Connection() *grpc.ClientConn { |
| 209 |
return c.connPool.Conn() |
| 210 |
} |
| 211 |
|
| 212 |
// setGoogleClientInfo sets the name and version of the application in |
| 213 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 214 |
// use by Google-written clients. |
| 215 |
func (c *imageVersionsGRPCClient) setGoogleClientInfo(keyval ...string) { |
| 216 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 217 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 218 |
c.xGoogHeaders = []string{ |
| 219 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 220 |
} |
| 221 |
} |
| 222 |
|
| 223 |
// Close closes the connection to the API service. The user should invoke this when |
| 224 |
// the client is no longer required. |
| 225 |
func (c *imageVersionsGRPCClient) Close() error { |
| 226 |
return c.connPool.Close() |
| 227 |
} |
| 228 |
|
| 229 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 230 |
type imageVersionsRESTClient struct { |
| 231 |
// The http endpoint to connect to. |
| 232 |
endpoint string |
| 233 |
|
| 234 |
// The http client. |
| 235 |
httpClient *http.Client |
| 236 |
|
| 237 |
// The x-goog-* headers to be sent with each request. |
| 238 |
xGoogHeaders []string |
| 239 |
|
| 240 |
// Points back to the CallOptions field of the containing ImageVersionsClient |
| 241 |
CallOptions **ImageVersionsCallOptions |
| 242 |
|
| 243 |
logger *slog.Logger |
| 244 |
} |
| 245 |
|
| 246 |
// NewImageVersionsRESTClient creates a new image versions rest client. |
| 247 |
// |
| 248 |
// Readonly service to query available ImageVersions. |
| 249 |
func NewImageVersionsRESTClient(ctx context.Context, opts ...option.ClientOption) (*ImageVersionsClient, error) { |
| 250 |
clientOpts := append(defaultImageVersionsRESTClientOptions(), opts...) |
| 251 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 252 |
if err != nil { |
| 253 |
return nil, err |
| 254 |
} |
| 255 |
|
| 256 |
callOpts := defaultImageVersionsRESTCallOptions() |
| 257 |
c := &imageVersionsRESTClient{ |
| 258 |
endpoint: endpoint, |
| 259 |
httpClient: httpClient, |
| 260 |
CallOptions: &callOpts, |
| 261 |
logger: internaloption.GetLogger(opts), |
| 262 |
} |
| 263 |
c.setGoogleClientInfo() |
| 264 |
|
| 265 |
return &ImageVersionsClient{internalClient: c, CallOptions: callOpts}, nil |
| 266 |
} |
| 267 |
|
| 268 |
func defaultImageVersionsRESTClientOptions() []option.ClientOption { |
| 269 |
return []option.ClientOption{ |
| 270 |
internaloption.WithDefaultEndpoint("https://composer.googleapis.com"), |
| 271 |
internaloption.WithDefaultEndpointTemplate("https://composer.UNIVERSE_DOMAIN"), |
| 272 |
internaloption.WithDefaultMTLSEndpoint("https://composer.mtls.googleapis.com"), |
| 273 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 274 |
internaloption.WithDefaultAudience("https://composer.googleapis.com/"), |
| 275 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 276 |
internaloption.EnableNewAuthLibrary(), |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
// setGoogleClientInfo sets the name and version of the application in |
| 281 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 282 |
// use by Google-written clients. |
| 283 |
func (c *imageVersionsRESTClient) setGoogleClientInfo(keyval ...string) { |
| 284 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 285 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 286 |
c.xGoogHeaders = []string{ |
| 287 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 288 |
} |
| 289 |
} |
| 290 |
|
| 291 |
// Close closes the connection to the API service. The user should invoke this when |
| 292 |
// the client is no longer required. |
| 293 |
func (c *imageVersionsRESTClient) Close() error { |
| 294 |
// Replace httpClient with nil to force cleanup. |
| 295 |
c.httpClient = nil |
| 296 |
return nil |
| 297 |
} |
| 298 |
|
| 299 |
// Connection returns a connection to the API service. |
| 300 |
// |
| 301 |
// Deprecated: This method always returns nil. |
| 302 |
func (c *imageVersionsRESTClient) Connection() *grpc.ClientConn { |
| 303 |
return nil |
| 304 |
} |
| 305 |
func (c *imageVersionsGRPCClient) ListImageVersions(ctx context.Context, req *servicepb.ListImageVersionsRequest, opts ...gax.CallOption) *ImageVersionIterator { |
| 306 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 307 |
|
| 308 |
hds = append(c.xGoogHeaders, hds...) |
| 309 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 310 |
opts = append((*c.CallOptions).ListImageVersions[0:len((*c.CallOptions).ListImageVersions):len((*c.CallOptions).ListImageVersions)], opts...) |
| 311 |
it := &ImageVersionIterator{} |
| 312 |
req = proto.Clone(req).(*servicepb.ListImageVersionsRequest) |
| 313 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*servicepb.ImageVersion, string, error) { |
| 314 |
resp := &servicepb.ListImageVersionsResponse{} |
| 315 |
if pageToken != "" { |
| 316 |
req.PageToken = pageToken |
| 317 |
} |
| 318 |
if pageSize > math.MaxInt32 { |
| 319 |
req.PageSize = math.MaxInt32 |
| 320 |
} else if pageSize != 0 { |
| 321 |
req.PageSize = int32(pageSize) |
| 322 |
} |
| 323 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 324 |
var err error |
| 325 |
resp, err = executeRPC(ctx, c.imageVersionsClient.ListImageVersions, req, settings.GRPC, c.logger, "ListImageVersions") |
| 326 |
return err |
| 327 |
}, opts...) |
| 328 |
if err != nil { |
| 329 |
return nil, "", err |
| 330 |
} |
| 331 |
|
| 332 |
it.Response = resp |
| 333 |
return resp.GetImageVersions(), resp.GetNextPageToken(), nil |
| 334 |
} |
| 335 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 336 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 337 |
if err != nil { |
| 338 |
return "", err |
| 339 |
} |
| 340 |
it.items = append(it.items, items...) |
| 341 |
return nextPageToken, nil |
| 342 |
} |
| 343 |
|
| 344 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 345 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 346 |
it.pageInfo.Token = req.GetPageToken() |
| 347 |
|
| 348 |
return it |
| 349 |
} |
| 350 |
|
| 351 |
func (c *imageVersionsGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 352 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 353 |
|
| 354 |
hds = append(c.xGoogHeaders, hds...) |
| 355 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 356 |
opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) |
| 357 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 358 |
var err error |
| 359 |
_, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") |
| 360 |
return err |
| 361 |
}, opts...) |
| 362 |
return err |
| 363 |
} |
| 364 |
|
| 365 |
func (c *imageVersionsGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 366 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 367 |
|
| 368 |
hds = append(c.xGoogHeaders, hds...) |
| 369 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 370 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 371 |
var resp *longrunningpb.Operation |
| 372 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 373 |
var err error |
| 374 |
resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") |
| 375 |
return err |
| 376 |
}, opts...) |
| 377 |
if err != nil { |
| 378 |
return nil, err |
| 379 |
} |
| 380 |
return resp, nil |
| 381 |
} |
| 382 |
|
| 383 |
func (c *imageVersionsGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 384 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 385 |
|
| 386 |
hds = append(c.xGoogHeaders, hds...) |
| 387 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 388 |
opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) |
| 389 |
it := &OperationIterator{} |
| 390 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 391 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 392 |
resp := &longrunningpb.ListOperationsResponse{} |
| 393 |
if pageToken != "" { |
| 394 |
req.PageToken = pageToken |
| 395 |
} |
| 396 |
if pageSize > math.MaxInt32 { |
| 397 |
req.PageSize = math.MaxInt32 |
| 398 |
} else if pageSize != 0 { |
| 399 |
req.PageSize = int32(pageSize) |
| 400 |
} |
| 401 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 402 |
var err error |
| 403 |
resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") |
| 404 |
return err |
| 405 |
}, opts...) |
| 406 |
if err != nil { |
| 407 |
return nil, "", err |
| 408 |
} |
| 409 |
|
| 410 |
it.Response = resp |
| 411 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 412 |
} |
| 413 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 414 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 415 |
if err != nil { |
| 416 |
return "", err |
| 417 |
} |
| 418 |
it.items = append(it.items, items...) |
| 419 |
return nextPageToken, nil |
| 420 |
} |
| 421 |
|
| 422 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 423 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 424 |
it.pageInfo.Token = req.GetPageToken() |
| 425 |
|
| 426 |
return it |
| 427 |
} |
| 428 |
|
| 429 |
// ListImageVersions list ImageVersions for provided location. |
| 430 |
func (c *imageVersionsRESTClient) ListImageVersions(ctx context.Context, req *servicepb.ListImageVersionsRequest, opts ...gax.CallOption) *ImageVersionIterator { |
| 431 |
it := &ImageVersionIterator{} |
| 432 |
req = proto.Clone(req).(*servicepb.ListImageVersionsRequest) |
| 433 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 434 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*servicepb.ImageVersion, string, error) { |
| 435 |
resp := &servicepb.ListImageVersionsResponse{} |
| 436 |
if pageToken != "" { |
| 437 |
req.PageToken = pageToken |
| 438 |
} |
| 439 |
if pageSize > math.MaxInt32 { |
| 440 |
req.PageSize = math.MaxInt32 |
| 441 |
} else if pageSize != 0 { |
| 442 |
req.PageSize = int32(pageSize) |
| 443 |
} |
| 444 |
baseUrl, err := url.Parse(c.endpoint) |
| 445 |
if err != nil { |
| 446 |
return nil, "", err |
| 447 |
} |
| 448 |
baseUrl.Path += fmt.Sprintf("/v1/%v/imageVersions", req.GetParent()) |
| 449 |
|
| 450 |
params := url.Values{} |
| 451 |
params.Add("$alt", "json;enum-encoding=int") |
| 452 |
if req.GetIncludePastReleases() { |
| 453 |
params.Add("includePastReleases", fmt.Sprintf("%v", req.GetIncludePastReleases())) |
| 454 |
} |
| 455 |
if req.GetPageSize() != 0 { |
| 456 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 457 |
} |
| 458 |
if req.GetPageToken() != "" { |
| 459 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 460 |
} |
| 461 |
|
| 462 |
baseUrl.RawQuery = params.Encode() |
| 463 |
|
| 464 |
// Build HTTP headers from client and context metadata. |
| 465 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 466 |
headers := gax.BuildHeaders(ctx, hds...) |
| 467 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 468 |
if settings.Path != "" { |
| 469 |
baseUrl.Path = settings.Path |
| 470 |
} |
| 471 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 472 |
if err != nil { |
| 473 |
return err |
| 474 |
} |
| 475 |
httpReq.Header = headers |
| 476 |
|
| 477 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListImageVersions") |
| 478 |
if err != nil { |
| 479 |
return err |
| 480 |
} |
| 481 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 482 |
return err |
| 483 |
} |
| 484 |
|
| 485 |
return nil |
| 486 |
}, opts...) |
| 487 |
if e != nil { |
| 488 |
return nil, "", e |
| 489 |
} |
| 490 |
it.Response = resp |
| 491 |
return resp.GetImageVersions(), resp.GetNextPageToken(), nil |
| 492 |
} |
| 493 |
|
| 494 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 495 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 496 |
if err != nil { |
| 497 |
return "", err |
| 498 |
} |
| 499 |
it.items = append(it.items, items...) |
| 500 |
return nextPageToken, nil |
| 501 |
} |
| 502 |
|
| 503 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 504 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 505 |
it.pageInfo.Token = req.GetPageToken() |
| 506 |
|
| 507 |
return it |
| 508 |
} |
| 509 |
|
| 510 |
// DeleteOperation is a utility method from google.longrunning.Operations. |
| 511 |
func (c *imageVersionsRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { |
| 512 |
baseUrl, err := url.Parse(c.endpoint) |
| 513 |
if err != nil { |
| 514 |
return err |
| 515 |
} |
| 516 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 517 |
|
| 518 |
params := url.Values{} |
| 519 |
params.Add("$alt", "json;enum-encoding=int") |
| 520 |
|
| 521 |
baseUrl.RawQuery = params.Encode() |
| 522 |
|
| 523 |
// Build HTTP headers from client and context metadata. |
| 524 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 525 |
|
| 526 |
hds = append(c.xGoogHeaders, hds...) |
| 527 |
hds = append(hds, "Content-Type", "application/json") |
| 528 |
headers := gax.BuildHeaders(ctx, hds...) |
| 529 |
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 530 |
if settings.Path != "" { |
| 531 |
baseUrl.Path = settings.Path |
| 532 |
} |
| 533 |
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) |
| 534 |
if err != nil { |
| 535 |
return err |
| 536 |
} |
| 537 |
httpReq = httpReq.WithContext(ctx) |
| 538 |
httpReq.Header = headers |
| 539 |
|
| 540 |
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") |
| 541 |
return err |
| 542 |
}, opts...) |
| 543 |
} |
| 544 |
|
| 545 |
// GetOperation is a utility method from google.longrunning.Operations. |
| 546 |
func (c *imageVersionsRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { |
| 547 |
baseUrl, err := url.Parse(c.endpoint) |
| 548 |
if err != nil { |
| 549 |
return nil, err |
| 550 |
} |
| 551 |
baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName()) |
| 552 |
|
| 553 |
params := url.Values{} |
| 554 |
params.Add("$alt", "json;enum-encoding=int") |
| 555 |
|
| 556 |
baseUrl.RawQuery = params.Encode() |
| 557 |
|
| 558 |
// Build HTTP headers from client and context metadata. |
| 559 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} |
| 560 |
|
| 561 |
hds = append(c.xGoogHeaders, hds...) |
| 562 |
hds = append(hds, "Content-Type", "application/json") |
| 563 |
headers := gax.BuildHeaders(ctx, hds...) |
| 564 |
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) |
| 565 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 566 |
resp := &longrunningpb.Operation{} |
| 567 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 568 |
if settings.Path != "" { |
| 569 |
baseUrl.Path = settings.Path |
| 570 |
} |
| 571 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 572 |
if err != nil { |
| 573 |
return err |
| 574 |
} |
| 575 |
httpReq = httpReq.WithContext(ctx) |
| 576 |
httpReq.Header = headers |
| 577 |
|
| 578 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") |
| 579 |
if err != nil { |
| 580 |
return err |
| 581 |
} |
| 582 |
|
| 583 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 584 |
return err |
| 585 |
} |
| 586 |
|
| 587 |
return nil |
| 588 |
}, opts...) |
| 589 |
if e != nil { |
| 590 |
return nil, e |
| 591 |
} |
| 592 |
return resp, nil |
| 593 |
} |
| 594 |
|
| 595 |
// ListOperations is a utility method from google.longrunning.Operations. |
| 596 |
func (c *imageVersionsRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { |
| 597 |
it := &OperationIterator{} |
| 598 |
req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) |
| 599 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 600 |
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { |
| 601 |
resp := &longrunningpb.ListOperationsResponse{} |
| 602 |
if pageToken != "" { |
| 603 |
req.PageToken = pageToken |
| 604 |
} |
| 605 |
if pageSize > math.MaxInt32 { |
| 606 |
req.PageSize = math.MaxInt32 |
| 607 |
} else if pageSize != 0 { |
| 608 |
req.PageSize = int32(pageSize) |
| 609 |
} |
| 610 |
baseUrl, err := url.Parse(c.endpoint) |
| 611 |
if err != nil { |
| 612 |
return nil, "", err |
| 613 |
} |
| 614 |
baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName()) |
| 615 |
|
| 616 |
params := url.Values{} |
| 617 |
params.Add("$alt", "json;enum-encoding=int") |
| 618 |
if req.GetFilter() != "" { |
| 619 |
params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) |
| 620 |
} |
| 621 |
if req.GetPageSize() != 0 { |
| 622 |
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) |
| 623 |
} |
| 624 |
if req.GetPageToken() != "" { |
| 625 |
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) |
| 626 |
} |
| 627 |
|
| 628 |
baseUrl.RawQuery = params.Encode() |
| 629 |
|
| 630 |
// Build HTTP headers from client and context metadata. |
| 631 |
hds := append(c.xGoogHeaders, "Content-Type", "application/json") |
| 632 |
headers := gax.BuildHeaders(ctx, hds...) |
| 633 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 634 |
if settings.Path != "" { |
| 635 |
baseUrl.Path = settings.Path |
| 636 |
} |
| 637 |
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) |
| 638 |
if err != nil { |
| 639 |
return err |
| 640 |
} |
| 641 |
httpReq.Header = headers |
| 642 |
|
| 643 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") |
| 644 |
if err != nil { |
| 645 |
return err |
| 646 |
} |
| 647 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 648 |
return err |
| 649 |
} |
| 650 |
|
| 651 |
return nil |
| 652 |
}, opts...) |
| 653 |
if e != nil { |
| 654 |
return nil, "", e |
| 655 |
} |
| 656 |
it.Response = resp |
| 657 |
return resp.GetOperations(), resp.GetNextPageToken(), nil |
| 658 |
} |
| 659 |
|
| 660 |
fetch := func(pageSize int, pageToken string) (string, error) { |
| 661 |
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) |
| 662 |
if err != nil { |
| 663 |
return "", err |
| 664 |
} |
| 665 |
it.items = append(it.items, items...) |
| 666 |
return nextPageToken, nil |
| 667 |
} |
| 668 |
|
| 669 |
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) |
| 670 |
it.pageInfo.MaxSize = int(req.GetPageSize()) |
| 671 |
it.pageInfo.Token = req.GetPageToken() |
| 672 |
|
| 673 |
return it |
| 674 |
} |