google_cloud_webrisk_v1/client.rs
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 sidekick. DO NOT EDIT.
16#![allow(rustdoc::redundant_explicit_links)]
17#![allow(rustdoc::broken_intra_doc_links)]
18
19/// Implements a client for the Web Risk API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_webrisk_v1::client::WebRiskService;
25/// let client = WebRiskService::builder().build().await?;
26/// // use `client` to make requests to the Web Risk API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// Web Risk API defines an interface to detect malicious URLs on your
33/// website and in client applications.
34///
35/// # Configuration
36///
37/// To configure `WebRiskService` use the `with_*` methods in the type returned
38/// by [builder()][WebRiskService::builder]. The default configuration should
39/// work for most applications. Common configuration changes include
40///
41/// * [with_endpoint()]: by default this client uses the global default endpoint
42/// (`https://webrisk.googleapis.com`). Applications using regional
43/// endpoints or running in restricted networks (e.g. a network configured
44// with [Private Google Access with VPC Service Controls]) may want to
45/// override this default.
46/// * [with_credentials()]: by default this client uses
47/// [Application Default Credentials]. Applications using custom
48/// authentication may need to override this default.
49///
50/// [with_endpoint()]: super::builder::web_risk_service::ClientBuilder::with_endpoint
51/// [with_credentials()]: super::builder::web_risk_service::ClientBuilder::credentials
52/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
53/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
54///
55/// # Pooling and Cloning
56///
57/// `WebRiskService` holds a connection pool internally, it is advised to
58/// create one and the reuse it. You do not need to wrap `WebRiskService` in
59/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
60/// already uses an `Arc` internally.
61#[derive(Clone, Debug)]
62pub struct WebRiskService {
63 inner: std::sync::Arc<dyn super::stub::dynamic::WebRiskService>,
64}
65
66impl WebRiskService {
67 /// Returns a builder for [WebRiskService].
68 ///
69 /// ```
70 /// # tokio_test::block_on(async {
71 /// # use google_cloud_webrisk_v1::client::WebRiskService;
72 /// let client = WebRiskService::builder().build().await?;
73 /// # gax::client_builder::Result::<()>::Ok(()) });
74 /// ```
75 pub fn builder() -> super::builder::web_risk_service::ClientBuilder {
76 gax::client_builder::internal::new_builder(
77 super::builder::web_risk_service::client::Factory,
78 )
79 }
80
81 /// Creates a new client from the provided stub.
82 ///
83 /// The most common case for calling this function is in tests mocking the
84 /// client's behavior.
85 pub fn from_stub<T>(stub: T) -> Self
86 where
87 T: super::stub::WebRiskService + 'static,
88 {
89 Self {
90 inner: std::sync::Arc::new(stub),
91 }
92 }
93
94 pub(crate) async fn new(
95 config: gaxi::options::ClientConfig,
96 ) -> gax::client_builder::Result<Self> {
97 let inner = Self::build_inner(config).await?;
98 Ok(Self { inner })
99 }
100
101 async fn build_inner(
102 conf: gaxi::options::ClientConfig,
103 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::WebRiskService>> {
104 if gaxi::options::tracing_enabled(&conf) {
105 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106 }
107 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108 }
109
110 async fn build_transport(
111 conf: gaxi::options::ClientConfig,
112 ) -> gax::client_builder::Result<impl super::stub::WebRiskService> {
113 super::transport::WebRiskService::new(conf).await
114 }
115
116 async fn build_with_tracing(
117 conf: gaxi::options::ClientConfig,
118 ) -> gax::client_builder::Result<impl super::stub::WebRiskService> {
119 Self::build_transport(conf)
120 .await
121 .map(super::tracing::WebRiskService::new)
122 }
123
124 /// Gets the most recent threat list diffs. These diffs should be applied to
125 /// a local database of hashes to keep it up-to-date. If the local database is
126 /// empty or excessively out-of-date, a complete snapshot of the database will
127 /// be returned. This Method only updates a single ThreatList at a time. To
128 /// update multiple ThreatList databases, this method needs to be called once
129 /// for each list.
130 pub fn compute_threat_list_diff(
131 &self,
132 ) -> super::builder::web_risk_service::ComputeThreatListDiff {
133 super::builder::web_risk_service::ComputeThreatListDiff::new(self.inner.clone())
134 }
135
136 /// This method is used to check whether a URI is on a given threatList.
137 /// Multiple threatLists may be searched in a single query.
138 /// The response will list all requested threatLists the URI was found to
139 /// match. If the URI is not found on any of the requested ThreatList an
140 /// empty response will be returned.
141 pub fn search_uris(&self) -> super::builder::web_risk_service::SearchUris {
142 super::builder::web_risk_service::SearchUris::new(self.inner.clone())
143 }
144
145 /// Gets the full hashes that match the requested hash prefix.
146 /// This is used after a hash prefix is looked up in a threatList
147 /// and there is a match. The client side threatList only holds partial hashes
148 /// so the client must query this method to determine if there is a full
149 /// hash match of a threat.
150 pub fn search_hashes(&self) -> super::builder::web_risk_service::SearchHashes {
151 super::builder::web_risk_service::SearchHashes::new(self.inner.clone())
152 }
153
154 /// Creates a Submission of a URI suspected of containing phishing content to
155 /// be reviewed. If the result verifies the existence of malicious phishing
156 /// content, the site will be added to the [Google's Social Engineering
157 /// lists](https://support.google.com/webmasters/answer/6350487/) in order to
158 /// protect users that could get exposed to this threat in the future. Only
159 /// allowlisted projects can use this method during Early Access. Please reach
160 /// out to Sales or your customer engineer to obtain access.
161 pub fn create_submission(&self) -> super::builder::web_risk_service::CreateSubmission {
162 super::builder::web_risk_service::CreateSubmission::new(self.inner.clone())
163 }
164
165 /// Submits a URI suspected of containing malicious content to be reviewed.
166 /// Returns a google.longrunning.Operation which, once the review is complete,
167 /// is updated with its result. You can use the [Pub/Sub API]
168 /// (<https://cloud.google.com/pubsub>) to receive notifications for the returned
169 /// Operation. If the result verifies the existence of malicious content, the
170 /// site will be added to the [Google's Social Engineering lists]
171 /// (<https://support.google.com/webmasters/answer/6350487/>) in order to
172 /// protect users that could get exposed to this threat in the future. Only
173 /// allowlisted projects can use this method during Early Access. Please reach
174 /// out to Sales or your customer engineer to obtain access.
175 ///
176 /// # Long running operations
177 ///
178 /// This method is used to start, and/or poll a [long-running Operation].
179 /// The [Working with long-running operations] chapter in the [user guide]
180 /// covers these operations in detail.
181 ///
182 /// [long-running operation]: https://google.aip.dev/151
183 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
184 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
185 pub fn submit_uri(&self) -> super::builder::web_risk_service::SubmitUri {
186 super::builder::web_risk_service::SubmitUri::new(self.inner.clone())
187 }
188
189 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
190 ///
191 /// [google.longrunning.Operations]: longrunning::client::Operations
192 pub fn list_operations(&self) -> super::builder::web_risk_service::ListOperations {
193 super::builder::web_risk_service::ListOperations::new(self.inner.clone())
194 }
195
196 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
197 ///
198 /// [google.longrunning.Operations]: longrunning::client::Operations
199 pub fn get_operation(&self) -> super::builder::web_risk_service::GetOperation {
200 super::builder::web_risk_service::GetOperation::new(self.inner.clone())
201 }
202
203 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
204 ///
205 /// [google.longrunning.Operations]: longrunning::client::Operations
206 pub fn delete_operation(&self) -> super::builder::web_risk_service::DeleteOperation {
207 super::builder::web_risk_service::DeleteOperation::new(self.inner.clone())
208 }
209
210 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
211 ///
212 /// [google.longrunning.Operations]: longrunning::client::Operations
213 pub fn cancel_operation(&self) -> super::builder::web_risk_service::CancelOperation {
214 super::builder::web_risk_service::CancelOperation::new(self.inner.clone())
215 }
216}