1// Copyright 2021 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 17package cx 18 19import ( 20 "context" 21 "fmt" 22 "math" 23 "net/url" 24 "time" 25 26 gax "github.com/googleapis/gax-go/v2" 27 "google.golang.org/api/iterator" 28 "google.golang.org/api/option" 29 "google.golang.org/api/option/internaloption" 30 gtransport "google.golang.org/api/transport/grpc" 31 cxpb "google.golang.org/genproto/googleapis/cloud/dialogflow/cx/v3beta1" 32 "google.golang.org/grpc" 33 "google.golang.org/grpc/codes" 34 "google.golang.org/grpc/metadata" 35 "google.golang.org/protobuf/proto" 36) 37 38var newSecuritySettingsClientHook clientHook 39 40// SecuritySettingsCallOptions contains the retry settings for each method of SecuritySettingsClient. 41type SecuritySettingsCallOptions struct { 42 CreateSecuritySettings []gax.CallOption 43 GetSecuritySettings []gax.CallOption 44 UpdateSecuritySettings []gax.CallOption 45 ListSecuritySettings []gax.CallOption 46 DeleteSecuritySettings []gax.CallOption 47} 48 49func defaultSecuritySettingsGRPCClientOptions() []option.ClientOption { 50 return []option.ClientOption{ 51 internaloption.WithDefaultEndpoint("dialogflow.googleapis.com:443"), 52 internaloption.WithDefaultMTLSEndpoint("dialogflow.mtls.googleapis.com:443"), 53 internaloption.WithDefaultAudience("https://dialogflow.googleapis.com/"), 54 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 55 internaloption.EnableJwtWithScope(), 56 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 57 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 58 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 59 } 60} 61 62func defaultSecuritySettingsCallOptions() *SecuritySettingsCallOptions { 63 return &SecuritySettingsCallOptions{ 64 CreateSecuritySettings: []gax.CallOption{ 65 gax.WithRetry(func() gax.Retryer { 66 return gax.OnCodes([]codes.Code{ 67 codes.Unavailable, 68 }, gax.Backoff{ 69 Initial: 100 * time.Millisecond, 70 Max: 60000 * time.Millisecond, 71 Multiplier: 1.30, 72 }) 73 }), 74 }, 75 GetSecuritySettings: []gax.CallOption{ 76 gax.WithRetry(func() gax.Retryer { 77 return gax.OnCodes([]codes.Code{ 78 codes.Unavailable, 79 }, gax.Backoff{ 80 Initial: 100 * time.Millisecond, 81 Max: 60000 * time.Millisecond, 82 Multiplier: 1.30, 83 }) 84 }), 85 }, 86 UpdateSecuritySettings: []gax.CallOption{ 87 gax.WithRetry(func() gax.Retryer { 88 return gax.OnCodes([]codes.Code{ 89 codes.Unavailable, 90 }, gax.Backoff{ 91 Initial: 100 * time.Millisecond, 92 Max: 60000 * time.Millisecond, 93 Multiplier: 1.30, 94 }) 95 }), 96 }, 97 ListSecuritySettings: []gax.CallOption{ 98 gax.WithRetry(func() gax.Retryer { 99 return gax.OnCodes([]codes.Code{ 100 codes.Unavailable, 101 }, gax.Backoff{ 102 Initial: 100 * time.Millisecond, 103 Max: 60000 * time.Millisecond, 104 Multiplier: 1.30, 105 }) 106 }), 107 }, 108 DeleteSecuritySettings: []gax.CallOption{ 109 gax.WithRetry(func() gax.Retryer { 110 return gax.OnCodes([]codes.Code{ 111 codes.Unavailable, 112 }, gax.Backoff{ 113 Initial: 100 * time.Millisecond, 114 Max: 60000 * time.Millisecond, 115 Multiplier: 1.30, 116 }) 117 }), 118 }, 119 } 120} 121 122// internalSecuritySettingsClient is an interface that defines the methods availaible from Dialogflow API. 123type internalSecuritySettingsClient interface { 124 Close() error 125 setGoogleClientInfo(...string) 126 Connection() *grpc.ClientConn 127 CreateSecuritySettings(context.Context, *cxpb.CreateSecuritySettingsRequest, ...gax.CallOption) (*cxpb.SecuritySettings, error) 128 GetSecuritySettings(context.Context, *cxpb.GetSecuritySettingsRequest, ...gax.CallOption) (*cxpb.SecuritySettings, error) 129 UpdateSecuritySettings(context.Context, *cxpb.UpdateSecuritySettingsRequest, ...gax.CallOption) (*cxpb.SecuritySettings, error) 130 ListSecuritySettings(context.Context, *cxpb.ListSecuritySettingsRequest, ...gax.CallOption) *SecuritySettingsIterator 131 DeleteSecuritySettings(context.Context, *cxpb.DeleteSecuritySettingsRequest, ...gax.CallOption) error 132} 133 134// SecuritySettingsClient is a client for interacting with Dialogflow API. 135// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 136// 137// Service for managing security settings for Dialogflow. 138type SecuritySettingsClient struct { 139 // The internal transport-dependent client. 140 internalClient internalSecuritySettingsClient 141 142 // The call options for this service. 143 CallOptions *SecuritySettingsCallOptions 144} 145 146// Wrapper methods routed to the internal client. 147 148// Close closes the connection to the API service. The user should invoke this when 149// the client is no longer required. 150func (c *SecuritySettingsClient) Close() error { 151 return c.internalClient.Close() 152} 153 154// setGoogleClientInfo sets the name and version of the application in 155// the `x-goog-api-client` header passed on each request. Intended for 156// use by Google-written clients. 157func (c *SecuritySettingsClient) setGoogleClientInfo(keyval ...string) { 158 c.internalClient.setGoogleClientInfo(keyval...) 159} 160 161// Connection returns a connection to the API service. 162// 163// Deprecated. 164func (c *SecuritySettingsClient) Connection() *grpc.ClientConn { 165 return c.internalClient.Connection() 166} 167 168// CreateSecuritySettings create security settings in the specified location. 169func (c *SecuritySettingsClient) CreateSecuritySettings(ctx context.Context, req *cxpb.CreateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 170 return c.internalClient.CreateSecuritySettings(ctx, req, opts...) 171} 172 173// GetSecuritySettings retrieves the specified SecuritySettings. 174// The returned settings may be stale by up to 1 minute. 175func (c *SecuritySettingsClient) GetSecuritySettings(ctx context.Context, req *cxpb.GetSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 176 return c.internalClient.GetSecuritySettings(ctx, req, opts...) 177} 178 179// UpdateSecuritySettings updates the specified SecuritySettings. 180func (c *SecuritySettingsClient) UpdateSecuritySettings(ctx context.Context, req *cxpb.UpdateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 181 return c.internalClient.UpdateSecuritySettings(ctx, req, opts...) 182} 183 184// ListSecuritySettings returns the list of all security settings in the specified location. 185func (c *SecuritySettingsClient) ListSecuritySettings(ctx context.Context, req *cxpb.ListSecuritySettingsRequest, opts ...gax.CallOption) *SecuritySettingsIterator { 186 return c.internalClient.ListSecuritySettings(ctx, req, opts...) 187} 188 189// DeleteSecuritySettings deletes the specified SecuritySettings. 190func (c *SecuritySettingsClient) DeleteSecuritySettings(ctx context.Context, req *cxpb.DeleteSecuritySettingsRequest, opts ...gax.CallOption) error { 191 return c.internalClient.DeleteSecuritySettings(ctx, req, opts...) 192} 193 194// securitySettingsGRPCClient is a client for interacting with Dialogflow API over gRPC transport. 195// 196// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 197type securitySettingsGRPCClient struct { 198 // Connection pool of gRPC connections to the service. 199 connPool gtransport.ConnPool 200 201 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 202 disableDeadlines bool 203 204 // Points back to the CallOptions field of the containing SecuritySettingsClient 205 CallOptions **SecuritySettingsCallOptions 206 207 // The gRPC API client. 208 securitySettingsClient cxpb.SecuritySettingsServiceClient 209 210 // The x-goog-* metadata to be sent with each request. 211 xGoogMetadata metadata.MD 212} 213 214// NewSecuritySettingsClient creates a new security settings service client based on gRPC. 215// The returned client must be Closed when it is done being used to clean up its underlying connections. 216// 217// Service for managing security settings for Dialogflow. 218func NewSecuritySettingsClient(ctx context.Context, opts ...option.ClientOption) (*SecuritySettingsClient, error) { 219 clientOpts := defaultSecuritySettingsGRPCClientOptions() 220 if newSecuritySettingsClientHook != nil { 221 hookOpts, err := newSecuritySettingsClientHook(ctx, clientHookParams{}) 222 if err != nil { 223 return nil, err 224 } 225 clientOpts = append(clientOpts, hookOpts...) 226 } 227 228 disableDeadlines, err := checkDisableDeadlines() 229 if err != nil { 230 return nil, err 231 } 232 233 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 234 if err != nil { 235 return nil, err 236 } 237 client := SecuritySettingsClient{CallOptions: defaultSecuritySettingsCallOptions()} 238 239 c := &securitySettingsGRPCClient{ 240 connPool: connPool, 241 disableDeadlines: disableDeadlines, 242 securitySettingsClient: cxpb.NewSecuritySettingsServiceClient(connPool), 243 CallOptions: &client.CallOptions, 244 } 245 c.setGoogleClientInfo() 246 247 client.internalClient = c 248 249 return &client, nil 250} 251 252// Connection returns a connection to the API service. 253// 254// Deprecated. 255func (c *securitySettingsGRPCClient) Connection() *grpc.ClientConn { 256 return c.connPool.Conn() 257} 258 259// setGoogleClientInfo sets the name and version of the application in 260// the `x-goog-api-client` header passed on each request. Intended for 261// use by Google-written clients. 262func (c *securitySettingsGRPCClient) setGoogleClientInfo(keyval ...string) { 263 kv := append([]string{"gl-go", versionGo()}, keyval...) 264 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 265 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 266} 267 268// Close closes the connection to the API service. The user should invoke this when 269// the client is no longer required. 270func (c *securitySettingsGRPCClient) Close() error { 271 return c.connPool.Close() 272} 273 274func (c *securitySettingsGRPCClient) CreateSecuritySettings(ctx context.Context, req *cxpb.CreateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 275 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 276 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 277 defer cancel() 278 ctx = cctx 279 } 280 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 281 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 282 opts = append((*c.CallOptions).CreateSecuritySettings[0:len((*c.CallOptions).CreateSecuritySettings):len((*c.CallOptions).CreateSecuritySettings)], opts...) 283 var resp *cxpb.SecuritySettings 284 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 285 var err error 286 resp, err = c.securitySettingsClient.CreateSecuritySettings(ctx, req, settings.GRPC...) 287 return err 288 }, opts...) 289 if err != nil { 290 return nil, err 291 } 292 return resp, nil 293} 294 295func (c *securitySettingsGRPCClient) GetSecuritySettings(ctx context.Context, req *cxpb.GetSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 296 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 297 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 298 defer cancel() 299 ctx = cctx 300 } 301 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 302 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 303 opts = append((*c.CallOptions).GetSecuritySettings[0:len((*c.CallOptions).GetSecuritySettings):len((*c.CallOptions).GetSecuritySettings)], opts...) 304 var resp *cxpb.SecuritySettings 305 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 306 var err error 307 resp, err = c.securitySettingsClient.GetSecuritySettings(ctx, req, settings.GRPC...) 308 return err 309 }, opts...) 310 if err != nil { 311 return nil, err 312 } 313 return resp, nil 314} 315 316func (c *securitySettingsGRPCClient) UpdateSecuritySettings(ctx context.Context, req *cxpb.UpdateSecuritySettingsRequest, opts ...gax.CallOption) (*cxpb.SecuritySettings, error) { 317 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 318 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 319 defer cancel() 320 ctx = cctx 321 } 322 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "security_settings.name", url.QueryEscape(req.GetSecuritySettings().GetName()))) 323 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 324 opts = append((*c.CallOptions).UpdateSecuritySettings[0:len((*c.CallOptions).UpdateSecuritySettings):len((*c.CallOptions).UpdateSecuritySettings)], opts...) 325 var resp *cxpb.SecuritySettings 326 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 327 var err error 328 resp, err = c.securitySettingsClient.UpdateSecuritySettings(ctx, req, settings.GRPC...) 329 return err 330 }, opts...) 331 if err != nil { 332 return nil, err 333 } 334 return resp, nil 335} 336 337func (c *securitySettingsGRPCClient) ListSecuritySettings(ctx context.Context, req *cxpb.ListSecuritySettingsRequest, opts ...gax.CallOption) *SecuritySettingsIterator { 338 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))) 339 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 340 opts = append((*c.CallOptions).ListSecuritySettings[0:len((*c.CallOptions).ListSecuritySettings):len((*c.CallOptions).ListSecuritySettings)], opts...) 341 it := &SecuritySettingsIterator{} 342 req = proto.Clone(req).(*cxpb.ListSecuritySettingsRequest) 343 it.InternalFetch = func(pageSize int, pageToken string) ([]*cxpb.SecuritySettings, string, error) { 344 resp := &cxpb.ListSecuritySettingsResponse{} 345 if pageToken != "" { 346 req.PageToken = pageToken 347 } 348 if pageSize > math.MaxInt32 { 349 req.PageSize = math.MaxInt32 350 } else if pageSize != 0 { 351 req.PageSize = int32(pageSize) 352 } 353 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 354 var err error 355 resp, err = c.securitySettingsClient.ListSecuritySettings(ctx, req, settings.GRPC...) 356 return err 357 }, opts...) 358 if err != nil { 359 return nil, "", err 360 } 361 362 it.Response = resp 363 return resp.GetSecuritySettings(), resp.GetNextPageToken(), nil 364 } 365 fetch := func(pageSize int, pageToken string) (string, error) { 366 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken) 367 if err != nil { 368 return "", err 369 } 370 it.items = append(it.items, items...) 371 return nextPageToken, nil 372 } 373 374 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf) 375 it.pageInfo.MaxSize = int(req.GetPageSize()) 376 it.pageInfo.Token = req.GetPageToken() 377 378 return it 379} 380 381func (c *securitySettingsGRPCClient) DeleteSecuritySettings(ctx context.Context, req *cxpb.DeleteSecuritySettingsRequest, opts ...gax.CallOption) error { 382 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 383 cctx, cancel := context.WithTimeout(ctx, 60000*time.Millisecond) 384 defer cancel() 385 ctx = cctx 386 } 387 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))) 388 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 389 opts = append((*c.CallOptions).DeleteSecuritySettings[0:len((*c.CallOptions).DeleteSecuritySettings):len((*c.CallOptions).DeleteSecuritySettings)], opts...) 390 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 391 var err error 392 _, err = c.securitySettingsClient.DeleteSecuritySettings(ctx, req, settings.GRPC...) 393 return err 394 }, opts...) 395 return err 396} 397 398// SecuritySettingsIterator manages a stream of *cxpb.SecuritySettings. 399type SecuritySettingsIterator struct { 400 items []*cxpb.SecuritySettings 401 pageInfo *iterator.PageInfo 402 nextFunc func() error 403 404 // Response is the raw response for the current page. 405 // It must be cast to the RPC response type. 406 // Calling Next() or InternalFetch() updates this value. 407 Response interface{} 408 409 // InternalFetch is for use by the Google Cloud Libraries only. 410 // It is not part of the stable interface of this package. 411 // 412 // InternalFetch returns results from a single call to the underlying RPC. 413 // The number of results is no greater than pageSize. 414 // If there are no more results, nextPageToken is empty and err is nil. 415 InternalFetch func(pageSize int, pageToken string) (results []*cxpb.SecuritySettings, nextPageToken string, err error) 416} 417 418// PageInfo supports pagination. See the google.golang.org/api/iterator package for details. 419func (it *SecuritySettingsIterator) PageInfo() *iterator.PageInfo { 420 return it.pageInfo 421} 422 423// Next returns the next result. Its second return value is iterator.Done if there are no more 424// results. Once Next returns Done, all subsequent calls will return Done. 425func (it *SecuritySettingsIterator) Next() (*cxpb.SecuritySettings, error) { 426 var item *cxpb.SecuritySettings 427 if err := it.nextFunc(); err != nil { 428 return item, err 429 } 430 item = it.items[0] 431 it.items = it.items[1:] 432 return item, nil 433} 434 435func (it *SecuritySettingsIterator) bufLen() int { 436 return len(it.items) 437} 438 439func (it *SecuritySettingsIterator) takeBuf() interface{} { 440 b := it.items 441 it.items = nil 442 return b 443} 444