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