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 webrisk 18 19import ( 20 "context" 21 "math" 22 "time" 23 24 gax "github.com/googleapis/gax-go/v2" 25 "google.golang.org/api/option" 26 "google.golang.org/api/option/internaloption" 27 gtransport "google.golang.org/api/transport/grpc" 28 webriskpb "google.golang.org/genproto/googleapis/cloud/webrisk/v1beta1" 29 "google.golang.org/grpc" 30 "google.golang.org/grpc/codes" 31 "google.golang.org/grpc/metadata" 32) 33 34var newWebRiskServiceV1Beta1ClientHook clientHook 35 36// WebRiskServiceV1Beta1CallOptions contains the retry settings for each method of WebRiskServiceV1Beta1Client. 37type WebRiskServiceV1Beta1CallOptions struct { 38 ComputeThreatListDiff []gax.CallOption 39 SearchUris []gax.CallOption 40 SearchHashes []gax.CallOption 41} 42 43func defaultWebRiskServiceV1Beta1GRPCClientOptions() []option.ClientOption { 44 return []option.ClientOption{ 45 internaloption.WithDefaultEndpoint("webrisk.googleapis.com:443"), 46 internaloption.WithDefaultMTLSEndpoint("webrisk.mtls.googleapis.com:443"), 47 internaloption.WithDefaultAudience("https://webrisk.googleapis.com/"), 48 internaloption.WithDefaultScopes(DefaultAuthScopes()...), 49 internaloption.EnableJwtWithScope(), 50 option.WithGRPCDialOption(grpc.WithDisableServiceConfig()), 51 option.WithGRPCDialOption(grpc.WithDefaultCallOptions( 52 grpc.MaxCallRecvMsgSize(math.MaxInt32))), 53 } 54} 55 56func defaultWebRiskServiceV1Beta1CallOptions() *WebRiskServiceV1Beta1CallOptions { 57 return &WebRiskServiceV1Beta1CallOptions{ 58 ComputeThreatListDiff: []gax.CallOption{ 59 gax.WithRetry(func() gax.Retryer { 60 return gax.OnCodes([]codes.Code{ 61 codes.DeadlineExceeded, 62 codes.Unavailable, 63 }, gax.Backoff{ 64 Initial: 100 * time.Millisecond, 65 Max: 60000 * time.Millisecond, 66 Multiplier: 1.30, 67 }) 68 }), 69 }, 70 SearchUris: []gax.CallOption{ 71 gax.WithRetry(func() gax.Retryer { 72 return gax.OnCodes([]codes.Code{ 73 codes.DeadlineExceeded, 74 codes.Unavailable, 75 }, gax.Backoff{ 76 Initial: 100 * time.Millisecond, 77 Max: 60000 * time.Millisecond, 78 Multiplier: 1.30, 79 }) 80 }), 81 }, 82 SearchHashes: []gax.CallOption{ 83 gax.WithRetry(func() gax.Retryer { 84 return gax.OnCodes([]codes.Code{ 85 codes.DeadlineExceeded, 86 codes.Unavailable, 87 }, gax.Backoff{ 88 Initial: 100 * time.Millisecond, 89 Max: 60000 * time.Millisecond, 90 Multiplier: 1.30, 91 }) 92 }), 93 }, 94 } 95} 96 97// internalWebRiskServiceV1Beta1Client is an interface that defines the methods availaible from Web Risk API. 98type internalWebRiskServiceV1Beta1Client interface { 99 Close() error 100 setGoogleClientInfo(...string) 101 Connection() *grpc.ClientConn 102 ComputeThreatListDiff(context.Context, *webriskpb.ComputeThreatListDiffRequest, ...gax.CallOption) (*webriskpb.ComputeThreatListDiffResponse, error) 103 SearchUris(context.Context, *webriskpb.SearchUrisRequest, ...gax.CallOption) (*webriskpb.SearchUrisResponse, error) 104 SearchHashes(context.Context, *webriskpb.SearchHashesRequest, ...gax.CallOption) (*webriskpb.SearchHashesResponse, error) 105} 106 107// WebRiskServiceV1Beta1Client is a client for interacting with Web Risk API. 108// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 109// 110// Web Risk v1beta1 API defines an interface to detect malicious URLs on your 111// website and in client applications. 112type WebRiskServiceV1Beta1Client struct { 113 // The internal transport-dependent client. 114 internalClient internalWebRiskServiceV1Beta1Client 115 116 // The call options for this service. 117 CallOptions *WebRiskServiceV1Beta1CallOptions 118} 119 120// Wrapper methods routed to the internal client. 121 122// Close closes the connection to the API service. The user should invoke this when 123// the client is no longer required. 124func (c *WebRiskServiceV1Beta1Client) Close() error { 125 return c.internalClient.Close() 126} 127 128// setGoogleClientInfo sets the name and version of the application in 129// the `x-goog-api-client` header passed on each request. Intended for 130// use by Google-written clients. 131func (c *WebRiskServiceV1Beta1Client) setGoogleClientInfo(keyval ...string) { 132 c.internalClient.setGoogleClientInfo(keyval...) 133} 134 135// Connection returns a connection to the API service. 136// 137// Deprecated. 138func (c *WebRiskServiceV1Beta1Client) Connection() *grpc.ClientConn { 139 return c.internalClient.Connection() 140} 141 142// ComputeThreatListDiff gets the most recent threat list diffs. 143func (c *WebRiskServiceV1Beta1Client) ComputeThreatListDiff(ctx context.Context, req *webriskpb.ComputeThreatListDiffRequest, opts ...gax.CallOption) (*webriskpb.ComputeThreatListDiffResponse, error) { 144 return c.internalClient.ComputeThreatListDiff(ctx, req, opts...) 145} 146 147// SearchUris this method is used to check whether a URI is on a given threatList. 148func (c *WebRiskServiceV1Beta1Client) SearchUris(ctx context.Context, req *webriskpb.SearchUrisRequest, opts ...gax.CallOption) (*webriskpb.SearchUrisResponse, error) { 149 return c.internalClient.SearchUris(ctx, req, opts...) 150} 151 152// SearchHashes gets the full hashes that match the requested hash prefix. 153// This is used after a hash prefix is looked up in a threatList 154// and there is a match. The client side threatList only holds partial hashes 155// so the client must query this method to determine if there is a full 156// hash match of a threat. 157func (c *WebRiskServiceV1Beta1Client) SearchHashes(ctx context.Context, req *webriskpb.SearchHashesRequest, opts ...gax.CallOption) (*webriskpb.SearchHashesResponse, error) { 158 return c.internalClient.SearchHashes(ctx, req, opts...) 159} 160 161// webRiskServiceV1Beta1GRPCClient is a client for interacting with Web Risk API over gRPC transport. 162// 163// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. 164type webRiskServiceV1Beta1GRPCClient struct { 165 // Connection pool of gRPC connections to the service. 166 connPool gtransport.ConnPool 167 168 // flag to opt out of default deadlines via GOOGLE_API_GO_EXPERIMENTAL_DISABLE_DEFAULT_DEADLINE 169 disableDeadlines bool 170 171 // Points back to the CallOptions field of the containing WebRiskServiceV1Beta1Client 172 CallOptions **WebRiskServiceV1Beta1CallOptions 173 174 // The gRPC API client. 175 webRiskServiceV1Beta1Client webriskpb.WebRiskServiceV1Beta1Client 176 177 // The x-goog-* metadata to be sent with each request. 178 xGoogMetadata metadata.MD 179} 180 181// NewWebRiskServiceV1Beta1Client creates a new web risk service v1 beta1 client based on gRPC. 182// The returned client must be Closed when it is done being used to clean up its underlying connections. 183// 184// Web Risk v1beta1 API defines an interface to detect malicious URLs on your 185// website and in client applications. 186func NewWebRiskServiceV1Beta1Client(ctx context.Context, opts ...option.ClientOption) (*WebRiskServiceV1Beta1Client, error) { 187 clientOpts := defaultWebRiskServiceV1Beta1GRPCClientOptions() 188 if newWebRiskServiceV1Beta1ClientHook != nil { 189 hookOpts, err := newWebRiskServiceV1Beta1ClientHook(ctx, clientHookParams{}) 190 if err != nil { 191 return nil, err 192 } 193 clientOpts = append(clientOpts, hookOpts...) 194 } 195 196 disableDeadlines, err := checkDisableDeadlines() 197 if err != nil { 198 return nil, err 199 } 200 201 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) 202 if err != nil { 203 return nil, err 204 } 205 client := WebRiskServiceV1Beta1Client{CallOptions: defaultWebRiskServiceV1Beta1CallOptions()} 206 207 c := &webRiskServiceV1Beta1GRPCClient{ 208 connPool: connPool, 209 disableDeadlines: disableDeadlines, 210 webRiskServiceV1Beta1Client: webriskpb.NewWebRiskServiceV1Beta1Client(connPool), 211 CallOptions: &client.CallOptions, 212 } 213 c.setGoogleClientInfo() 214 215 client.internalClient = c 216 217 return &client, nil 218} 219 220// Connection returns a connection to the API service. 221// 222// Deprecated. 223func (c *webRiskServiceV1Beta1GRPCClient) Connection() *grpc.ClientConn { 224 return c.connPool.Conn() 225} 226 227// setGoogleClientInfo sets the name and version of the application in 228// the `x-goog-api-client` header passed on each request. Intended for 229// use by Google-written clients. 230func (c *webRiskServiceV1Beta1GRPCClient) setGoogleClientInfo(keyval ...string) { 231 kv := append([]string{"gl-go", versionGo()}, keyval...) 232 kv = append(kv, "gapic", versionClient, "gax", gax.Version, "grpc", grpc.Version) 233 c.xGoogMetadata = metadata.Pairs("x-goog-api-client", gax.XGoogHeader(kv...)) 234} 235 236// Close closes the connection to the API service. The user should invoke this when 237// the client is no longer required. 238func (c *webRiskServiceV1Beta1GRPCClient) Close() error { 239 return c.connPool.Close() 240} 241 242func (c *webRiskServiceV1Beta1GRPCClient) ComputeThreatListDiff(ctx context.Context, req *webriskpb.ComputeThreatListDiffRequest, opts ...gax.CallOption) (*webriskpb.ComputeThreatListDiffResponse, error) { 243 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 244 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 245 defer cancel() 246 ctx = cctx 247 } 248 ctx = insertMetadata(ctx, c.xGoogMetadata) 249 opts = append((*c.CallOptions).ComputeThreatListDiff[0:len((*c.CallOptions).ComputeThreatListDiff):len((*c.CallOptions).ComputeThreatListDiff)], opts...) 250 var resp *webriskpb.ComputeThreatListDiffResponse 251 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 252 var err error 253 resp, err = c.webRiskServiceV1Beta1Client.ComputeThreatListDiff(ctx, req, settings.GRPC...) 254 return err 255 }, opts...) 256 if err != nil { 257 return nil, err 258 } 259 return resp, nil 260} 261 262func (c *webRiskServiceV1Beta1GRPCClient) SearchUris(ctx context.Context, req *webriskpb.SearchUrisRequest, opts ...gax.CallOption) (*webriskpb.SearchUrisResponse, error) { 263 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 264 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 265 defer cancel() 266 ctx = cctx 267 } 268 ctx = insertMetadata(ctx, c.xGoogMetadata) 269 opts = append((*c.CallOptions).SearchUris[0:len((*c.CallOptions).SearchUris):len((*c.CallOptions).SearchUris)], opts...) 270 var resp *webriskpb.SearchUrisResponse 271 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 272 var err error 273 resp, err = c.webRiskServiceV1Beta1Client.SearchUris(ctx, req, settings.GRPC...) 274 return err 275 }, opts...) 276 if err != nil { 277 return nil, err 278 } 279 return resp, nil 280} 281 282func (c *webRiskServiceV1Beta1GRPCClient) SearchHashes(ctx context.Context, req *webriskpb.SearchHashesRequest, opts ...gax.CallOption) (*webriskpb.SearchHashesResponse, error) { 283 if _, ok := ctx.Deadline(); !ok && !c.disableDeadlines { 284 cctx, cancel := context.WithTimeout(ctx, 600000*time.Millisecond) 285 defer cancel() 286 ctx = cctx 287 } 288 ctx = insertMetadata(ctx, c.xGoogMetadata) 289 opts = append((*c.CallOptions).SearchHashes[0:len((*c.CallOptions).SearchHashes):len((*c.CallOptions).SearchHashes)], opts...) 290 var resp *webriskpb.SearchHashesResponse 291 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { 292 var err error 293 resp, err = c.webRiskServiceV1Beta1Client.SearchHashes(ctx, req, settings.GRPC...) 294 return err 295 }, opts...) 296 if err != nil { 297 return nil, err 298 } 299 return resp, nil 300} 301