| 1 |
// Copyright 2025 Google LLC |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// https://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Code generated by protoc-gen-go_gapic. DO NOT EDIT. |
| 16 |
|
| 17 |
package phishingprotection |
| 18 |
|
| 19 |
import ( |
| 20 |
"bytes" |
| 21 |
"context" |
| 22 |
"fmt" |
| 23 |
"log/slog" |
| 24 |
"math" |
| 25 |
"net/http" |
| 26 |
"net/url" |
| 27 |
"time" |
| 28 |
|
| 29 |
phishingprotectionpb "cloud.google.com/go/phishingprotection/apiv1beta1/phishingprotectionpb" |
| 30 |
gax "github.com/googleapis/gax-go/v2" |
| 31 |
"google.golang.org/api/option" |
| 32 |
"google.golang.org/api/option/internaloption" |
| 33 |
gtransport "google.golang.org/api/transport/grpc" |
| 34 |
httptransport "google.golang.org/api/transport/http" |
| 35 |
"google.golang.org/grpc" |
| 36 |
"google.golang.org/protobuf/encoding/protojson" |
| 37 |
) |
| 38 |
|
| 39 |
var newPhishingProtectionServiceV1Beta1ClientHook clientHook |
| 40 |
|
| 41 |
// PhishingProtectionServiceV1Beta1CallOptions contains the retry settings for each method of PhishingProtectionServiceV1Beta1Client. |
| 42 |
type PhishingProtectionServiceV1Beta1CallOptions struct { |
| 43 |
ReportPhishing []gax.CallOption |
| 44 |
} |
| 45 |
|
| 46 |
func defaultPhishingProtectionServiceV1Beta1GRPCClientOptions() []option.ClientOption { |
| 47 |
return []option.ClientOption{ |
| 48 |
internaloption.WithDefaultEndpoint("phishingprotection.googleapis.com:443"), |
| 49 |
internaloption.WithDefaultEndpointTemplate("phishingprotection.UNIVERSE_DOMAIN:443"), |
| 50 |
internaloption.WithDefaultMTLSEndpoint("phishingprotection.mtls.googleapis.com:443"), |
| 51 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 52 |
internaloption.WithDefaultAudience("https://phishingprotection.googleapis.com/"), |
| 53 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 54 |
internaloption.EnableJwtWithScope(), |
| 55 |
internaloption.EnableNewAuthLibrary(), |
| 56 |
option.WithGRPCDialOption(grpc.WithDefaultCallOptions( |
| 57 |
grpc.MaxCallRecvMsgSize(math.MaxInt32))), |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
func defaultPhishingProtectionServiceV1Beta1CallOptions() *PhishingProtectionServiceV1Beta1CallOptions { |
| 62 |
return &PhishingProtectionServiceV1Beta1CallOptions{ |
| 63 |
ReportPhishing: []gax.CallOption{ |
| 64 |
gax.WithTimeout(600000 * time.Millisecond), |
| 65 |
}, |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
func defaultPhishingProtectionServiceV1Beta1RESTCallOptions() *PhishingProtectionServiceV1Beta1CallOptions { |
| 70 |
return &PhishingProtectionServiceV1Beta1CallOptions{ |
| 71 |
ReportPhishing: []gax.CallOption{ |
| 72 |
gax.WithTimeout(600000 * time.Millisecond), |
| 73 |
}, |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
// internalPhishingProtectionServiceV1Beta1Client is an interface that defines the methods available from Phishing Protection API. |
| 78 |
type internalPhishingProtectionServiceV1Beta1Client interface { |
| 79 |
Close() error |
| 80 |
setGoogleClientInfo(...string) |
| 81 |
Connection() *grpc.ClientConn |
| 82 |
ReportPhishing(context.Context, *phishingprotectionpb.ReportPhishingRequest, ...gax.CallOption) (*phishingprotectionpb.ReportPhishingResponse, error) |
| 83 |
} |
| 84 |
|
| 85 |
// PhishingProtectionServiceV1Beta1Client is a client for interacting with Phishing Protection API. |
| 86 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 87 |
// |
| 88 |
// Service to report phishing URIs. |
| 89 |
type PhishingProtectionServiceV1Beta1Client struct { |
| 90 |
// The internal transport-dependent client. |
| 91 |
internalClient internalPhishingProtectionServiceV1Beta1Client |
| 92 |
|
| 93 |
// The call options for this service. |
| 94 |
CallOptions *PhishingProtectionServiceV1Beta1CallOptions |
| 95 |
} |
| 96 |
|
| 97 |
// Wrapper methods routed to the internal client. |
| 98 |
|
| 99 |
// Close closes the connection to the API service. The user should invoke this when |
| 100 |
// the client is no longer required. |
| 101 |
func (c *PhishingProtectionServiceV1Beta1Client) Close() error { |
| 102 |
return c.internalClient.Close() |
| 103 |
} |
| 104 |
|
| 105 |
// setGoogleClientInfo sets the name and version of the application in |
| 106 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 107 |
// use by Google-written clients. |
| 108 |
func (c *PhishingProtectionServiceV1Beta1Client) setGoogleClientInfo(keyval ...string) { |
| 109 |
c.internalClient.setGoogleClientInfo(keyval...) |
| 110 |
} |
| 111 |
|
| 112 |
// Connection returns a connection to the API service. |
| 113 |
// |
| 114 |
// Deprecated: Connections are now pooled so this method does not always |
| 115 |
// return the same resource. |
| 116 |
func (c *PhishingProtectionServiceV1Beta1Client) Connection() *grpc.ClientConn { |
| 117 |
return c.internalClient.Connection() |
| 118 |
} |
| 119 |
|
| 120 |
// ReportPhishing reports a URI suspected of containing phishing content to be reviewed. Once |
| 121 |
// the report review is complete, its result can be found in the Cloud |
| 122 |
// Security Command Center findings dashboard for Phishing Protection. If the |
| 123 |
// result verifies the existence of malicious phishing content, the site will |
| 124 |
// be added the to Google’s Social Engineering |
| 125 |
// lists (at https://support.google.com/webmasters/answer/6350487/) in order to |
| 126 |
// protect users that could get exposed to this threat in the future. |
| 127 |
func (c *PhishingProtectionServiceV1Beta1Client) ReportPhishing(ctx context.Context, req *phishingprotectionpb.ReportPhishingRequest, opts ...gax.CallOption) (*phishingprotectionpb.ReportPhishingResponse, error) { |
| 128 |
return c.internalClient.ReportPhishing(ctx, req, opts...) |
| 129 |
} |
| 130 |
|
| 131 |
// phishingProtectionServiceV1Beta1GRPCClient is a client for interacting with Phishing Protection API over gRPC transport. |
| 132 |
// |
| 133 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 134 |
type phishingProtectionServiceV1Beta1GRPCClient struct { |
| 135 |
// Connection pool of gRPC connections to the service. |
| 136 |
connPool gtransport.ConnPool |
| 137 |
|
| 138 |
// Points back to the CallOptions field of the containing PhishingProtectionServiceV1Beta1Client |
| 139 |
CallOptions **PhishingProtectionServiceV1Beta1CallOptions |
| 140 |
|
| 141 |
// The gRPC API client. |
| 142 |
phishingProtectionServiceV1Beta1Client phishingprotectionpb.PhishingProtectionServiceV1Beta1Client |
| 143 |
|
| 144 |
// The x-goog-* metadata to be sent with each request. |
| 145 |
xGoogHeaders []string |
| 146 |
|
| 147 |
logger *slog.Logger |
| 148 |
} |
| 149 |
|
| 150 |
// NewPhishingProtectionServiceV1Beta1Client creates a new phishing protection service v1 beta1 client based on gRPC. |
| 151 |
// The returned client must be Closed when it is done being used to clean up its underlying connections. |
| 152 |
// |
| 153 |
// Service to report phishing URIs. |
| 154 |
func NewPhishingProtectionServiceV1Beta1Client(ctx context.Context, opts ...option.ClientOption) (*PhishingProtectionServiceV1Beta1Client, error) { |
| 155 |
clientOpts := defaultPhishingProtectionServiceV1Beta1GRPCClientOptions() |
| 156 |
if newPhishingProtectionServiceV1Beta1ClientHook != nil { |
| 157 |
hookOpts, err := newPhishingProtectionServiceV1Beta1ClientHook(ctx, clientHookParams{}) |
| 158 |
if err != nil { |
| 159 |
return nil, err |
| 160 |
} |
| 161 |
clientOpts = append(clientOpts, hookOpts...) |
| 162 |
} |
| 163 |
|
| 164 |
connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) |
| 165 |
if err != nil { |
| 166 |
return nil, err |
| 167 |
} |
| 168 |
client := PhishingProtectionServiceV1Beta1Client{CallOptions: defaultPhishingProtectionServiceV1Beta1CallOptions()} |
| 169 |
|
| 170 |
c := &phishingProtectionServiceV1Beta1GRPCClient{ |
| 171 |
connPool: connPool, |
| 172 |
phishingProtectionServiceV1Beta1Client: phishingprotectionpb.NewPhishingProtectionServiceV1Beta1Client(connPool), |
| 173 |
CallOptions: &client.CallOptions, |
| 174 |
logger: internaloption.GetLogger(opts), |
| 175 |
} |
| 176 |
c.setGoogleClientInfo() |
| 177 |
|
| 178 |
client.internalClient = c |
| 179 |
|
| 180 |
return &client, nil |
| 181 |
} |
| 182 |
|
| 183 |
// Connection returns a connection to the API service. |
| 184 |
// |
| 185 |
// Deprecated: Connections are now pooled so this method does not always |
| 186 |
// return the same resource. |
| 187 |
func (c *phishingProtectionServiceV1Beta1GRPCClient) Connection() *grpc.ClientConn { |
| 188 |
return c.connPool.Conn() |
| 189 |
} |
| 190 |
|
| 191 |
// setGoogleClientInfo sets the name and version of the application in |
| 192 |
// the `x-goog-api-client` header passed on each request. Intended for |
| 193 |
// use by Google-written clients. |
| 194 |
func (c *phishingProtectionServiceV1Beta1GRPCClient) setGoogleClientInfo(keyval ...string) { |
| 195 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 196 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion) |
| 197 |
c.xGoogHeaders = []string{ |
| 198 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 199 |
} |
| 200 |
} |
| 201 |
|
| 202 |
// Close closes the connection to the API service. The user should invoke this when |
| 203 |
// the client is no longer required. |
| 204 |
func (c *phishingProtectionServiceV1Beta1GRPCClient) Close() error { |
| 205 |
return c.connPool.Close() |
| 206 |
} |
| 207 |
|
| 208 |
// Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls. |
| 209 |
type phishingProtectionServiceV1Beta1RESTClient struct { |
| 210 |
// The http endpoint to connect to. |
| 211 |
endpoint string |
| 212 |
|
| 213 |
// The http client. |
| 214 |
httpClient *http.Client |
| 215 |
|
| 216 |
// The x-goog-* headers to be sent with each request. |
| 217 |
xGoogHeaders []string |
| 218 |
|
| 219 |
// Points back to the CallOptions field of the containing PhishingProtectionServiceV1Beta1Client |
| 220 |
CallOptions **PhishingProtectionServiceV1Beta1CallOptions |
| 221 |
|
| 222 |
logger *slog.Logger |
| 223 |
} |
| 224 |
|
| 225 |
// NewPhishingProtectionServiceV1Beta1RESTClient creates a new phishing protection service v1 beta1 rest client. |
| 226 |
// |
| 227 |
// Service to report phishing URIs. |
| 228 |
func NewPhishingProtectionServiceV1Beta1RESTClient(ctx context.Context, opts ...option.ClientOption) (*PhishingProtectionServiceV1Beta1Client, error) { |
| 229 |
clientOpts := append(defaultPhishingProtectionServiceV1Beta1RESTClientOptions(), opts...) |
| 230 |
httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...) |
| 231 |
if err != nil { |
| 232 |
return nil, err |
| 233 |
} |
| 234 |
|
| 235 |
callOpts := defaultPhishingProtectionServiceV1Beta1RESTCallOptions() |
| 236 |
c := &phishingProtectionServiceV1Beta1RESTClient{ |
| 237 |
endpoint: endpoint, |
| 238 |
httpClient: httpClient, |
| 239 |
CallOptions: &callOpts, |
| 240 |
logger: internaloption.GetLogger(opts), |
| 241 |
} |
| 242 |
c.setGoogleClientInfo() |
| 243 |
|
| 244 |
return &PhishingProtectionServiceV1Beta1Client{internalClient: c, CallOptions: callOpts}, nil |
| 245 |
} |
| 246 |
|
| 247 |
func defaultPhishingProtectionServiceV1Beta1RESTClientOptions() []option.ClientOption { |
| 248 |
return []option.ClientOption{ |
| 249 |
internaloption.WithDefaultEndpoint("https://phishingprotection.googleapis.com"), |
| 250 |
internaloption.WithDefaultEndpointTemplate("https://phishingprotection.UNIVERSE_DOMAIN"), |
| 251 |
internaloption.WithDefaultMTLSEndpoint("https://phishingprotection.mtls.googleapis.com"), |
| 252 |
internaloption.WithDefaultUniverseDomain("googleapis.com"), |
| 253 |
internaloption.WithDefaultAudience("https://phishingprotection.googleapis.com/"), |
| 254 |
internaloption.WithDefaultScopes(DefaultAuthScopes()...), |
| 255 |
internaloption.EnableNewAuthLibrary(), |
| 256 |
} |
| 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. |
| 262 |
func (c *phishingProtectionServiceV1Beta1RESTClient) setGoogleClientInfo(keyval ...string) { |
| 263 |
kv := append([]string{"gl-go", gax.GoVersion}, keyval...) |
| 264 |
kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion) |
| 265 |
c.xGoogHeaders = []string{ |
| 266 |
"x-goog-api-client", gax.XGoogHeader(kv...), |
| 267 |
} |
| 268 |
} |
| 269 |
|
| 270 |
// Close closes the connection to the API service. The user should invoke this when |
| 271 |
// the client is no longer required. |
| 272 |
func (c *phishingProtectionServiceV1Beta1RESTClient) Close() error { |
| 273 |
// Replace httpClient with nil to force cleanup. |
| 274 |
c.httpClient = nil |
| 275 |
return nil |
| 276 |
} |
| 277 |
|
| 278 |
// Connection returns a connection to the API service. |
| 279 |
// |
| 280 |
// Deprecated: This method always returns nil. |
| 281 |
func (c *phishingProtectionServiceV1Beta1RESTClient) Connection() *grpc.ClientConn { |
| 282 |
return nil |
| 283 |
} |
| 284 |
func (c *phishingProtectionServiceV1Beta1GRPCClient) ReportPhishing(ctx context.Context, req *phishingprotectionpb.ReportPhishingRequest, opts ...gax.CallOption) (*phishingprotectionpb.ReportPhishingResponse, error) { |
| 285 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 286 |
|
| 287 |
hds = append(c.xGoogHeaders, hds...) |
| 288 |
ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...) |
| 289 |
opts = append((*c.CallOptions).ReportPhishing[0:len((*c.CallOptions).ReportPhishing):len((*c.CallOptions).ReportPhishing)], opts...) |
| 290 |
var resp *phishingprotectionpb.ReportPhishingResponse |
| 291 |
err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 292 |
var err error |
| 293 |
resp, err = executeRPC(ctx, c.phishingProtectionServiceV1Beta1Client.ReportPhishing, req, settings.GRPC, c.logger, "ReportPhishing") |
| 294 |
return err |
| 295 |
}, opts...) |
| 296 |
if err != nil { |
| 297 |
return nil, err |
| 298 |
} |
| 299 |
return resp, nil |
| 300 |
} |
| 301 |
|
| 302 |
// ReportPhishing reports a URI suspected of containing phishing content to be reviewed. Once |
| 303 |
// the report review is complete, its result can be found in the Cloud |
| 304 |
// Security Command Center findings dashboard for Phishing Protection. If the |
| 305 |
// result verifies the existence of malicious phishing content, the site will |
| 306 |
// be added the to Google’s Social Engineering |
| 307 |
// lists (at https://support.google.com/webmasters/answer/6350487/) in order to |
| 308 |
// protect users that could get exposed to this threat in the future. |
| 309 |
func (c *phishingProtectionServiceV1Beta1RESTClient) ReportPhishing(ctx context.Context, req *phishingprotectionpb.ReportPhishingRequest, opts ...gax.CallOption) (*phishingprotectionpb.ReportPhishingResponse, error) { |
| 310 |
m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true} |
| 311 |
jsonReq, err := m.Marshal(req) |
| 312 |
if err != nil { |
| 313 |
return nil, err |
| 314 |
} |
| 315 |
|
| 316 |
baseUrl, err := url.Parse(c.endpoint) |
| 317 |
if err != nil { |
| 318 |
return nil, err |
| 319 |
} |
| 320 |
baseUrl.Path += fmt.Sprintf("/v1beta1/%v/phishing:report", req.GetParent()) |
| 321 |
|
| 322 |
params := url.Values{} |
| 323 |
params.Add("$alt", "json;enum-encoding=int") |
| 324 |
|
| 325 |
baseUrl.RawQuery = params.Encode() |
| 326 |
|
| 327 |
// Build HTTP headers from client and context metadata. |
| 328 |
hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "parent", url.QueryEscape(req.GetParent()))} |
| 329 |
|
| 330 |
hds = append(c.xGoogHeaders, hds...) |
| 331 |
hds = append(hds, "Content-Type", "application/json") |
| 332 |
headers := gax.BuildHeaders(ctx, hds...) |
| 333 |
opts = append((*c.CallOptions).ReportPhishing[0:len((*c.CallOptions).ReportPhishing):len((*c.CallOptions).ReportPhishing)], opts...) |
| 334 |
unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true} |
| 335 |
resp := &phishingprotectionpb.ReportPhishingResponse{} |
| 336 |
e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error { |
| 337 |
if settings.Path != "" { |
| 338 |
baseUrl.Path = settings.Path |
| 339 |
} |
| 340 |
httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq)) |
| 341 |
if err != nil { |
| 342 |
return err |
| 343 |
} |
| 344 |
httpReq = httpReq.WithContext(ctx) |
| 345 |
httpReq.Header = headers |
| 346 |
|
| 347 |
buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ReportPhishing") |
| 348 |
if err != nil { |
| 349 |
return err |
| 350 |
} |
| 351 |
|
| 352 |
if err := unm.Unmarshal(buf, resp); err != nil { |
| 353 |
return err |
| 354 |
} |
| 355 |
|
| 356 |
return nil |
| 357 |
}, opts...) |
| 358 |
if e != nil { |
| 359 |
return nil, e |
| 360 |
} |
| 361 |
return resp, nil |
| 362 |
} |