1// Copyright 2019 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 gapic-generator. DO NOT EDIT. 16 17package recaptchaenterprise 18 19import ( 20 "context" 21 "fmt" 22 23 gax "github.com/googleapis/gax-go/v2" 24 "google.golang.org/api/option" 25 "google.golang.org/api/transport" 26 recaptchaenterprisepb "google.golang.org/genproto/googleapis/cloud/recaptchaenterprise/v1beta1" 27 "google.golang.org/grpc" 28 "google.golang.org/grpc/metadata" 29) 30 31// RecaptchaEnterpriseServiceV1Beta1CallOptions contains the retry settings for each method of RecaptchaEnterpriseServiceV1Beta1Client. 32type RecaptchaEnterpriseServiceV1Beta1CallOptions struct { 33 CreateAssessment []gax.CallOption 34 AnnotateAssessment []gax.CallOption 35} 36 37func defaultRecaptchaEnterpriseServiceV1Beta1ClientOptions() []option.ClientOption { 38 return []option.ClientOption{ 39 option.WithEndpoint("recaptchaenterprise.googleapis.com:443"), 40 option.WithScopes(DefaultAuthScopes()...), 41 } 42} 43 44func defaultRecaptchaEnterpriseServiceV1Beta1CallOptions() *RecaptchaEnterpriseServiceV1Beta1CallOptions { 45 retry := map[[2]string][]gax.CallOption{} 46 return &RecaptchaEnterpriseServiceV1Beta1CallOptions{ 47 CreateAssessment: retry[[2]string{"default", "non_idempotent"}], 48 AnnotateAssessment: retry[[2]string{"default", "non_idempotent"}], 49 } 50} 51 52// RecaptchaEnterpriseServiceV1Beta1Client is a client for interacting with reCAPTCHA Enterprise API. 53// 54// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 55type RecaptchaEnterpriseServiceV1Beta1Client struct { 56 // The connection to the service. 57 conn *grpc.ClientConn 58 59 // The gRPC API client. 60 recaptchaEnterpriseServiceV1Beta1Client recaptchaenterprisepb.RecaptchaEnterpriseServiceV1Beta1Client 61 62 // The call options for this service. 63 CallOptions *RecaptchaEnterpriseServiceV1Beta1CallOptions 64 65 // The x-goog-* metadata to be sent with each request. 66 xGoogMetadata metadata.MD 67} 68 69// NewRecaptchaEnterpriseServiceV1Beta1Client creates a new recaptcha enterprise service v1 beta1 client. 70// 71// Service to determine the likelihood an event is legitimate. 72func NewRecaptchaEnterpriseServiceV1Beta1Client(ctx context.Context, opts ...option.ClientOption) (*RecaptchaEnterpriseServiceV1Beta1Client, error) { 73 conn, err := transport.DialGRPC(ctx, append(defaultRecaptchaEnterpriseServiceV1Beta1ClientOptions(), opts...)...) 74 if err != nil { 75 return nil, err 76 } 77 c := &RecaptchaEnterpriseServiceV1Beta1Client{ 78 conn: conn, 79 CallOptions: defaultRecaptchaEnterpriseServiceV1Beta1CallOptions(), 80 81 recaptchaEnterpriseServiceV1Beta1Client: recaptchaenterprisepb.NewRecaptchaEnterpriseServiceV1Beta1Client(conn), 82 } 83 c.setGoogleClientInfo() 84 return c, nil 85} 86 87// Connection returns the client's connection to the API service. 88func (c *RecaptchaEnterpriseServiceV1Beta1Client) Connection() *grpc.ClientConn { 89 return c.conn 90} 91 92// Close closes the connection to the API service. The user should invoke this when 93// the client is no longer required. 94func (c *RecaptchaEnterpriseServiceV1Beta1Client) Close() error { 95 return c.conn.Close() 96} 97 98// setGoogleClientInfo sets the name and version of the application in 99// the `x-goog-api-client` header passed on each request. Intended for 100// use by Google-written clients. 101func (c *RecaptchaEnterpriseServiceV1Beta1Client) setGoogleClientInfo(keyval ...string) { 102 kv := append([]string{"gl-go", versionGo()}, keyval...) 103 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 104 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 105} 106 107// CreateAssessment creates an Assessment of the likelihood an event is legitimate. 108func (c *RecaptchaEnterpriseServiceV1Beta1Client) CreateAssessment(ctx context.Context, req *recaptchaenterprisepb.CreateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.Assessment, error) { 109 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "parent", req.GetParent())) 110 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 111 opts = append(c.CallOptions.CreateAssessment[0:len(c.CallOptions.CreateAssessment):len(c.CallOptions.CreateAssessment)], opts...) 112 var resp *recaptchaenterprisepb.Assessment 113 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 114 var err error 115 resp, err = c.recaptchaEnterpriseServiceV1Beta1Client.CreateAssessment(ctx, req, settings.GRPC...) 116 return err 117 }, opts...) 118 if err != nil { 119 return nil, err 120 } 121 return resp, nil 122} 123 124// AnnotateAssessment annotates a previously created Assessment to provide additional information 125// on whether the event turned out to be authentic or fradulent. 126func (c *RecaptchaEnterpriseServiceV1Beta1Client) AnnotateAssessment(ctx context.Context, req *recaptchaenterprisepb.AnnotateAssessmentRequest, opts ...gax.CallOption) (*recaptchaenterprisepb.AnnotateAssessmentResponse, error) { 127 md := metadata.Pairs("x-goog-request-params", fmt.Sprintf("%s=%v", "name", req.GetName())) 128 ctx = insertMetadata(ctx, c.xGoogMetadata, md) 129 opts = append(c.CallOptions.AnnotateAssessment[0:len(c.CallOptions.AnnotateAssessment):len(c.CallOptions.AnnotateAssessment)], opts...) 130 var resp *recaptchaenterprisepb.AnnotateAssessmentResponse 131 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 132 var err error 133 resp, err = c.recaptchaEnterpriseServiceV1Beta1Client.AnnotateAssessment(ctx, req, settings.GRPC...) 134 return err 135 }, opts...) 136 if err != nil { 137 return nil, err 138 } 139 return resp, nil 140} 141