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