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