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