cloud.google.com/go/aiplatform@v1.106.0/apiv1beta1/extension_registry_client.go (about) 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 aiplatform 18 19 import ( 20 "bytes" 21 "context" 22 "fmt" 23 "log/slog" 24 "math" 25 "net/http" 26 "net/url" 27 28 aiplatformpb "cloud.google.com/go/aiplatform/apiv1beta1/aiplatformpb" 29 iampb "cloud.google.com/go/iam/apiv1/iampb" 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/protobuf/encoding/protojson" 42 "google.golang.org/protobuf/proto" 43 ) 44 45 var newExtensionRegistryClientHook clientHook 46 47 // ExtensionRegistryCallOptions contains the retry settings for each method of ExtensionRegistryClient. 48 type ExtensionRegistryCallOptions struct { 49 ImportExtension []gax.CallOption 50 GetExtension []gax.CallOption 51 ListExtensions []gax.CallOption 52 UpdateExtension []gax.CallOption 53 DeleteExtension []gax.CallOption 54 GetLocation []gax.CallOption 55 ListLocations []gax.CallOption 56 GetIamPolicy []gax.CallOption 57 SetIamPolicy []gax.CallOption 58 TestIamPermissions []gax.CallOption 59 CancelOperation []gax.CallOption 60 DeleteOperation []gax.CallOption 61 GetOperation []gax.CallOption 62 ListOperations []gax.CallOption 63 WaitOperation []gax.CallOption 64 } 65 66 func defaultExtensionRegistryGRPCClientOptions() []option.ClientOption { 67 return []option.ClientOption{ 68 internaloption.WithDefaultEndpoint("aiplatform.googleapis.com:443"), 69 internaloption.WithDefaultEndpointTemplate("aiplatform.UNIVERSE_DOMAIN:443"), 70 internaloption.WithDefaultMTLSEndpoint("aiplatform.mtls.googleapis.com:443"), 71 internaloption.WithDefaultUniverseDomain("googleapis.com"), 72 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 73 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 74 internaloption.EnableJwtWithScope(), 75 internaloption.EnableNewAuthLibrary(), 76 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 77 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 78 } 79 } 80 81 func defaultExtensionRegistryCallOptions() *ExtensionRegistryCallOptions { 82 return &ExtensionRegistryCallOptions{ 83 ImportExtension: []gax.CallOption{}, 84 GetExtension: []gax.CallOption{}, 85 ListExtensions: []gax.CallOption{}, 86 UpdateExtension: []gax.CallOption{}, 87 DeleteExtension: []gax.CallOption{}, 88 GetLocation: []gax.CallOption{}, 89 ListLocations: []gax.CallOption{}, 90 GetIamPolicy: []gax.CallOption{}, 91 SetIamPolicy: []gax.CallOption{}, 92 TestIamPermissions: []gax.CallOption{}, 93 CancelOperation: []gax.CallOption{}, 94 DeleteOperation: []gax.CallOption{}, 95 GetOperation: []gax.CallOption{}, 96 ListOperations: []gax.CallOption{}, 97 WaitOperation: []gax.CallOption{}, 98 } 99 } 100 101 func defaultExtensionRegistryRESTCallOptions() *ExtensionRegistryCallOptions { 102 return &ExtensionRegistryCallOptions{ 103 ImportExtension: []gax.CallOption{}, 104 GetExtension: []gax.CallOption{}, 105 ListExtensions: []gax.CallOption{}, 106 UpdateExtension: []gax.CallOption{}, 107 DeleteExtension: []gax.CallOption{}, 108 GetLocation: []gax.CallOption{}, 109 ListLocations: []gax.CallOption{}, 110 GetIamPolicy: []gax.CallOption{}, 111 SetIamPolicy: []gax.CallOption{}, 112 TestIamPermissions: []gax.CallOption{}, 113 CancelOperation: []gax.CallOption{}, 114 DeleteOperation: []gax.CallOption{}, 115 GetOperation: []gax.CallOption{}, 116 ListOperations: []gax.CallOption{}, 117 WaitOperation: []gax.CallOption{}, 118 } 119 } 120 121 // internalExtensionRegistryClient is an interface that defines the methods available from Vertex AI API. 122 type internalExtensionRegistryClient interface { 123 Close() error 124 setGoogleClientInfo(...string) 125 Connection() *grpc.ClientConn 126 ImportExtension(context.Context, *aiplatformpb.ImportExtensionRequest, ...gax.CallOption) (*ImportExtensionOperation, error) 127 ImportExtensionOperation(name string) *ImportExtensionOperation 128 GetExtension(context.Context, *aiplatformpb.GetExtensionRequest, ...gax.CallOption) (*aiplatformpb.Extension, error) 129 ListExtensions(context.Context, *aiplatformpb.ListExtensionsRequest, ...gax.CallOption) *ExtensionIterator 130 UpdateExtension(context.Context, *aiplatformpb.UpdateExtensionRequest, ...gax.CallOption) (*aiplatformpb.Extension, error) 131 DeleteExtension(context.Context, *aiplatformpb.DeleteExtensionRequest, ...gax.CallOption) (*DeleteExtensionOperation, error) 132 DeleteExtensionOperation(name string) *DeleteExtensionOperation 133 GetLocation(context.Context, *locationpb.GetLocationRequest, ...gax.CallOption) (*locationpb.Location, error) 134 ListLocations(context.Context, *locationpb.ListLocationsRequest, ...gax.CallOption) *LocationIterator 135 GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 136 SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error) 137 TestIamPermissions(context.Context, *iampb.TestIamPermissionsRequest, ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) 138 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error 139 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error 140 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 141 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator 142 WaitOperation(context.Context, *longrunningpb.WaitOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error) 143 } 144 145 // ExtensionRegistryClient is a client for interacting with Vertex AI API. 146 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 147 // 148 // A service for managing Vertex AI’s Extension registry. 149 type ExtensionRegistryClient struct { 150 // The internal transport-dependent client. 151 internalClient internalExtensionRegistryClient 152 153 // The call options for this service. 154 CallOptions *ExtensionRegistryCallOptions 155 156 // LROClient is used internally to handle long-running operations. 157 // It is exposed so that its CallOptions can be modified if required. 158 // Users should not Close this client. 159 LROClient *lroauto.OperationsClient 160 } 161 162 // Wrapper methods routed to the internal client. 163 164 // Close closes the connection to the API service. The user should invoke this when 165 // the client is no longer required. 166 func (c *ExtensionRegistryClient) Close() error { 167 return c.internalClient.Close() 168 } 169 170 // setGoogleClientInfo sets the name and version of the application in 171 // the `x-goog-api-client` header passed on each request. Intended for 172 // use by Google-written clients. 173 func (c *ExtensionRegistryClient) setGoogleClientInfo(keyval ...string) { 174 c.internalClient.setGoogleClientInfo(keyval...) 175 } 176 177 // Connection returns a connection to the API service. 178 // 179 // Deprecated: Connections are now pooled so this method does not always 180 // return the same resource. 181 func (c *ExtensionRegistryClient) Connection() *grpc.ClientConn { 182 return c.internalClient.Connection() 183 } 184 185 // ImportExtension imports an Extension. 186 func (c *ExtensionRegistryClient) ImportExtension(ctx context.Context, req *aiplatformpb.ImportExtensionRequest, opts ...gax.CallOption) (*ImportExtensionOperation, error) { 187 return c.internalClient.ImportExtension(ctx, req, opts...) 188 } 189 190 // ImportExtensionOperation returns a new ImportExtensionOperation from a given name. 191 // The name must be that of a previously created ImportExtensionOperation, possibly from a different process. 192 func (c *ExtensionRegistryClient) ImportExtensionOperation(name string) *ImportExtensionOperation { 193 return c.internalClient.ImportExtensionOperation(name) 194 } 195 196 // GetExtension gets an Extension. 197 func (c *ExtensionRegistryClient) GetExtension(ctx context.Context, req *aiplatformpb.GetExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 198 return c.internalClient.GetExtension(ctx, req, opts...) 199 } 200 201 // ListExtensions lists Extensions in a location. 202 func (c *ExtensionRegistryClient) ListExtensions(ctx context.Context, req *aiplatformpb.ListExtensionsRequest, opts ...gax.CallOption) *ExtensionIterator { 203 return c.internalClient.ListExtensions(ctx, req, opts...) 204 } 205 206 // UpdateExtension updates an Extension. 207 func (c *ExtensionRegistryClient) UpdateExtension(ctx context.Context, req *aiplatformpb.UpdateExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 208 return c.internalClient.UpdateExtension(ctx, req, opts...) 209 } 210 211 // DeleteExtension deletes an Extension. 212 func (c *ExtensionRegistryClient) DeleteExtension(ctx context.Context, req *aiplatformpb.DeleteExtensionRequest, opts ...gax.CallOption) (*DeleteExtensionOperation, error) { 213 return c.internalClient.DeleteExtension(ctx, req, opts...) 214 } 215 216 // DeleteExtensionOperation returns a new DeleteExtensionOperation from a given name. 217 // The name must be that of a previously created DeleteExtensionOperation, possibly from a different process. 218 func (c *ExtensionRegistryClient) DeleteExtensionOperation(name string) *DeleteExtensionOperation { 219 return c.internalClient.DeleteExtensionOperation(name) 220 } 221 222 // GetLocation gets information about a location. 223 func (c *ExtensionRegistryClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 224 return c.internalClient.GetLocation(ctx, req, opts...) 225 } 226 227 // ListLocations lists information about the supported locations for this service. 228 func (c *ExtensionRegistryClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 229 return c.internalClient.ListLocations(ctx, req, opts...) 230 } 231 232 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 233 // if the resource exists and does not have a policy set. 234 func (c *ExtensionRegistryClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 235 return c.internalClient.GetIamPolicy(ctx, req, opts...) 236 } 237 238 // SetIamPolicy sets the access control policy on the specified resource. Replaces 239 // any existing policy. 240 // 241 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 242 // errors. 243 func (c *ExtensionRegistryClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 244 return c.internalClient.SetIamPolicy(ctx, req, opts...) 245 } 246 247 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 248 // resource does not exist, this will return an empty set of 249 // permissions, not a NOT_FOUND error. 250 // 251 // Note: This operation is designed to be used for building 252 // permission-aware UIs and command-line tools, not for authorization 253 // checking. This operation may “fail open” without warning. 254 func (c *ExtensionRegistryClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 255 return c.internalClient.TestIamPermissions(ctx, req, opts...) 256 } 257 258 // CancelOperation is a utility method from google.longrunning.Operations. 259 func (c *ExtensionRegistryClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 260 return c.internalClient.CancelOperation(ctx, req, opts...) 261 } 262 263 // DeleteOperation is a utility method from google.longrunning.Operations. 264 func (c *ExtensionRegistryClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 265 return c.internalClient.DeleteOperation(ctx, req, opts...) 266 } 267 268 // GetOperation is a utility method from google.longrunning.Operations. 269 func (c *ExtensionRegistryClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 270 return c.internalClient.GetOperation(ctx, req, opts...) 271 } 272 273 // ListOperations is a utility method from google.longrunning.Operations. 274 func (c *ExtensionRegistryClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 275 return c.internalClient.ListOperations(ctx, req, opts...) 276 } 277 278 // WaitOperation is a utility method from google.longrunning.Operations. 279 func (c *ExtensionRegistryClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 280 return c.internalClient.WaitOperation(ctx, req, opts...) 281 } 282 283 // extensionRegistryGRPCClient is a client for interacting with Vertex AI API over gRPC transport. 284 // 285 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 286 type extensionRegistryGRPCClient struct { 287 // Connection pool of gRPC connections to the service. 288 connPool gtransport.ConnPool 289 290 // Points back to the CallOptions field of the containing ExtensionRegistryClient 291 CallOptions **ExtensionRegistryCallOptions 292 293 // The gRPC API client. 294 extensionRegistryClient aiplatformpb.ExtensionRegistryServiceClient 295 296 // LROClient is used internally to handle long-running operations. 297 // It is exposed so that its CallOptions can be modified if required. 298 // Users should not Close this client. 299 LROClient **lroauto.OperationsClient 300 301 operationsClient longrunningpb.OperationsClient 302 303 iamPolicyClient iampb.IAMPolicyClient 304 305 locationsClient locationpb.LocationsClient 306 307 // The x-goog-* metadata to be sent with each request. 308 xGoogHeaders []string 309 310 logger *slog.Logger 311 } 312 313 // NewExtensionRegistryClient creates a new extension registry service client based on gRPC. 314 // The returned client must be Closed when it is done being used to clean up its underlying connections. 315 // 316 // A service for managing Vertex AI’s Extension registry. 317 func NewExtensionRegistryClient(ctx context.Context, opts ...option.ClientOption) (*ExtensionRegistryClient, error) { 318 clientOpts := defaultExtensionRegistryGRPCClientOptions() 319 if newExtensionRegistryClientHook != nil { 320 hookOpts, err := newExtensionRegistryClientHook(ctx, clientHookParams{}) 321 if err != nil { 322 return nil, err 323 } 324 clientOpts = append(clientOpts, hookOpts...) 325 } 326 327 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 328 if err != nil { 329 return nil, err 330 } 331 client := ExtensionRegistryClient{CallOptions: defaultExtensionRegistryCallOptions()} 332 333 c := &extensionRegistryGRPCClient{ 334 connPool: connPool, 335 extensionRegistryClient: aiplatformpb.NewExtensionRegistryServiceClient(connPool), 336 CallOptions: &client.CallOptions, 337 logger: internaloption.GetLogger(opts), 338 operationsClient: longrunningpb.NewOperationsClient(connPool), 339 iamPolicyClient: iampb.NewIAMPolicyClient(connPool), 340 locationsClient: locationpb.NewLocationsClient(connPool), 341 } 342 c.setGoogleClientInfo() 343 344 client.internalClient = c 345 346 client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool)) 347 if err != nil { 348 // This error "should not happen", since we are just reusing old connection pool 349 // and never actually need to dial. 350 // If this does happen, we could leak connp. However, we cannot close conn: 351 // If the user invoked the constructor with option.WithGRPCConn, 352 // we would close a connection that's still in use. 353 // TODO: investigate error conditions. 354 return nil, err 355 } 356 c.LROClient = &client.LROClient 357 return &client, nil 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 *extensionRegistryGRPCClient) Connection() *grpc.ClientConn { 365 return c.connPool.Conn() 366 } 367 368 // setGoogleClientInfo sets the name and version of the application in 369 // the `x-goog-api-client` header passed on each request. Intended for 370 // use by Google-written clients. 371 func (c *extensionRegistryGRPCClient) setGoogleClientInfo(keyval ...string) { 372 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 373 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) 374 c.xGoogHeaders = []string{ 375 "x-goog-api-client", gax.XGoogHeader(kv...), 376 } 377 } 378 379 // Close closes the connection to the API service. The user should invoke this when 380 // the client is no longer required. 381 func (c *extensionRegistryGRPCClient) Close() error { 382 return c.connPool.Close() 383 } 384 385 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 386 type extensionRegistryRESTClient struct { 387 // The http endpoint to connect to. 388 endpoint string 389 390 // The http client. 391 httpClient *http.Client 392 393 // LROClient is used internally to handle long-running operations. 394 // It is exposed so that its CallOptions can be modified if required. 395 // Users should not Close this client. 396 LROClient **lroauto.OperationsClient 397 398 // The x-goog-* headers to be sent with each request. 399 xGoogHeaders []string 400 401 // Points back to the CallOptions field of the containing ExtensionRegistryClient 402 CallOptions **ExtensionRegistryCallOptions 403 404 logger *slog.Logger 405 } 406 407 // NewExtensionRegistryRESTClient creates a new extension registry service rest client. 408 // 409 // A service for managing Vertex AI’s Extension registry. 410 func NewExtensionRegistryRESTClient(ctx context.Context, opts ...option.ClientOption) (*ExtensionRegistryClient, error) { 411 clientOpts := append(defaultExtensionRegistryRESTClientOptions(), opts...) 412 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) 413 if err != nil { 414 return nil, err 415 } 416 417 callOpts := defaultExtensionRegistryRESTCallOptions() 418 c := &extensionRegistryRESTClient{ 419 endpoint: endpoint, 420 httpClient: httpClient, 421 CallOptions: &callOpts, 422 logger: internaloption.GetLogger(opts), 423 } 424 c.setGoogleClientInfo() 425 426 lroOpts := []option.ClientOption{ 427 option.WithHTTPClient(httpClient), 428 option.WithEndpoint(endpoint), 429 } 430 opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...) 431 if err != nil { 432 return nil, err 433 } 434 c.LROClient = &opClient 435 436 return &ExtensionRegistryClient{internalClient: c, CallOptions: callOpts}, nil 437 } 438 439 func defaultExtensionRegistryRESTClientOptions() []option.ClientOption { 440 return []option.ClientOption{ 441 internaloption.WithDefaultEndpoint("https://aiplatform.googleapis.com"), 442 internaloption.WithDefaultEndpointTemplate("https://aiplatform.UNIVERSE_DOMAIN"), 443 internaloption.WithDefaultMTLSEndpoint("https://aiplatform.mtls.googleapis.com"), 444 internaloption.WithDefaultUniverseDomain("googleapis.com"), 445 internaloption.WithDefaultAudience("https://aiplatform.googleapis.com/"), 446 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 447 internaloption.EnableNewAuthLibrary(), 448 } 449 } 450 451 // setGoogleClientInfo sets the name and version of the application in 452 // the `x-goog-api-client` header passed on each request. Intended for 453 // use by Google-written clients. 454 func (c *extensionRegistryRESTClient) setGoogleClientInfo(keyval ...string) { 455 kv := append([]string{"gl-go", gax.GoVersion}, keyval...) 456 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) 457 c.xGoogHeaders = []string{ 458 "x-goog-api-client", gax.XGoogHeader(kv...), 459 } 460 } 461 462 // Close closes the connection to the API service. The user should invoke this when 463 // the client is no longer required. 464 func (c *extensionRegistryRESTClient) Close() error { 465 // Replace httpClient with nil to force cleanup. 466 c.httpClient = nil 467 return nil 468 } 469 470 // Connection returns a connection to the API service. 471 // 472 // Deprecated: This method always returns nil. 473 func (c *extensionRegistryRESTClient) Connection() *grpc.ClientConn { 474 return nil 475 } 476 func (c *extensionRegistryGRPCClient) ImportExtension(ctx context.Context, req *aiplatformpb.ImportExtensionRequest, opts ...gax.CallOption) (*ImportExtensionOperation, error) { 477 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 478 479 hds = append(c.xGoogHeaders, hds...) 480 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 481 opts = append((*c.CallOptions).ImportExtension[0:len((*c.CallOptions).ImportExtension):len((*c.CallOptions).ImportExtension)], opts...) 482 var resp *longrunningpb.Operation 483 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 484 var err error 485 resp, err = executeRPC(ctx, c.extensionRegistryClient.ImportExtension, req, settings.GRPC, c.logger, "ImportExtension") 486 return err 487 }, opts...) 488 if err != nil { 489 return nil, err 490 } 491 return &ImportExtensionOperation{ 492 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 493 }, nil 494 } 495 496 func (c *extensionRegistryGRPCClient) GetExtension(ctx context.Context, req *aiplatformpb.GetExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 497 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 498 499 hds = append(c.xGoogHeaders, hds...) 500 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 501 opts = append((*c.CallOptions).GetExtension[0:len((*c.CallOptions).GetExtension):len((*c.CallOptions).GetExtension)], opts...) 502 var resp *aiplatformpb.Extension 503 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 504 var err error 505 resp, err = executeRPC(ctx, c.extensionRegistryClient.GetExtension, req, settings.GRPC, c.logger, "GetExtension") 506 return err 507 }, opts...) 508 if err != nil { 509 return nil, err 510 } 511 return resp, nil 512 } 513 514 func (c *extensionRegistryGRPCClient) ListExtensions(ctx context.Context, req *aiplatformpb.ListExtensionsRequest, opts ...gax.CallOption) *ExtensionIterator { 515 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 516 517 hds = append(c.xGoogHeaders, hds...) 518 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 519 opts = append((*c.CallOptions).ListExtensions[0:len((*c.CallOptions).ListExtensions):len((*c.CallOptions).ListExtensions)], opts...) 520 it := &ExtensionIterator{} 521 req = proto.Clone(req).(*aiplatformpb.ListExtensionsRequest) 522 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Extension, string, error) { 523 resp := &aiplatformpb.ListExtensionsResponse{} 524 if pageToken != "" { 525 req.PageToken = pageToken 526 } 527 if pageSize > math.MaxInt32 { 528 req.PageSize = math.MaxInt32 529 } else if pageSize != 0 { 530 req.PageSize = int32(pageSize) 531 } 532 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 533 var err error 534 resp, err = executeRPC(ctx, c.extensionRegistryClient.ListExtensions, req, settings.GRPC, c.logger, "ListExtensions") 535 return err 536 }, opts...) 537 if err != nil { 538 return nil, "", err 539 } 540 541 it.Response = resp 542 return resp.GetExtensions(), resp.GetNextPageToken(), nil 543 } 544 fetch := func(pageSize int, pageToken string) (string, error) { 545 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 546 if err != nil { 547 return "", err 548 } 549 it.items = append(it.items, items...) 550 return nextPageToken, nil 551 } 552 553 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 554 it.pageInfo.MaxSize = int(req.GetPageSize()) 555 it.pageInfo.Token = req.GetPageToken() 556 557 return it 558 } 559 560 func (c *extensionRegistryGRPCClient) UpdateExtension(ctx context.Context, req *aiplatformpb.UpdateExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 561 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "extension.name", url.QueryEscape(req.GetExtension().GetName()))} 562 563 hds = append(c.xGoogHeaders, hds...) 564 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 565 opts = append((*c.CallOptions).UpdateExtension[0:len((*c.CallOptions).UpdateExtension):len((*c.CallOptions).UpdateExtension)], opts...) 566 var resp *aiplatformpb.Extension 567 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 568 var err error 569 resp, err = executeRPC(ctx, c.extensionRegistryClient.UpdateExtension, req, settings.GRPC, c.logger, "UpdateExtension") 570 return err 571 }, opts...) 572 if err != nil { 573 return nil, err 574 } 575 return resp, nil 576 } 577 578 func (c *extensionRegistryGRPCClient) DeleteExtension(ctx context.Context, req *aiplatformpb.DeleteExtensionRequest, opts ...gax.CallOption) (*DeleteExtensionOperation, error) { 579 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 580 581 hds = append(c.xGoogHeaders, hds...) 582 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 583 opts = append((*c.CallOptions).DeleteExtension[0:len((*c.CallOptions).DeleteExtension):len((*c.CallOptions).DeleteExtension)], opts...) 584 var resp *longrunningpb.Operation 585 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 586 var err error 587 resp, err = executeRPC(ctx, c.extensionRegistryClient.DeleteExtension, req, settings.GRPC, c.logger, "DeleteExtension") 588 return err 589 }, opts...) 590 if err != nil { 591 return nil, err 592 } 593 return &DeleteExtensionOperation{ 594 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 595 }, nil 596 } 597 598 func (c *extensionRegistryGRPCClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 599 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 600 601 hds = append(c.xGoogHeaders, hds...) 602 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 603 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 604 var resp *locationpb.Location 605 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 606 var err error 607 resp, err = executeRPC(ctx, c.locationsClient.GetLocation, req, settings.GRPC, c.logger, "GetLocation") 608 return err 609 }, opts...) 610 if err != nil { 611 return nil, err 612 } 613 return resp, nil 614 } 615 616 func (c *extensionRegistryGRPCClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 617 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 618 619 hds = append(c.xGoogHeaders, hds...) 620 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 621 opts = append((*c.CallOptions).ListLocations[0:len((*c.CallOptions).ListLocations):len((*c.CallOptions).ListLocations)], opts...) 622 it := &LocationIterator{} 623 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 624 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 625 resp := &locationpb.ListLocationsResponse{} 626 if pageToken != "" { 627 req.PageToken = pageToken 628 } 629 if pageSize > math.MaxInt32 { 630 req.PageSize = math.MaxInt32 631 } else if pageSize != 0 { 632 req.PageSize = int32(pageSize) 633 } 634 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 635 var err error 636 resp, err = executeRPC(ctx, c.locationsClient.ListLocations, req, settings.GRPC, c.logger, "ListLocations") 637 return err 638 }, opts...) 639 if err != nil { 640 return nil, "", err 641 } 642 643 it.Response = resp 644 return resp.GetLocations(), resp.GetNextPageToken(), nil 645 } 646 fetch := func(pageSize int, pageToken string) (string, error) { 647 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 648 if err != nil { 649 return "", err 650 } 651 it.items = append(it.items, items...) 652 return nextPageToken, nil 653 } 654 655 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 656 it.pageInfo.MaxSize = int(req.GetPageSize()) 657 it.pageInfo.Token = req.GetPageToken() 658 659 return it 660 } 661 662 func (c *extensionRegistryGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 663 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 664 665 hds = append(c.xGoogHeaders, hds...) 666 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 667 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 668 var resp *iampb.Policy 669 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 670 var err error 671 resp, err = executeRPC(ctx, c.iamPolicyClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy") 672 return err 673 }, opts...) 674 if err != nil { 675 return nil, err 676 } 677 return resp, nil 678 } 679 680 func (c *extensionRegistryGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 681 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 682 683 hds = append(c.xGoogHeaders, hds...) 684 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 685 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 686 var resp *iampb.Policy 687 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 688 var err error 689 resp, err = executeRPC(ctx, c.iamPolicyClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy") 690 return err 691 }, opts...) 692 if err != nil { 693 return nil, err 694 } 695 return resp, nil 696 } 697 698 func (c *extensionRegistryGRPCClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 699 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 700 701 hds = append(c.xGoogHeaders, hds...) 702 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 703 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 704 var resp *iampb.TestIamPermissionsResponse 705 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 706 var err error 707 resp, err = executeRPC(ctx, c.iamPolicyClient.TestIamPermissions, req, settings.GRPC, c.logger, "TestIamPermissions") 708 return err 709 }, opts...) 710 if err != nil { 711 return nil, err 712 } 713 return resp, nil 714 } 715 716 func (c *extensionRegistryGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 717 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 718 719 hds = append(c.xGoogHeaders, hds...) 720 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 721 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...) 722 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 723 var err error 724 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation") 725 return err 726 }, opts...) 727 return err 728 } 729 730 func (c *extensionRegistryGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 731 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 732 733 hds = append(c.xGoogHeaders, hds...) 734 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 735 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...) 736 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 737 var err error 738 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation") 739 return err 740 }, opts...) 741 return err 742 } 743 744 func (c *extensionRegistryGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 745 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 746 747 hds = append(c.xGoogHeaders, hds...) 748 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 749 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 750 var resp *longrunningpb.Operation 751 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 752 var err error 753 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation") 754 return err 755 }, opts...) 756 if err != nil { 757 return nil, err 758 } 759 return resp, nil 760 } 761 762 func (c *extensionRegistryGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 763 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 764 765 hds = append(c.xGoogHeaders, hds...) 766 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 767 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...) 768 it := &OperationIterator{} 769 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 770 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 771 resp := &longrunningpb.ListOperationsResponse{} 772 if pageToken != "" { 773 req.PageToken = pageToken 774 } 775 if pageSize > math.MaxInt32 { 776 req.PageSize = math.MaxInt32 777 } else if pageSize != 0 { 778 req.PageSize = int32(pageSize) 779 } 780 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 781 var err error 782 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations") 783 return err 784 }, opts...) 785 if err != nil { 786 return nil, "", err 787 } 788 789 it.Response = resp 790 return resp.GetOperations(), resp.GetNextPageToken(), nil 791 } 792 fetch := func(pageSize int, pageToken string) (string, error) { 793 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 794 if err != nil { 795 return "", err 796 } 797 it.items = append(it.items, items...) 798 return nextPageToken, nil 799 } 800 801 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 802 it.pageInfo.MaxSize = int(req.GetPageSize()) 803 it.pageInfo.Token = req.GetPageToken() 804 805 return it 806 } 807 808 func (c *extensionRegistryGRPCClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 809 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 810 811 hds = append(c.xGoogHeaders, hds...) 812 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) 813 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 814 var resp *longrunningpb.Operation 815 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 816 var err error 817 resp, err = executeRPC(ctx, c.operationsClient.WaitOperation, req, settings.GRPC, c.logger, "WaitOperation") 818 return err 819 }, opts...) 820 if err != nil { 821 return nil, err 822 } 823 return resp, nil 824 } 825 826 // ImportExtension imports an Extension. 827 func (c *extensionRegistryRESTClient) ImportExtension(ctx context.Context, req *aiplatformpb.ImportExtensionRequest, opts ...gax.CallOption) (*ImportExtensionOperation, error) { 828 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 829 body := req.GetExtension() 830 jsonReq, err := m.Marshal(body) 831 if err != nil { 832 return nil, err 833 } 834 835 baseUrl, err := url.Parse(c.endpoint) 836 if err != nil { 837 return nil, err 838 } 839 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/extensions:import", req.GetParent()) 840 841 params := url.Values{} 842 params.Add("$alt", "json;enum-encoding=int") 843 844 baseUrl.RawQuery = params.Encode() 845 846 // Build HTTP headers from client and context metadata. 847 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} 848 849 hds = append(c.xGoogHeaders, hds...) 850 hds = append(hds, "Content-Type", "application/json") 851 headers := gax.BuildHeaders(ctx, hds...) 852 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 853 resp := &longrunningpb.Operation{} 854 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 855 if settings.Path != "" { 856 baseUrl.Path = settings.Path 857 } 858 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 859 if err != nil { 860 return err 861 } 862 httpReq = httpReq.WithContext(ctx) 863 httpReq.Header = headers 864 865 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ImportExtension") 866 if err != nil { 867 return err 868 } 869 if err := unm.Unmarshal(buf, resp); err != nil { 870 return err 871 } 872 873 return nil 874 }, opts...) 875 if e != nil { 876 return nil, e 877 } 878 879 override := fmt.Sprintf("/ui/%s", resp.GetName()) 880 return &ImportExtensionOperation{ 881 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 882 pollPath: override, 883 }, nil 884 } 885 886 // GetExtension gets an Extension. 887 func (c *extensionRegistryRESTClient) GetExtension(ctx context.Context, req *aiplatformpb.GetExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 888 baseUrl, err := url.Parse(c.endpoint) 889 if err != nil { 890 return nil, err 891 } 892 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 893 894 params := url.Values{} 895 params.Add("$alt", "json;enum-encoding=int") 896 897 baseUrl.RawQuery = params.Encode() 898 899 // Build HTTP headers from client and context metadata. 900 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 901 902 hds = append(c.xGoogHeaders, hds...) 903 hds = append(hds, "Content-Type", "application/json") 904 headers := gax.BuildHeaders(ctx, hds...) 905 opts = append((*c.CallOptions).GetExtension[0:len((*c.CallOptions).GetExtension):len((*c.CallOptions).GetExtension)], opts...) 906 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 907 resp := &aiplatformpb.Extension{} 908 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 909 if settings.Path != "" { 910 baseUrl.Path = settings.Path 911 } 912 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 913 if err != nil { 914 return err 915 } 916 httpReq = httpReq.WithContext(ctx) 917 httpReq.Header = headers 918 919 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetExtension") 920 if err != nil { 921 return err 922 } 923 924 if err := unm.Unmarshal(buf, resp); err != nil { 925 return err 926 } 927 928 return nil 929 }, opts...) 930 if e != nil { 931 return nil, e 932 } 933 return resp, nil 934 } 935 936 // ListExtensions lists Extensions in a location. 937 func (c *extensionRegistryRESTClient) ListExtensions(ctx context.Context, req *aiplatformpb.ListExtensionsRequest, opts ...gax.CallOption) *ExtensionIterator { 938 it := &ExtensionIterator{} 939 req = proto.Clone(req).(*aiplatformpb.ListExtensionsRequest) 940 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 941 it.InternalFetch = func(pageSize int, pageToken string) ([]*aiplatformpb.Extension, string, error) { 942 resp := &aiplatformpb.ListExtensionsResponse{} 943 if pageToken != "" { 944 req.PageToken = pageToken 945 } 946 if pageSize > math.MaxInt32 { 947 req.PageSize = math.MaxInt32 948 } else if pageSize != 0 { 949 req.PageSize = int32(pageSize) 950 } 951 baseUrl, err := url.Parse(c.endpoint) 952 if err != nil { 953 return nil, "", err 954 } 955 baseUrl.Path += fmt.Sprintf("/v1beta1/%v/extensions", req.GetParent()) 956 957 params := url.Values{} 958 params.Add("$alt", "json;enum-encoding=int") 959 if req.GetFilter() != "" { 960 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 961 } 962 if req.GetOrderBy() != "" { 963 params.Add("orderBy", fmt.Sprintf("%v", req.GetOrderBy())) 964 } 965 if req.GetPageSize() != 0 { 966 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 967 } 968 if req.GetPageToken() != "" { 969 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 970 } 971 972 baseUrl.RawQuery = params.Encode() 973 974 // Build HTTP headers from client and context metadata. 975 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 976 headers := gax.BuildHeaders(ctx, hds...) 977 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 978 if settings.Path != "" { 979 baseUrl.Path = settings.Path 980 } 981 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 982 if err != nil { 983 return err 984 } 985 httpReq.Header = headers 986 987 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListExtensions") 988 if err != nil { 989 return err 990 } 991 if err := unm.Unmarshal(buf, resp); err != nil { 992 return err 993 } 994 995 return nil 996 }, opts...) 997 if e != nil { 998 return nil, "", e 999 } 1000 it.Response = resp 1001 return resp.GetExtensions(), resp.GetNextPageToken(), nil 1002 } 1003 1004 fetch := func(pageSize int, pageToken string) (string, error) { 1005 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1006 if err != nil { 1007 return "", err 1008 } 1009 it.items = append(it.items, items...) 1010 return nextPageToken, nil 1011 } 1012 1013 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1014 it.pageInfo.MaxSize = int(req.GetPageSize()) 1015 it.pageInfo.Token = req.GetPageToken() 1016 1017 return it 1018 } 1019 1020 // UpdateExtension updates an Extension. 1021 func (c *extensionRegistryRESTClient) UpdateExtension(ctx context.Context, req *aiplatformpb.UpdateExtensionRequest, opts ...gax.CallOption) (*aiplatformpb.Extension, error) { 1022 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1023 body := req.GetExtension() 1024 jsonReq, err := m.Marshal(body) 1025 if err != nil { 1026 return nil, err 1027 } 1028 1029 baseUrl, err := url.Parse(c.endpoint) 1030 if err != nil { 1031 return nil, err 1032 } 1033 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetExtension().GetName()) 1034 1035 params := url.Values{} 1036 params.Add("$alt", "json;enum-encoding=int") 1037 if req.GetUpdateMask() != nil { 1038 field, err := protojson.Marshal(req.GetUpdateMask()) 1039 if err != nil { 1040 return nil, err 1041 } 1042 params.Add("updateMask", string(field[1:len(field)-1])) 1043 } 1044 1045 baseUrl.RawQuery = params.Encode() 1046 1047 // Build HTTP headers from client and context metadata. 1048 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "extension.name", url.QueryEscape(req.GetExtension().GetName()))} 1049 1050 hds = append(c.xGoogHeaders, hds...) 1051 hds = append(hds, "Content-Type", "application/json") 1052 headers := gax.BuildHeaders(ctx, hds...) 1053 opts = append((*c.CallOptions).UpdateExtension[0:len((*c.CallOptions).UpdateExtension):len((*c.CallOptions).UpdateExtension)], opts...) 1054 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1055 resp := &aiplatformpb.Extension{} 1056 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1057 if settings.Path != "" { 1058 baseUrl.Path = settings.Path 1059 } 1060 httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq)) 1061 if err != nil { 1062 return err 1063 } 1064 httpReq = httpReq.WithContext(ctx) 1065 httpReq.Header = headers 1066 1067 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateExtension") 1068 if err != nil { 1069 return err 1070 } 1071 1072 if err := unm.Unmarshal(buf, resp); err != nil { 1073 return err 1074 } 1075 1076 return nil 1077 }, opts...) 1078 if e != nil { 1079 return nil, e 1080 } 1081 return resp, nil 1082 } 1083 1084 // DeleteExtension deletes an Extension. 1085 func (c *extensionRegistryRESTClient) DeleteExtension(ctx context.Context, req *aiplatformpb.DeleteExtensionRequest, opts ...gax.CallOption) (*DeleteExtensionOperation, error) { 1086 baseUrl, err := url.Parse(c.endpoint) 1087 if err != nil { 1088 return nil, err 1089 } 1090 baseUrl.Path += fmt.Sprintf("/v1beta1/%v", req.GetName()) 1091 1092 params := url.Values{} 1093 params.Add("$alt", "json;enum-encoding=int") 1094 1095 baseUrl.RawQuery = params.Encode() 1096 1097 // Build HTTP headers from client and context metadata. 1098 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1099 1100 hds = append(c.xGoogHeaders, hds...) 1101 hds = append(hds, "Content-Type", "application/json") 1102 headers := gax.BuildHeaders(ctx, hds...) 1103 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1104 resp := &longrunningpb.Operation{} 1105 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1106 if settings.Path != "" { 1107 baseUrl.Path = settings.Path 1108 } 1109 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1110 if err != nil { 1111 return err 1112 } 1113 httpReq = httpReq.WithContext(ctx) 1114 httpReq.Header = headers 1115 1116 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteExtension") 1117 if err != nil { 1118 return err 1119 } 1120 if err := unm.Unmarshal(buf, resp); err != nil { 1121 return err 1122 } 1123 1124 return nil 1125 }, opts...) 1126 if e != nil { 1127 return nil, e 1128 } 1129 1130 override := fmt.Sprintf("/ui/%s", resp.GetName()) 1131 return &DeleteExtensionOperation{ 1132 lro: longrunning.InternalNewOperation(*c.LROClient, resp), 1133 pollPath: override, 1134 }, nil 1135 } 1136 1137 // GetLocation gets information about a location. 1138 func (c *extensionRegistryRESTClient) GetLocation(ctx context.Context, req *locationpb.GetLocationRequest, opts ...gax.CallOption) (*locationpb.Location, error) { 1139 baseUrl, err := url.Parse(c.endpoint) 1140 if err != nil { 1141 return nil, err 1142 } 1143 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1144 1145 params := url.Values{} 1146 params.Add("$alt", "json;enum-encoding=int") 1147 1148 baseUrl.RawQuery = params.Encode() 1149 1150 // Build HTTP headers from client and context metadata. 1151 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1152 1153 hds = append(c.xGoogHeaders, hds...) 1154 hds = append(hds, "Content-Type", "application/json") 1155 headers := gax.BuildHeaders(ctx, hds...) 1156 opts = append((*c.CallOptions).GetLocation[0:len((*c.CallOptions).GetLocation):len((*c.CallOptions).GetLocation)], opts...) 1157 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1158 resp := &locationpb.Location{} 1159 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1160 if settings.Path != "" { 1161 baseUrl.Path = settings.Path 1162 } 1163 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1164 if err != nil { 1165 return err 1166 } 1167 httpReq = httpReq.WithContext(ctx) 1168 httpReq.Header = headers 1169 1170 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetLocation") 1171 if err != nil { 1172 return err 1173 } 1174 1175 if err := unm.Unmarshal(buf, resp); err != nil { 1176 return err 1177 } 1178 1179 return nil 1180 }, opts...) 1181 if e != nil { 1182 return nil, e 1183 } 1184 return resp, nil 1185 } 1186 1187 // ListLocations lists information about the supported locations for this service. 1188 func (c *extensionRegistryRESTClient) ListLocations(ctx context.Context, req *locationpb.ListLocationsRequest, opts ...gax.CallOption) *LocationIterator { 1189 it := &LocationIterator{} 1190 req = proto.Clone(req).(*locationpb.ListLocationsRequest) 1191 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1192 it.InternalFetch = func(pageSize int, pageToken string) ([]*locationpb.Location, string, error) { 1193 resp := &locationpb.ListLocationsResponse{} 1194 if pageToken != "" { 1195 req.PageToken = pageToken 1196 } 1197 if pageSize > math.MaxInt32 { 1198 req.PageSize = math.MaxInt32 1199 } else if pageSize != 0 { 1200 req.PageSize = int32(pageSize) 1201 } 1202 baseUrl, err := url.Parse(c.endpoint) 1203 if err != nil { 1204 return nil, "", err 1205 } 1206 baseUrl.Path += fmt.Sprintf("/ui/%v/locations", req.GetName()) 1207 1208 params := url.Values{} 1209 params.Add("$alt", "json;enum-encoding=int") 1210 if req.GetFilter() != "" { 1211 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1212 } 1213 if req.GetPageSize() != 0 { 1214 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1215 } 1216 if req.GetPageToken() != "" { 1217 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1218 } 1219 1220 baseUrl.RawQuery = params.Encode() 1221 1222 // Build HTTP headers from client and context metadata. 1223 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1224 headers := gax.BuildHeaders(ctx, hds...) 1225 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1226 if settings.Path != "" { 1227 baseUrl.Path = settings.Path 1228 } 1229 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1230 if err != nil { 1231 return err 1232 } 1233 httpReq.Header = headers 1234 1235 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListLocations") 1236 if err != nil { 1237 return err 1238 } 1239 if err := unm.Unmarshal(buf, resp); err != nil { 1240 return err 1241 } 1242 1243 return nil 1244 }, opts...) 1245 if e != nil { 1246 return nil, "", e 1247 } 1248 it.Response = resp 1249 return resp.GetLocations(), resp.GetNextPageToken(), nil 1250 } 1251 1252 fetch := func(pageSize int, pageToken string) (string, error) { 1253 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1254 if err != nil { 1255 return "", err 1256 } 1257 it.items = append(it.items, items...) 1258 return nextPageToken, nil 1259 } 1260 1261 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1262 it.pageInfo.MaxSize = int(req.GetPageSize()) 1263 it.pageInfo.Token = req.GetPageToken() 1264 1265 return it 1266 } 1267 1268 // GetIamPolicy gets the access control policy for a resource. Returns an empty policy 1269 // if the resource exists and does not have a policy set. 1270 func (c *extensionRegistryRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1271 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1272 jsonReq, err := m.Marshal(req) 1273 if err != nil { 1274 return nil, err 1275 } 1276 1277 baseUrl, err := url.Parse(c.endpoint) 1278 if err != nil { 1279 return nil, err 1280 } 1281 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:getIamPolicy", req.GetResource()) 1282 1283 params := url.Values{} 1284 params.Add("$alt", "json;enum-encoding=int") 1285 1286 baseUrl.RawQuery = params.Encode() 1287 1288 // Build HTTP headers from client and context metadata. 1289 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1290 1291 hds = append(c.xGoogHeaders, hds...) 1292 hds = append(hds, "Content-Type", "application/json") 1293 headers := gax.BuildHeaders(ctx, hds...) 1294 opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...) 1295 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1296 resp := &iampb.Policy{} 1297 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1298 if settings.Path != "" { 1299 baseUrl.Path = settings.Path 1300 } 1301 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1302 if err != nil { 1303 return err 1304 } 1305 httpReq = httpReq.WithContext(ctx) 1306 httpReq.Header = headers 1307 1308 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "GetIamPolicy") 1309 if err != nil { 1310 return err 1311 } 1312 1313 if err := unm.Unmarshal(buf, resp); err != nil { 1314 return err 1315 } 1316 1317 return nil 1318 }, opts...) 1319 if e != nil { 1320 return nil, e 1321 } 1322 return resp, nil 1323 } 1324 1325 // SetIamPolicy sets the access control policy on the specified resource. Replaces 1326 // any existing policy. 1327 // 1328 // Can return NOT_FOUND, INVALID_ARGUMENT, and PERMISSION_DENIED 1329 // errors. 1330 func (c *extensionRegistryRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) { 1331 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1332 jsonReq, err := m.Marshal(req) 1333 if err != nil { 1334 return nil, err 1335 } 1336 1337 baseUrl, err := url.Parse(c.endpoint) 1338 if err != nil { 1339 return nil, err 1340 } 1341 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:setIamPolicy", req.GetResource()) 1342 1343 params := url.Values{} 1344 params.Add("$alt", "json;enum-encoding=int") 1345 1346 baseUrl.RawQuery = params.Encode() 1347 1348 // Build HTTP headers from client and context metadata. 1349 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1350 1351 hds = append(c.xGoogHeaders, hds...) 1352 hds = append(hds, "Content-Type", "application/json") 1353 headers := gax.BuildHeaders(ctx, hds...) 1354 opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...) 1355 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1356 resp := &iampb.Policy{} 1357 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1358 if settings.Path != "" { 1359 baseUrl.Path = settings.Path 1360 } 1361 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1362 if err != nil { 1363 return err 1364 } 1365 httpReq = httpReq.WithContext(ctx) 1366 httpReq.Header = headers 1367 1368 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy") 1369 if err != nil { 1370 return err 1371 } 1372 1373 if err := unm.Unmarshal(buf, resp); err != nil { 1374 return err 1375 } 1376 1377 return nil 1378 }, opts...) 1379 if e != nil { 1380 return nil, e 1381 } 1382 return resp, nil 1383 } 1384 1385 // TestIamPermissions returns permissions that a caller has on the specified resource. If the 1386 // resource does not exist, this will return an empty set of 1387 // permissions, not a NOT_FOUND error. 1388 // 1389 // Note: This operation is designed to be used for building 1390 // permission-aware UIs and command-line tools, not for authorization 1391 // checking. This operation may “fail open” without warning. 1392 func (c *extensionRegistryRESTClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error) { 1393 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} 1394 jsonReq, err := m.Marshal(req) 1395 if err != nil { 1396 return nil, err 1397 } 1398 1399 baseUrl, err := url.Parse(c.endpoint) 1400 if err != nil { 1401 return nil, err 1402 } 1403 baseUrl.Path += fmt.Sprintf("/v1beta1/%v:testIamPermissions", req.GetResource()) 1404 1405 params := url.Values{} 1406 params.Add("$alt", "json;enum-encoding=int") 1407 1408 baseUrl.RawQuery = params.Encode() 1409 1410 // Build HTTP headers from client and context metadata. 1411 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))} 1412 1413 hds = append(c.xGoogHeaders, hds...) 1414 hds = append(hds, "Content-Type", "application/json") 1415 headers := gax.BuildHeaders(ctx, hds...) 1416 opts = append((*c.CallOptions).TestIamPermissions[0:len((*c.CallOptions).TestIamPermissions):len((*c.CallOptions).TestIamPermissions)], opts...) 1417 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1418 resp := &iampb.TestIamPermissionsResponse{} 1419 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1420 if settings.Path != "" { 1421 baseUrl.Path = settings.Path 1422 } 1423 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) 1424 if err != nil { 1425 return err 1426 } 1427 httpReq = httpReq.WithContext(ctx) 1428 httpReq.Header = headers 1429 1430 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TestIamPermissions") 1431 if err != nil { 1432 return err 1433 } 1434 1435 if err := unm.Unmarshal(buf, resp); err != nil { 1436 return err 1437 } 1438 1439 return nil 1440 }, opts...) 1441 if e != nil { 1442 return nil, e 1443 } 1444 return resp, nil 1445 } 1446 1447 // CancelOperation is a utility method from google.longrunning.Operations. 1448 func (c *extensionRegistryRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error { 1449 baseUrl, err := url.Parse(c.endpoint) 1450 if err != nil { 1451 return err 1452 } 1453 baseUrl.Path += fmt.Sprintf("/ui/%v:cancel", req.GetName()) 1454 1455 params := url.Values{} 1456 params.Add("$alt", "json;enum-encoding=int") 1457 1458 baseUrl.RawQuery = params.Encode() 1459 1460 // Build HTTP headers from client and context metadata. 1461 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1462 1463 hds = append(c.xGoogHeaders, hds...) 1464 hds = append(hds, "Content-Type", "application/json") 1465 headers := gax.BuildHeaders(ctx, hds...) 1466 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1467 if settings.Path != "" { 1468 baseUrl.Path = settings.Path 1469 } 1470 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1471 if err != nil { 1472 return err 1473 } 1474 httpReq = httpReq.WithContext(ctx) 1475 httpReq.Header = headers 1476 1477 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "CancelOperation") 1478 return err 1479 }, opts...) 1480 } 1481 1482 // DeleteOperation is a utility method from google.longrunning.Operations. 1483 func (c *extensionRegistryRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error { 1484 baseUrl, err := url.Parse(c.endpoint) 1485 if err != nil { 1486 return err 1487 } 1488 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1489 1490 params := url.Values{} 1491 params.Add("$alt", "json;enum-encoding=int") 1492 1493 baseUrl.RawQuery = params.Encode() 1494 1495 // Build HTTP headers from client and context metadata. 1496 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1497 1498 hds = append(c.xGoogHeaders, hds...) 1499 hds = append(hds, "Content-Type", "application/json") 1500 headers := gax.BuildHeaders(ctx, hds...) 1501 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1502 if settings.Path != "" { 1503 baseUrl.Path = settings.Path 1504 } 1505 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil) 1506 if err != nil { 1507 return err 1508 } 1509 httpReq = httpReq.WithContext(ctx) 1510 httpReq.Header = headers 1511 1512 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation") 1513 return err 1514 }, opts...) 1515 } 1516 1517 // GetOperation is a utility method from google.longrunning.Operations. 1518 func (c *extensionRegistryRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1519 baseUrl, err := url.Parse(c.endpoint) 1520 if err != nil { 1521 return nil, err 1522 } 1523 baseUrl.Path += fmt.Sprintf("/ui/%v", req.GetName()) 1524 1525 params := url.Values{} 1526 params.Add("$alt", "json;enum-encoding=int") 1527 1528 baseUrl.RawQuery = params.Encode() 1529 1530 // Build HTTP headers from client and context metadata. 1531 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1532 1533 hds = append(c.xGoogHeaders, hds...) 1534 hds = append(hds, "Content-Type", "application/json") 1535 headers := gax.BuildHeaders(ctx, hds...) 1536 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...) 1537 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1538 resp := &longrunningpb.Operation{} 1539 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1540 if settings.Path != "" { 1541 baseUrl.Path = settings.Path 1542 } 1543 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1544 if err != nil { 1545 return err 1546 } 1547 httpReq = httpReq.WithContext(ctx) 1548 httpReq.Header = headers 1549 1550 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation") 1551 if err != nil { 1552 return err 1553 } 1554 1555 if err := unm.Unmarshal(buf, resp); err != nil { 1556 return err 1557 } 1558 1559 return nil 1560 }, opts...) 1561 if e != nil { 1562 return nil, e 1563 } 1564 return resp, nil 1565 } 1566 1567 // ListOperations is a utility method from google.longrunning.Operations. 1568 func (c *extensionRegistryRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator { 1569 it := &OperationIterator{} 1570 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest) 1571 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1572 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) { 1573 resp := &longrunningpb.ListOperationsResponse{} 1574 if pageToken != "" { 1575 req.PageToken = pageToken 1576 } 1577 if pageSize > math.MaxInt32 { 1578 req.PageSize = math.MaxInt32 1579 } else if pageSize != 0 { 1580 req.PageSize = int32(pageSize) 1581 } 1582 baseUrl, err := url.Parse(c.endpoint) 1583 if err != nil { 1584 return nil, "", err 1585 } 1586 baseUrl.Path += fmt.Sprintf("/ui/%v/operations", req.GetName()) 1587 1588 params := url.Values{} 1589 params.Add("$alt", "json;enum-encoding=int") 1590 if req.GetFilter() != "" { 1591 params.Add("filter", fmt.Sprintf("%v", req.GetFilter())) 1592 } 1593 if req.GetPageSize() != 0 { 1594 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize())) 1595 } 1596 if req.GetPageToken() != "" { 1597 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken())) 1598 } 1599 1600 baseUrl.RawQuery = params.Encode() 1601 1602 // Build HTTP headers from client and context metadata. 1603 hds := append(c.xGoogHeaders, "Content-Type", "application/json") 1604 headers := gax.BuildHeaders(ctx, hds...) 1605 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1606 if settings.Path != "" { 1607 baseUrl.Path = settings.Path 1608 } 1609 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil) 1610 if err != nil { 1611 return err 1612 } 1613 httpReq.Header = headers 1614 1615 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations") 1616 if err != nil { 1617 return err 1618 } 1619 if err := unm.Unmarshal(buf, resp); err != nil { 1620 return err 1621 } 1622 1623 return nil 1624 }, opts...) 1625 if e != nil { 1626 return nil, "", e 1627 } 1628 it.Response = resp 1629 return resp.GetOperations(), resp.GetNextPageToken(), nil 1630 } 1631 1632 fetch := func(pageSize int, pageToken string) (string, error) { 1633 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 1634 if err != nil { 1635 return "", err 1636 } 1637 it.items = append(it.items, items...) 1638 return nextPageToken, nil 1639 } 1640 1641 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 1642 it.pageInfo.MaxSize = int(req.GetPageSize()) 1643 it.pageInfo.Token = req.GetPageToken() 1644 1645 return it 1646 } 1647 1648 // WaitOperation is a utility method from google.longrunning.Operations. 1649 func (c *extensionRegistryRESTClient) WaitOperation(ctx context.Context, req *longrunningpb.WaitOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) { 1650 baseUrl, err := url.Parse(c.endpoint) 1651 if err != nil { 1652 return nil, err 1653 } 1654 baseUrl.Path += fmt.Sprintf("/ui/%v:wait", req.GetName()) 1655 1656 params := url.Values{} 1657 params.Add("$alt", "json;enum-encoding=int") 1658 if req.GetTimeout() != nil { 1659 field, err := protojson.Marshal(req.GetTimeout()) 1660 if err != nil { 1661 return nil, err 1662 } 1663 params.Add("timeout", string(field[1:len(field)-1])) 1664 } 1665 1666 baseUrl.RawQuery = params.Encode() 1667 1668 // Build HTTP headers from client and context metadata. 1669 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))} 1670 1671 hds = append(c.xGoogHeaders, hds...) 1672 hds = append(hds, "Content-Type", "application/json") 1673 headers := gax.BuildHeaders(ctx, hds...) 1674 opts = append((*c.CallOptions).WaitOperation[0:len((*c.CallOptions).WaitOperation):len((*c.CallOptions).WaitOperation)], opts...) 1675 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} 1676 resp := &longrunningpb.Operation{} 1677 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 1678 if settings.Path != "" { 1679 baseUrl.Path = settings.Path 1680 } 1681 httpReq, err := http.NewRequest("POST", baseUrl.String(), nil) 1682 if err != nil { 1683 return err 1684 } 1685 httpReq = httpReq.WithContext(ctx) 1686 httpReq.Header = headers 1687 1688 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "WaitOperation") 1689 if err != nil { 1690 return err 1691 } 1692 1693 if err := unm.Unmarshal(buf, resp); err != nil { 1694 return err 1695 } 1696 1697 return nil 1698 }, opts...) 1699 if e != nil { 1700 return nil, e 1701 } 1702 return resp, nil 1703 } 1704 1705 // DeleteExtensionOperation returns a new DeleteExtensionOperation from a given name. 1706 // The name must be that of a previously created DeleteExtensionOperation, possibly from a different process. 1707 func (c *extensionRegistryGRPCClient) DeleteExtensionOperation(name string) *DeleteExtensionOperation { 1708 return &DeleteExtensionOperation{ 1709 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1710 } 1711 } 1712 1713 // DeleteExtensionOperation returns a new DeleteExtensionOperation from a given name. 1714 // The name must be that of a previously created DeleteExtensionOperation, possibly from a different process. 1715 func (c *extensionRegistryRESTClient) DeleteExtensionOperation(name string) *DeleteExtensionOperation { 1716 override := fmt.Sprintf("/ui/%s", name) 1717 return &DeleteExtensionOperation{ 1718 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1719 pollPath: override, 1720 } 1721 } 1722 1723 // ImportExtensionOperation returns a new ImportExtensionOperation from a given name. 1724 // The name must be that of a previously created ImportExtensionOperation, possibly from a different process. 1725 func (c *extensionRegistryGRPCClient) ImportExtensionOperation(name string) *ImportExtensionOperation { 1726 return &ImportExtensionOperation{ 1727 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1728 } 1729 } 1730 1731 // ImportExtensionOperation returns a new ImportExtensionOperation from a given name. 1732 // The name must be that of a previously created ImportExtensionOperation, possibly from a different process. 1733 func (c *extensionRegistryRESTClient) ImportExtensionOperation(name string) *ImportExtensionOperation { 1734 override := fmt.Sprintf("/ui/%s", name) 1735 return &ImportExtensionOperation{ 1736 lro: longrunning.InternalNewOperation(*c.LROClient, &longrunningpb.Operation{Name: name}), 1737 pollPath: override, 1738 } 1739 }