blob: 7173a048916bfce78e680ad2a7fbe0f28314cef0 [file] [edit]
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Code generated by protoc-gen-go_gapic. DO NOT EDIT.
package discoveryengine
import (
"bytes"
"context"
"fmt"
"log/slog"
"math"
"net/http"
"net/url"
"time"
discoveryenginepb "cloud.google.com/go/discoveryengine/apiv1beta/discoveryenginepb"
iampb "cloud.google.com/go/iam/apiv1/iampb"
"cloud.google.com/go/longrunning"
lroauto "cloud.google.com/go/longrunning/autogen"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
gax "github.com/googleapis/gax-go/v2"
"github.com/googleapis/gax-go/v2/callctx"
trace "go.opentelemetry.io/otel/trace"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
"google.golang.org/api/option/internaloption"
gtransport "google.golang.org/api/transport/grpc"
httptransport "google.golang.org/api/transport/http"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
)
var newEngineClientHook clientHook
// EngineCallOptions contains the retry settings for each method of EngineClient.
type EngineCallOptions struct {
CreateEngine []gax.CallOption
DeleteEngine []gax.CallOption
UpdateEngine []gax.CallOption
GetEngine []gax.CallOption
ListEngines []gax.CallOption
PauseEngine []gax.CallOption
ResumeEngine []gax.CallOption
TuneEngine []gax.CallOption
GetIamPolicy []gax.CallOption
SetIamPolicy []gax.CallOption
CancelOperation []gax.CallOption
GetOperation []gax.CallOption
ListOperations []gax.CallOption
}
func defaultEngineGRPCClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("discoveryengine.googleapis.com:443"),
internaloption.WithDefaultEndpointTemplate("discoveryengine.UNIVERSE_DOMAIN:443"),
internaloption.WithDefaultMTLSEndpoint("discoveryengine.mtls.googleapis.com:443"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://discoveryengine.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableJwtWithScope(),
internaloption.EnableNewAuthLibrary(),
option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
grpc.MaxCallRecvMsgSize(math.MaxInt32))),
}
}
func defaultEngineCallOptions() *EngineCallOptions {
return &EngineCallOptions{
CreateEngine: []gax.CallOption{},
DeleteEngine: []gax.CallOption{},
UpdateEngine: []gax.CallOption{},
GetEngine: []gax.CallOption{},
ListEngines: []gax.CallOption{},
PauseEngine: []gax.CallOption{},
ResumeEngine: []gax.CallOption{},
TuneEngine: []gax.CallOption{},
GetIamPolicy: []gax.CallOption{},
SetIamPolicy: []gax.CallOption{},
CancelOperation: []gax.CallOption{
gax.WithTimeout(30000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 10000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
GetOperation: []gax.CallOption{
gax.WithTimeout(30000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 10000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
ListOperations: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnCodes([]codes.Code{
codes.Unavailable,
}, gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 30000 * time.Millisecond,
Multiplier: 1.30,
})
}),
},
}
}
func defaultEngineRESTCallOptions() *EngineCallOptions {
return &EngineCallOptions{
CreateEngine: []gax.CallOption{},
DeleteEngine: []gax.CallOption{},
UpdateEngine: []gax.CallOption{},
GetEngine: []gax.CallOption{},
ListEngines: []gax.CallOption{},
PauseEngine: []gax.CallOption{},
ResumeEngine: []gax.CallOption{},
TuneEngine: []gax.CallOption{},
GetIamPolicy: []gax.CallOption{},
SetIamPolicy: []gax.CallOption{},
CancelOperation: []gax.CallOption{
gax.WithTimeout(30000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 10000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusServiceUnavailable)
}),
},
GetOperation: []gax.CallOption{
gax.WithTimeout(30000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 10000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusServiceUnavailable)
}),
},
ListOperations: []gax.CallOption{
gax.WithTimeout(300000 * time.Millisecond),
gax.WithRetry(func() gax.Retryer {
return gax.OnHTTPCodes(gax.Backoff{
Initial: 1000 * time.Millisecond,
Max: 30000 * time.Millisecond,
Multiplier: 1.30,
},
http.StatusServiceUnavailable)
}),
},
}
}
// internalEngineClient is an interface that defines the methods available from Discovery Engine API.
type internalEngineClient interface {
Close() error
setGoogleClientInfo(...string)
Connection() *grpc.ClientConn
CreateEngine(context.Context, *discoveryenginepb.CreateEngineRequest, ...gax.CallOption) (*CreateEngineOperation, error)
CreateEngineOperation(name string) *CreateEngineOperation
DeleteEngine(context.Context, *discoveryenginepb.DeleteEngineRequest, ...gax.CallOption) (*DeleteEngineOperation, error)
DeleteEngineOperation(name string) *DeleteEngineOperation
UpdateEngine(context.Context, *discoveryenginepb.UpdateEngineRequest, ...gax.CallOption) (*discoveryenginepb.Engine, error)
GetEngine(context.Context, *discoveryenginepb.GetEngineRequest, ...gax.CallOption) (*discoveryenginepb.Engine, error)
ListEngines(context.Context, *discoveryenginepb.ListEnginesRequest, ...gax.CallOption) *EngineIterator
PauseEngine(context.Context, *discoveryenginepb.PauseEngineRequest, ...gax.CallOption) (*discoveryenginepb.Engine, error)
ResumeEngine(context.Context, *discoveryenginepb.ResumeEngineRequest, ...gax.CallOption) (*discoveryenginepb.Engine, error)
TuneEngine(context.Context, *discoveryenginepb.TuneEngineRequest, ...gax.CallOption) (*TuneEngineOperation, error)
TuneEngineOperation(name string) *TuneEngineOperation
GetIamPolicy(context.Context, *iampb.GetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
SetIamPolicy(context.Context, *iampb.SetIamPolicyRequest, ...gax.CallOption) (*iampb.Policy, error)
CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
}
// EngineClient is a client for interacting with Discovery Engine API.
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
//
// Service for managing Engine
// configuration.
type EngineClient struct {
// The internal transport-dependent client.
internalClient internalEngineClient
// The call options for this service.
CallOptions *EngineCallOptions
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient *lroauto.OperationsClient
}
// Wrapper methods routed to the internal client.
// Close closes the connection to the API service. **Always** call Close() when
// the client is no longer required.
func (c *EngineClient) Close() error {
return c.internalClient.Close()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *EngineClient) setGoogleClientInfo(keyval ...string) {
c.internalClient.setGoogleClientInfo(keyval...)
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *EngineClient) Connection() *grpc.ClientConn {
return c.internalClient.Connection()
}
// CreateEngine creates an Engine.
func (c *EngineClient) CreateEngine(ctx context.Context, req *discoveryenginepb.CreateEngineRequest, opts ...gax.CallOption) (*CreateEngineOperation, error) {
return c.internalClient.CreateEngine(ctx, req, opts...)
}
// CreateEngineOperation returns a new CreateEngineOperation from a given name.
// The name must be that of a previously created CreateEngineOperation, possibly from a different process.
func (c *EngineClient) CreateEngineOperation(name string) *CreateEngineOperation {
return c.internalClient.CreateEngineOperation(name)
}
// DeleteEngine deletes an Engine.
func (c *EngineClient) DeleteEngine(ctx context.Context, req *discoveryenginepb.DeleteEngineRequest, opts ...gax.CallOption) (*DeleteEngineOperation, error) {
return c.internalClient.DeleteEngine(ctx, req, opts...)
}
// DeleteEngineOperation returns a new DeleteEngineOperation from a given name.
// The name must be that of a previously created DeleteEngineOperation, possibly from a different process.
func (c *EngineClient) DeleteEngineOperation(name string) *DeleteEngineOperation {
return c.internalClient.DeleteEngineOperation(name)
}
// UpdateEngine updates an Engine
func (c *EngineClient) UpdateEngine(ctx context.Context, req *discoveryenginepb.UpdateEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
return c.internalClient.UpdateEngine(ctx, req, opts...)
}
// GetEngine gets an Engine.
func (c *EngineClient) GetEngine(ctx context.Context, req *discoveryenginepb.GetEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
return c.internalClient.GetEngine(ctx, req, opts...)
}
// ListEngines lists all the Engines
// associated with the project.
func (c *EngineClient) ListEngines(ctx context.Context, req *discoveryenginepb.ListEnginesRequest, opts ...gax.CallOption) *EngineIterator {
return c.internalClient.ListEngines(ctx, req, opts...)
}
// PauseEngine pauses the training of an existing
// Engine. Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *EngineClient) PauseEngine(ctx context.Context, req *discoveryenginepb.PauseEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
return c.internalClient.PauseEngine(ctx, req, opts...)
}
// ResumeEngine resumes the training of an existing
// Engine. Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *EngineClient) ResumeEngine(ctx context.Context, req *discoveryenginepb.ResumeEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
return c.internalClient.ResumeEngine(ctx, req, opts...)
}
// TuneEngine tunes an existing Engine.
// Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *EngineClient) TuneEngine(ctx context.Context, req *discoveryenginepb.TuneEngineRequest, opts ...gax.CallOption) (*TuneEngineOperation, error) {
return c.internalClient.TuneEngine(ctx, req, opts...)
}
// TuneEngineOperation returns a new TuneEngineOperation from a given name.
// The name must be that of a previously created TuneEngineOperation, possibly from a different process.
func (c *EngineClient) TuneEngineOperation(name string) *TuneEngineOperation {
return c.internalClient.TuneEngineOperation(name)
}
// GetIamPolicy gets the IAM access control policy for an
// Engine. A NOT_FOUND error
// is returned if the resource does not exist. An empty policy is returned if
// the resource exists but does not have a policy set on it.
func (c *EngineClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
return c.internalClient.GetIamPolicy(ctx, req, opts...)
}
// SetIamPolicy sets the IAM access control policy for an
// Engine. A NOT_FOUND error
// is returned if the resource does not exist.
//
// Important: When setting a policy directly on an Engine resource,
// the only recommended roles in the bindings are:
// roles/discoveryengine.admin,
// roles/discoveryengine.agentspaceAdmin,
// roles/discoveryengine.user,
// roles/discoveryengine.agentspaceUser,
// roles/discoveryengine.viewer,
// roles/discoveryengine.agentspaceViewer.
// Attempting to grant any other role will result in a warning in logging.
func (c *EngineClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
return c.internalClient.SetIamPolicy(ctx, req, opts...)
}
// CancelOperation is a utility method from google.longrunning.Operations.
func (c *EngineClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
return c.internalClient.CancelOperation(ctx, req, opts...)
}
// GetOperation is a utility method from google.longrunning.Operations.
func (c *EngineClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
return c.internalClient.GetOperation(ctx, req, opts...)
}
// ListOperations is a utility method from google.longrunning.Operations.
func (c *EngineClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
return c.internalClient.ListOperations(ctx, req, opts...)
}
// engineGRPCClient is a client for interacting with Discovery Engine API over gRPC transport.
//
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type engineGRPCClient struct {
// Connection pool of gRPC connections to the service.
connPool gtransport.ConnPool
// Points back to the CallOptions field of the containing EngineClient
CallOptions **EngineCallOptions
// The gRPC API client.
engineClient discoveryenginepb.EngineServiceClient
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient **lroauto.OperationsClient
operationsClient longrunningpb.OperationsClient
// The x-goog-* metadata to be sent with each request.
xGoogHeaders []string
logger *slog.Logger
}
// NewEngineClient creates a new engine service client based on gRPC.
// The returned client must be Closed when it is done being used to clean up its underlying connections.
//
// Service for managing Engine
// configuration.
func NewEngineClient(ctx context.Context, opts ...option.ClientOption) (*EngineClient, error) {
clientOpts := defaultEngineGRPCClientOptions()
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
clientOpts = append(clientOpts, internaloption.WithTelemetryAttributes(map[string]string{
"gcp.client.service": "discoveryengine",
"gcp.client.version": getVersionClient(),
"gcp.client.repo": "googleapis/google-cloud-go",
"gcp.client.artifact": "cloud.google.com/go/discoveryengine/apiv1beta",
"gcp.client.language": "go",
"url.domain": "discoveryengine.googleapis.com",
}))
}
if newEngineClientHook != nil {
hookOpts, err := newEngineClientHook(ctx, clientHookParams{})
if err != nil {
return nil, err
}
clientOpts = append(clientOpts, hookOpts...)
}
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
if err != nil {
return nil, err
}
client := EngineClient{CallOptions: defaultEngineCallOptions()}
c := &engineGRPCClient{
connPool: connPool,
engineClient: discoveryenginepb.NewEngineServiceClient(connPool),
CallOptions: &client.CallOptions,
logger: internaloption.GetLogger(opts),
operationsClient: longrunningpb.NewOperationsClient(connPool),
}
c.setGoogleClientInfo()
if gax.IsFeatureEnabled("METRICS") {
metrics := gax.NewClientMetrics(
gax.WithTelemetryLogger(c.logger),
gax.WithTelemetryAttributes(map[string]string{
gax.ClientService: "discoveryengine",
gax.ClientVersion: getVersionClient(),
gax.ClientArtifact: "cloud.google.com/go/discoveryengine/apiv1beta",
gax.RPCSystem: "grpc",
gax.URLDomain: "discoveryengine.googleapis.com",
}),
)
client.CallOptions.CreateEngine = append(client.CallOptions.CreateEngine, gax.WithClientMetrics(metrics))
client.CallOptions.DeleteEngine = append(client.CallOptions.DeleteEngine, gax.WithClientMetrics(metrics))
client.CallOptions.UpdateEngine = append(client.CallOptions.UpdateEngine, gax.WithClientMetrics(metrics))
client.CallOptions.GetEngine = append(client.CallOptions.GetEngine, gax.WithClientMetrics(metrics))
client.CallOptions.ListEngines = append(client.CallOptions.ListEngines, gax.WithClientMetrics(metrics))
client.CallOptions.PauseEngine = append(client.CallOptions.PauseEngine, gax.WithClientMetrics(metrics))
client.CallOptions.ResumeEngine = append(client.CallOptions.ResumeEngine, gax.WithClientMetrics(metrics))
client.CallOptions.TuneEngine = append(client.CallOptions.TuneEngine, gax.WithClientMetrics(metrics))
client.CallOptions.GetIamPolicy = append(client.CallOptions.GetIamPolicy, gax.WithClientMetrics(metrics))
client.CallOptions.SetIamPolicy = append(client.CallOptions.SetIamPolicy, gax.WithClientMetrics(metrics))
client.CallOptions.CancelOperation = append(client.CallOptions.CancelOperation, gax.WithClientMetrics(metrics))
client.CallOptions.GetOperation = append(client.CallOptions.GetOperation, gax.WithClientMetrics(metrics))
client.CallOptions.ListOperations = append(client.CallOptions.ListOperations, gax.WithClientMetrics(metrics))
}
client.internalClient = c
client.LROClient, err = lroauto.NewOperationsClient(ctx, gtransport.WithConnPool(connPool))
if err != nil {
// This error "should not happen", since we are just reusing old connection pool
// and never actually need to dial.
// If this does happen, we could leak connp. However, we cannot close conn:
// If the user invoked the constructor with option.WithGRPCConn,
// we would close a connection that's still in use.
// TODO: investigate error conditions.
return nil, err
}
c.LROClient = &client.LROClient
return &client, nil
}
// Connection returns a connection to the API service.
//
// Deprecated: Connections are now pooled so this method does not always
// return the same resource.
func (c *engineGRPCClient) Connection() *grpc.ClientConn {
return c.connPool.Conn()
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *engineGRPCClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
c.xGoogHeaders = []string{
"x-goog-api-client", gax.XGoogHeader(kv...),
}
}
// Close closes the connection to the API service. **Always** call Close() when
// the client is no longer required.
func (c *engineGRPCClient) Close() error {
return c.connPool.Close()
}
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
type engineRESTClient struct {
// The http endpoint to connect to.
endpoint string
// The http client.
httpClient *http.Client
// LROClient is used internally to handle long-running operations.
// It is exposed so that its CallOptions can be modified if required.
// Users should not Close this client.
LROClient **lroauto.OperationsClient
// The x-goog-* headers to be sent with each request.
xGoogHeaders []string
// Points back to the CallOptions field of the containing EngineClient
CallOptions **EngineCallOptions
logger *slog.Logger
}
// NewEngineRESTClient creates a new engine service rest client.
//
// Service for managing Engine
// configuration.
func NewEngineRESTClient(ctx context.Context, opts ...option.ClientOption) (*EngineClient, error) {
clientOpts := append(defaultEngineRESTClientOptions(), opts...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
clientOpts = append(clientOpts, internaloption.WithTelemetryAttributes(map[string]string{
"gcp.client.service": "discoveryengine",
"gcp.client.version": getVersionClient(),
"gcp.client.repo": "googleapis/google-cloud-go",
"gcp.client.artifact": "cloud.google.com/go/discoveryengine/apiv1beta",
"gcp.client.language": "go",
"url.domain": "discoveryengine.googleapis.com",
}))
}
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
if err != nil {
return nil, err
}
callOpts := defaultEngineRESTCallOptions()
c := &engineRESTClient{
endpoint: endpoint,
httpClient: httpClient,
CallOptions: &callOpts,
logger: internaloption.GetLogger(opts),
}
c.setGoogleClientInfo()
if gax.IsFeatureEnabled("METRICS") {
metrics := gax.NewClientMetrics(
gax.WithTelemetryLogger(c.logger),
gax.WithTelemetryAttributes(map[string]string{
gax.ClientService: "discoveryengine",
gax.ClientVersion: getVersionClient(),
gax.ClientArtifact: "cloud.google.com/go/discoveryengine/apiv1beta",
gax.RPCSystem: "http",
gax.URLDomain: "discoveryengine.googleapis.com",
}),
)
callOpts.CreateEngine = append(callOpts.CreateEngine, gax.WithClientMetrics(metrics))
callOpts.DeleteEngine = append(callOpts.DeleteEngine, gax.WithClientMetrics(metrics))
callOpts.UpdateEngine = append(callOpts.UpdateEngine, gax.WithClientMetrics(metrics))
callOpts.GetEngine = append(callOpts.GetEngine, gax.WithClientMetrics(metrics))
callOpts.ListEngines = append(callOpts.ListEngines, gax.WithClientMetrics(metrics))
callOpts.PauseEngine = append(callOpts.PauseEngine, gax.WithClientMetrics(metrics))
callOpts.ResumeEngine = append(callOpts.ResumeEngine, gax.WithClientMetrics(metrics))
callOpts.TuneEngine = append(callOpts.TuneEngine, gax.WithClientMetrics(metrics))
callOpts.GetIamPolicy = append(callOpts.GetIamPolicy, gax.WithClientMetrics(metrics))
callOpts.SetIamPolicy = append(callOpts.SetIamPolicy, gax.WithClientMetrics(metrics))
callOpts.CancelOperation = append(callOpts.CancelOperation, gax.WithClientMetrics(metrics))
callOpts.GetOperation = append(callOpts.GetOperation, gax.WithClientMetrics(metrics))
callOpts.ListOperations = append(callOpts.ListOperations, gax.WithClientMetrics(metrics))
}
lroOpts := []option.ClientOption{
option.WithHTTPClient(httpClient),
option.WithEndpoint(endpoint),
}
opClient, err := lroauto.NewOperationsRESTClient(ctx, lroOpts...)
if err != nil {
return nil, err
}
c.LROClient = &opClient
return &EngineClient{internalClient: c, CallOptions: callOpts}, nil
}
func defaultEngineRESTClientOptions() []option.ClientOption {
return []option.ClientOption{
internaloption.WithDefaultEndpoint("https://discoveryengine.googleapis.com"),
internaloption.WithDefaultEndpointTemplate("https://discoveryengine.UNIVERSE_DOMAIN"),
internaloption.WithDefaultMTLSEndpoint("https://discoveryengine.mtls.googleapis.com"),
internaloption.WithDefaultUniverseDomain("googleapis.com"),
internaloption.WithDefaultAudience("https://discoveryengine.googleapis.com/"),
internaloption.WithDefaultScopes(DefaultAuthScopes()...),
internaloption.EnableNewAuthLibrary(),
}
}
// setGoogleClientInfo sets the name and version of the application in
// the `x-goog-api-client` header passed on each request. Intended for
// use by Google-written clients.
func (c *engineRESTClient) setGoogleClientInfo(keyval ...string) {
kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
c.xGoogHeaders = []string{
"x-goog-api-client", gax.XGoogHeader(kv...),
}
}
// Close closes the connection to the API service. **Always** call Close() when
// the client is no longer required.
func (c *engineRESTClient) Close() error {
// Replace httpClient with nil to force cleanup.
c.httpClient = nil
return nil
}
// Connection returns a connection to the API service.
//
// Deprecated: This method always returns nil.
func (c *engineRESTClient) Connection() *grpc.ClientConn {
return nil
}
func (c *engineGRPCClient) CreateEngine(ctx context.Context, req *discoveryenginepb.CreateEngineRequest, opts ...gax.CallOption) (*CreateEngineOperation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetParent()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/CreateEngine")
}
opts = append((*c.CallOptions).CreateEngine[0:len((*c.CallOptions).CreateEngine):len((*c.CallOptions).CreateEngine)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.CreateEngine, req, settings.GRPC, c.logger, "CreateEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.CreateEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &CreateEngineOperation{
lro: lro,
}, nil
}
func (c *engineGRPCClient) DeleteEngine(ctx context.Context, req *discoveryenginepb.DeleteEngineRequest, opts ...gax.CallOption) (*DeleteEngineOperation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/DeleteEngine")
}
opts = append((*c.CallOptions).DeleteEngine[0:len((*c.CallOptions).DeleteEngine):len((*c.CallOptions).DeleteEngine)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.DeleteEngine, req, settings.GRPC, c.logger, "DeleteEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.DeleteEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &DeleteEngineOperation{
lro: lro,
}, nil
}
func (c *engineGRPCClient) UpdateEngine(ctx context.Context, req *discoveryenginepb.UpdateEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "engine.name", url.QueryEscape(req.GetEngine().GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/UpdateEngine")
}
opts = append((*c.CallOptions).UpdateEngine[0:len((*c.CallOptions).UpdateEngine):len((*c.CallOptions).UpdateEngine)], opts...)
var resp *discoveryenginepb.Engine
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.UpdateEngine, req, settings.GRPC, c.logger, "UpdateEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) GetEngine(ctx context.Context, req *discoveryenginepb.GetEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/GetEngine")
}
opts = append((*c.CallOptions).GetEngine[0:len((*c.CallOptions).GetEngine):len((*c.CallOptions).GetEngine)], opts...)
var resp *discoveryenginepb.Engine
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.GetEngine, req, settings.GRPC, c.logger, "GetEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) ListEngines(ctx context.Context, req *discoveryenginepb.ListEnginesRequest, opts ...gax.CallOption) *EngineIterator {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetParent()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/ListEngines")
}
opts = append((*c.CallOptions).ListEngines[0:len((*c.CallOptions).ListEngines):len((*c.CallOptions).ListEngines)], opts...)
it := &EngineIterator{}
req = proto.CloneOf(req)
it.InternalFetch = func(pageSize int, pageToken string) ([]*discoveryenginepb.Engine, string, error) {
resp := &discoveryenginepb.ListEnginesResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.ListEngines, req, settings.GRPC, c.logger, "ListEngines")
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetEngines(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
func (c *engineGRPCClient) PauseEngine(ctx context.Context, req *discoveryenginepb.PauseEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/PauseEngine")
}
opts = append((*c.CallOptions).PauseEngine[0:len((*c.CallOptions).PauseEngine):len((*c.CallOptions).PauseEngine)], opts...)
var resp *discoveryenginepb.Engine
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.PauseEngine, req, settings.GRPC, c.logger, "PauseEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) ResumeEngine(ctx context.Context, req *discoveryenginepb.ResumeEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/ResumeEngine")
}
opts = append((*c.CallOptions).ResumeEngine[0:len((*c.CallOptions).ResumeEngine):len((*c.CallOptions).ResumeEngine)], opts...)
var resp *discoveryenginepb.Engine
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.ResumeEngine, req, settings.GRPC, c.logger, "ResumeEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) TuneEngine(ctx context.Context, req *discoveryenginepb.TuneEngineRequest, opts ...gax.CallOption) (*TuneEngineOperation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/TuneEngine")
}
opts = append((*c.CallOptions).TuneEngine[0:len((*c.CallOptions).TuneEngine):len((*c.CallOptions).TuneEngine)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.TuneEngine, req, settings.GRPC, c.logger, "TuneEngine")
return err
}, opts...)
if err != nil {
return nil, err
}
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.TuneEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &TuneEngineOperation{
lro: lro,
}, nil
}
func (c *engineGRPCClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetResource()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/GetIamPolicy")
}
opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
var resp *iampb.Policy
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.GetIamPolicy, req, settings.GRPC, c.logger, "GetIamPolicy")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetResource()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/SetIamPolicy")
}
opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
var resp *iampb.Policy
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.engineClient.SetIamPolicy, req, settings.GRPC, c.logger, "SetIamPolicy")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.longrunning.Operations/CancelOperation")
}
opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
_, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
return err
}, opts...)
return err
}
func (c *engineGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.longrunning.Operations/GetOperation")
}
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
var resp *longrunningpb.Operation
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
return err
}, opts...)
if err != nil {
return nil, err
}
return resp, nil
}
func (c *engineGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.longrunning.Operations/ListOperations")
}
opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
it := &OperationIterator{}
req = proto.CloneOf(req)
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
resp := &longrunningpb.ListOperationsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
var err error
resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
return err
}, opts...)
if err != nil {
return nil, "", err
}
it.Response = resp
return resp.GetOperations(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
// CreateEngine creates an Engine.
func (c *engineRESTClient) CreateEngine(ctx context.Context, req *discoveryenginepb.CreateEngineRequest, opts ...gax.CallOption) (*CreateEngineOperation, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
body := req.GetEngine()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v/engines", req.GetParent())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
params.Add("engineId", fmt.Sprintf("%v", req.GetEngineId()))
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetParent()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/CreateEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{parent=projects/*/locations/*/collections/*}/engines")
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CreateEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
override := fmt.Sprintf("/v1beta/%s", resp.GetName())
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.CreateEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &CreateEngineOperation{
lro: lro,
pollPath: override,
}, nil
}
// DeleteEngine deletes an Engine.
func (c *engineRESTClient) DeleteEngine(ctx context.Context, req *discoveryenginepb.DeleteEngineRequest, opts ...gax.CallOption) (*DeleteEngineOperation, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/DeleteEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/engines/*}")
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
override := fmt.Sprintf("/v1beta/%s", resp.GetName())
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.DeleteEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &DeleteEngineOperation{
lro: lro,
pollPath: override,
}, nil
}
// UpdateEngine updates an Engine
func (c *engineRESTClient) UpdateEngine(ctx context.Context, req *discoveryenginepb.UpdateEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
body := req.GetEngine()
jsonReq, err := m.Marshal(body)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v", req.GetEngine().GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetUpdateMask() != nil {
field, err := protojson.Marshal(req.GetUpdateMask())
if err != nil {
return nil, err
}
params.Add("updateMask", string(field[1:len(field)-1]))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "engine.name", url.QueryEscape(req.GetEngine().GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/UpdateEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{engine.name=projects/*/locations/*/collections/*/engines/*}")
}
opts = append((*c.CallOptions).UpdateEngine[0:len((*c.CallOptions).UpdateEngine):len((*c.CallOptions).UpdateEngine)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &discoveryenginepb.Engine{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("PATCH", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "UpdateEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// GetEngine gets an Engine.
func (c *engineRESTClient) GetEngine(ctx context.Context, req *discoveryenginepb.GetEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/GetEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/engines/*}")
}
opts = append((*c.CallOptions).GetEngine[0:len((*c.CallOptions).GetEngine):len((*c.CallOptions).GetEngine)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &discoveryenginepb.Engine{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// ListEngines lists all the Engines
// associated with the project.
func (c *engineRESTClient) ListEngines(ctx context.Context, req *discoveryenginepb.ListEnginesRequest, opts ...gax.CallOption) *EngineIterator {
it := &EngineIterator{}
req = proto.CloneOf(req)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
it.InternalFetch = func(pageSize int, pageToken string) ([]*discoveryenginepb.Engine, string, error) {
resp := &discoveryenginepb.ListEnginesResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, "", err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v/engines", req.GetParent())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetFilter() != "" {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req.GetPageSize() != 0 {
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
}
if req.GetPageToken() != "" {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListEngines")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, "", e
}
it.Response = resp
return resp.GetEngines(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
// PauseEngine pauses the training of an existing
// Engine. Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *engineRESTClient) PauseEngine(ctx context.Context, req *discoveryenginepb.PauseEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:pause", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/PauseEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/engines/*}:pause")
}
opts = append((*c.CallOptions).PauseEngine[0:len((*c.CallOptions).PauseEngine):len((*c.CallOptions).PauseEngine)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &discoveryenginepb.Engine{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "PauseEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// ResumeEngine resumes the training of an existing
// Engine. Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *engineRESTClient) ResumeEngine(ctx context.Context, req *discoveryenginepb.ResumeEngineRequest, opts ...gax.CallOption) (*discoveryenginepb.Engine, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:resume", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/ResumeEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/engines/*}:resume")
}
opts = append((*c.CallOptions).ResumeEngine[0:len((*c.CallOptions).ResumeEngine):len((*c.CallOptions).ResumeEngine)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &discoveryenginepb.Engine{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ResumeEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// TuneEngine tunes an existing Engine.
// Only applicable if
// SolutionType is
// SOLUTION_TYPE_RECOMMENDATION.
func (c *engineRESTClient) TuneEngine(ctx context.Context, req *discoveryenginepb.TuneEngineRequest, opts ...gax.CallOption) (*TuneEngineOperation, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:tune", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetName()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/TuneEngine")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/engines/*}:tune")
}
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "TuneEngine")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
override := fmt.Sprintf("/v1beta/%s", resp.GetName())
lro := longrunning.InternalNewOperationWithMetadata(*c.LROClient, resp, "*discoveryengine.TuneEngineOperation")
if gax.IsFeatureEnabled("TRACING") {
lro.SetParentSpanContext(trace.SpanContextFromContext(ctx))
}
return &TuneEngineOperation{
lro: lro,
pollPath: override,
}, nil
}
// GetIamPolicy gets the IAM access control policy for an
// Engine. A NOT_FOUND error
// is returned if the resource does not exist. An empty policy is returned if
// the resource exists but does not have a policy set on it.
func (c *engineRESTClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:getIamPolicy", req.GetResource())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetOptions().GetRequestedPolicyVersion() != 0 {
params.Add("options.requestedPolicyVersion", fmt.Sprintf("%v", req.GetOptions().GetRequestedPolicyVersion()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetResource()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/GetIamPolicy")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{resource=projects/*/locations/*/collections/*/engines/*}:getIamPolicy")
}
opts = append((*c.CallOptions).GetIamPolicy[0:len((*c.CallOptions).GetIamPolicy):len((*c.CallOptions).GetIamPolicy)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &iampb.Policy{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetIamPolicy")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// SetIamPolicy sets the IAM access control policy for an
// Engine. A NOT_FOUND error
// is returned if the resource does not exist.
//
// Important: When setting a policy directly on an Engine resource,
// the only recommended roles in the bindings are:
// roles/discoveryengine.admin,
// roles/discoveryengine.agentspaceAdmin,
// roles/discoveryengine.user,
// roles/discoveryengine.agentspaceUser,
// roles/discoveryengine.viewer,
// roles/discoveryengine.agentspaceViewer.
// Attempting to grant any other role will result in a warning in logging.
func (c *engineRESTClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error) {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return nil, err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:setIamPolicy", req.GetResource())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "resource", url.QueryEscape(req.GetResource()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "resource_name", fmt.Sprintf("//discoveryengine.googleapis.com/%v", req.GetResource()))
}
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.cloud.discoveryengine.v1beta.EngineService/SetIamPolicy")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{resource=projects/*/locations/*/collections/*/engines/*}:setIamPolicy")
}
opts = append((*c.CallOptions).SetIamPolicy[0:len((*c.CallOptions).SetIamPolicy):len((*c.CallOptions).SetIamPolicy)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &iampb.Policy{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "SetIamPolicy")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// CancelOperation is a utility method from google.longrunning.Operations.
func (c *engineRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
jsonReq, err := m.Marshal(req)
if err != nil {
return err
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v:cancel", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.longrunning.Operations/CancelOperation")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/dataStores/*/branches/*/operations/*}:cancel")
}
return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
_, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
return err
}, opts...)
}
// GetOperation is a utility method from google.longrunning.Operations.
func (c *engineRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
hds = append(c.xGoogHeaders, hds...)
hds = append(hds, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
if gax.IsFeatureEnabled("METRICS") || gax.IsFeatureEnabled("TRACING") || gax.IsFeatureEnabled("LOGGING") {
ctx = callctx.WithTelemetryContext(ctx, "rpc_method", "google.longrunning.Operations/GetOperation")
ctx = callctx.WithTelemetryContext(ctx, "url_template", "/v1beta/{name=projects/*/locations/*/collections/*/dataConnector/operations/*}")
}
opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
resp := &longrunningpb.Operation{}
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq = httpReq.WithContext(ctx)
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, e
}
return resp, nil
}
// ListOperations is a utility method from google.longrunning.Operations.
func (c *engineRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
it := &OperationIterator{}
req = proto.CloneOf(req)
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
resp := &longrunningpb.ListOperationsResponse{}
if pageToken != "" {
req.PageToken = pageToken
}
if pageSize > math.MaxInt32 {
req.PageSize = math.MaxInt32
} else if pageSize != 0 {
req.PageSize = int32(pageSize)
}
baseUrl, err := url.Parse(c.endpoint)
if err != nil {
return nil, "", err
}
baseUrl.Path += fmt.Sprintf("/v1beta/%v/operations", req.GetName())
params := url.Values{}
params.Add("$alt", "json;enum-encoding=int")
if req.GetFilter() != "" {
params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
}
if req.GetPageSize() != 0 {
params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
}
if req.GetPageToken() != "" {
params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
}
if req.GetReturnPartialSuccess() {
params.Add("returnPartialSuccess", fmt.Sprintf("%v", req.GetReturnPartialSuccess()))
}
baseUrl.RawQuery = params.Encode()
// Build HTTP headers from client and context metadata.
hds := append(c.xGoogHeaders, "Content-Type", "application/json")
headers := gax.BuildHeaders(ctx, hds...)
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
if settings.Path != "" {
baseUrl.Path = settings.Path
}
httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
if err != nil {
return err
}
httpReq.Header = headers
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
if err != nil {
return err
}
if err := unm.Unmarshal(buf, resp); err != nil {
return err
}
return nil
}, opts...)
if e != nil {
return nil, "", e
}
it.Response = resp
return resp.GetOperations(), resp.GetNextPageToken(), nil
}
fetch := func(pageSize int, pageToken string) (string, error) {
items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
if err != nil {
return "", err
}
it.items = append(it.items, items...)
return nextPageToken, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
it.pageInfo.MaxSize = int(req.GetPageSize())
it.pageInfo.Token = req.GetPageToken()
return it
}
// CreateEngineOperation returns a new CreateEngineOperation from a given name.
// The name must be that of a previously created CreateEngineOperation, possibly from a different process.
func (c *engineGRPCClient) CreateEngineOperation(name string) *CreateEngineOperation {
return &CreateEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.CreateEngineOperation"),
}
}
// CreateEngineOperation returns a new CreateEngineOperation from a given name.
// The name must be that of a previously created CreateEngineOperation, possibly from a different process.
func (c *engineRESTClient) CreateEngineOperation(name string) *CreateEngineOperation {
override := fmt.Sprintf("/v1beta/%s", name)
return &CreateEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.CreateEngineOperation"),
pollPath: override,
}
}
// DeleteEngineOperation returns a new DeleteEngineOperation from a given name.
// The name must be that of a previously created DeleteEngineOperation, possibly from a different process.
func (c *engineGRPCClient) DeleteEngineOperation(name string) *DeleteEngineOperation {
return &DeleteEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.DeleteEngineOperation"),
}
}
// DeleteEngineOperation returns a new DeleteEngineOperation from a given name.
// The name must be that of a previously created DeleteEngineOperation, possibly from a different process.
func (c *engineRESTClient) DeleteEngineOperation(name string) *DeleteEngineOperation {
override := fmt.Sprintf("/v1beta/%s", name)
return &DeleteEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.DeleteEngineOperation"),
pollPath: override,
}
}
// TuneEngineOperation returns a new TuneEngineOperation from a given name.
// The name must be that of a previously created TuneEngineOperation, possibly from a different process.
func (c *engineGRPCClient) TuneEngineOperation(name string) *TuneEngineOperation {
return &TuneEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.TuneEngineOperation"),
}
}
// TuneEngineOperation returns a new TuneEngineOperation from a given name.
// The name must be that of a previously created TuneEngineOperation, possibly from a different process.
func (c *engineRESTClient) TuneEngineOperation(name string) *TuneEngineOperation {
override := fmt.Sprintf("/v1beta/%s", name)
return &TuneEngineOperation{
lro: longrunning.InternalNewOperationWithMetadata(*c.LROClient, &longrunningpb.Operation{Name: name}, "*discoveryengine.TuneEngineOperation"),
pollPath: override,
}
}