google_cloud_websecurityscanner_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::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Web Security Scanner API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// parent: &str,
29/// ) -> anyhow::Result<()> {
30/// let client = WebSecurityScanner::builder().build().await?;
31/// let mut list = client.list_findings()
32/// .set_parent(parent)
33/// .by_item();
34/// while let Some(item) = list.next().await.transpose()? {
35/// println!("{:?}", item);
36/// }
37/// Ok(())
38/// }
39/// ```
40///
41/// # Service Description
42///
43/// Web Security Scanner Service identifies security vulnerabilities in web
44/// applications hosted on Google Cloud. It crawls your application, and
45/// attempts to exercise as many user inputs and event handlers as possible.
46///
47/// # Configuration
48///
49/// To configure `WebSecurityScanner` use the `with_*` methods in the type returned
50/// by [builder()][WebSecurityScanner::builder]. The default configuration should
51/// work for most applications. Common configuration changes include
52///
53/// * [with_endpoint()]: by default this client uses the global default endpoint
54/// (`https://websecurityscanner.googleapis.com`). Applications using regional
55/// endpoints or running in restricted networks (e.g. a network configured
56/// with [Private Google Access with VPC Service Controls]) may want to
57/// override this default.
58/// * [with_credentials()]: by default this client uses
59/// [Application Default Credentials]. Applications using custom
60/// authentication may need to override this default.
61///
62/// [with_endpoint()]: super::builder::web_security_scanner::ClientBuilder::with_endpoint
63/// [with_credentials()]: super::builder::web_security_scanner::ClientBuilder::with_credentials
64/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
65/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
66///
67/// # Pooling and Cloning
68///
69/// `WebSecurityScanner` holds a connection pool internally, it is advised to
70/// create one and reuse it. You do not need to wrap `WebSecurityScanner` in
71/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
72/// already uses an `Arc` internally.
73#[derive(Clone, Debug)]
74pub struct WebSecurityScanner {
75 inner: std::sync::Arc<dyn super::stub::dynamic::WebSecurityScanner>,
76}
77
78impl WebSecurityScanner {
79 /// Returns a builder for [WebSecurityScanner].
80 ///
81 /// ```
82 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
83 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
84 /// let client = WebSecurityScanner::builder().build().await?;
85 /// # Ok(()) }
86 /// ```
87 pub fn builder() -> super::builder::web_security_scanner::ClientBuilder {
88 crate::new_client_builder(super::builder::web_security_scanner::client::Factory)
89 }
90
91 /// Creates a new client from the provided stub.
92 ///
93 /// The most common case for calling this function is in tests mocking the
94 /// client's behavior.
95 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
96 where
97 T: super::stub::WebSecurityScanner + 'static,
98 {
99 Self { inner: stub.into() }
100 }
101
102 pub(crate) async fn new(
103 config: gaxi::options::ClientConfig,
104 ) -> crate::ClientBuilderResult<Self> {
105 let inner = Self::build_inner(config).await?;
106 Ok(Self { inner })
107 }
108
109 async fn build_inner(
110 conf: gaxi::options::ClientConfig,
111 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::WebSecurityScanner>>
112 {
113 if gaxi::options::tracing_enabled(&conf) {
114 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
115 }
116 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
117 }
118
119 async fn build_transport(
120 conf: gaxi::options::ClientConfig,
121 ) -> crate::ClientBuilderResult<impl super::stub::WebSecurityScanner> {
122 super::transport::WebSecurityScanner::new(conf).await
123 }
124
125 async fn build_with_tracing(
126 conf: gaxi::options::ClientConfig,
127 ) -> crate::ClientBuilderResult<impl super::stub::WebSecurityScanner> {
128 Self::build_transport(conf)
129 .await
130 .map(super::tracing::WebSecurityScanner::new)
131 }
132
133 /// Creates a new ScanConfig.
134 ///
135 /// # Example
136 /// ```
137 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
138 /// use google_cloud_websecurityscanner_v1::Result;
139 /// async fn sample(
140 /// client: &WebSecurityScanner
141 /// ) -> Result<()> {
142 /// let response = client.create_scan_config()
143 /// /* set fields */
144 /// .send().await?;
145 /// println!("response {:?}", response);
146 /// Ok(())
147 /// }
148 /// ```
149 pub fn create_scan_config(&self) -> super::builder::web_security_scanner::CreateScanConfig {
150 super::builder::web_security_scanner::CreateScanConfig::new(self.inner.clone())
151 }
152
153 /// Deletes an existing ScanConfig and its child resources.
154 ///
155 /// # Example
156 /// ```
157 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
158 /// use google_cloud_websecurityscanner_v1::Result;
159 /// async fn sample(
160 /// client: &WebSecurityScanner
161 /// ) -> Result<()> {
162 /// client.delete_scan_config()
163 /// /* set fields */
164 /// .send().await?;
165 /// Ok(())
166 /// }
167 /// ```
168 pub fn delete_scan_config(&self) -> super::builder::web_security_scanner::DeleteScanConfig {
169 super::builder::web_security_scanner::DeleteScanConfig::new(self.inner.clone())
170 }
171
172 /// Gets a ScanConfig.
173 ///
174 /// # Example
175 /// ```
176 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
177 /// use google_cloud_websecurityscanner_v1::Result;
178 /// async fn sample(
179 /// client: &WebSecurityScanner
180 /// ) -> Result<()> {
181 /// let response = client.get_scan_config()
182 /// /* set fields */
183 /// .send().await?;
184 /// println!("response {:?}", response);
185 /// Ok(())
186 /// }
187 /// ```
188 pub fn get_scan_config(&self) -> super::builder::web_security_scanner::GetScanConfig {
189 super::builder::web_security_scanner::GetScanConfig::new(self.inner.clone())
190 }
191
192 /// Lists ScanConfigs under a given project.
193 ///
194 /// # Example
195 /// ```
196 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
197 /// use google_cloud_gax::paginator::ItemPaginator as _;
198 /// use google_cloud_websecurityscanner_v1::Result;
199 /// async fn sample(
200 /// client: &WebSecurityScanner
201 /// ) -> Result<()> {
202 /// let mut list = client.list_scan_configs()
203 /// /* set fields */
204 /// .by_item();
205 /// while let Some(item) = list.next().await.transpose()? {
206 /// println!("{:?}", item);
207 /// }
208 /// Ok(())
209 /// }
210 /// ```
211 pub fn list_scan_configs(&self) -> super::builder::web_security_scanner::ListScanConfigs {
212 super::builder::web_security_scanner::ListScanConfigs::new(self.inner.clone())
213 }
214
215 /// Updates a ScanConfig. This method support partial update of a ScanConfig.
216 ///
217 /// # Example
218 /// ```
219 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
220 /// use google_cloud_websecurityscanner_v1::Result;
221 /// async fn sample(
222 /// client: &WebSecurityScanner
223 /// ) -> Result<()> {
224 /// let response = client.update_scan_config()
225 /// /* set fields */
226 /// .send().await?;
227 /// println!("response {:?}", response);
228 /// Ok(())
229 /// }
230 /// ```
231 pub fn update_scan_config(&self) -> super::builder::web_security_scanner::UpdateScanConfig {
232 super::builder::web_security_scanner::UpdateScanConfig::new(self.inner.clone())
233 }
234
235 /// Start a ScanRun according to the given ScanConfig.
236 ///
237 /// # Example
238 /// ```
239 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
240 /// use google_cloud_websecurityscanner_v1::Result;
241 /// async fn sample(
242 /// client: &WebSecurityScanner
243 /// ) -> Result<()> {
244 /// let response = client.start_scan_run()
245 /// /* set fields */
246 /// .send().await?;
247 /// println!("response {:?}", response);
248 /// Ok(())
249 /// }
250 /// ```
251 pub fn start_scan_run(&self) -> super::builder::web_security_scanner::StartScanRun {
252 super::builder::web_security_scanner::StartScanRun::new(self.inner.clone())
253 }
254
255 /// Gets a ScanRun.
256 ///
257 /// # Example
258 /// ```
259 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
260 /// use google_cloud_websecurityscanner_v1::Result;
261 /// async fn sample(
262 /// client: &WebSecurityScanner
263 /// ) -> Result<()> {
264 /// let response = client.get_scan_run()
265 /// /* set fields */
266 /// .send().await?;
267 /// println!("response {:?}", response);
268 /// Ok(())
269 /// }
270 /// ```
271 pub fn get_scan_run(&self) -> super::builder::web_security_scanner::GetScanRun {
272 super::builder::web_security_scanner::GetScanRun::new(self.inner.clone())
273 }
274
275 /// Lists ScanRuns under a given ScanConfig, in descending order of ScanRun
276 /// stop time.
277 ///
278 /// # Example
279 /// ```
280 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
281 /// use google_cloud_gax::paginator::ItemPaginator as _;
282 /// use google_cloud_websecurityscanner_v1::Result;
283 /// async fn sample(
284 /// client: &WebSecurityScanner
285 /// ) -> Result<()> {
286 /// let mut list = client.list_scan_runs()
287 /// /* set fields */
288 /// .by_item();
289 /// while let Some(item) = list.next().await.transpose()? {
290 /// println!("{:?}", item);
291 /// }
292 /// Ok(())
293 /// }
294 /// ```
295 pub fn list_scan_runs(&self) -> super::builder::web_security_scanner::ListScanRuns {
296 super::builder::web_security_scanner::ListScanRuns::new(self.inner.clone())
297 }
298
299 /// Stops a ScanRun. The stopped ScanRun is returned.
300 ///
301 /// # Example
302 /// ```
303 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
304 /// use google_cloud_websecurityscanner_v1::Result;
305 /// async fn sample(
306 /// client: &WebSecurityScanner
307 /// ) -> Result<()> {
308 /// let response = client.stop_scan_run()
309 /// /* set fields */
310 /// .send().await?;
311 /// println!("response {:?}", response);
312 /// Ok(())
313 /// }
314 /// ```
315 pub fn stop_scan_run(&self) -> super::builder::web_security_scanner::StopScanRun {
316 super::builder::web_security_scanner::StopScanRun::new(self.inner.clone())
317 }
318
319 /// List CrawledUrls under a given ScanRun.
320 ///
321 /// # Example
322 /// ```
323 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
324 /// use google_cloud_gax::paginator::ItemPaginator as _;
325 /// use google_cloud_websecurityscanner_v1::Result;
326 /// async fn sample(
327 /// client: &WebSecurityScanner
328 /// ) -> Result<()> {
329 /// let mut list = client.list_crawled_urls()
330 /// /* set fields */
331 /// .by_item();
332 /// while let Some(item) = list.next().await.transpose()? {
333 /// println!("{:?}", item);
334 /// }
335 /// Ok(())
336 /// }
337 /// ```
338 pub fn list_crawled_urls(&self) -> super::builder::web_security_scanner::ListCrawledUrls {
339 super::builder::web_security_scanner::ListCrawledUrls::new(self.inner.clone())
340 }
341
342 /// Gets a Finding.
343 ///
344 /// # Example
345 /// ```
346 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
347 /// use google_cloud_websecurityscanner_v1::Result;
348 /// async fn sample(
349 /// client: &WebSecurityScanner
350 /// ) -> Result<()> {
351 /// let response = client.get_finding()
352 /// /* set fields */
353 /// .send().await?;
354 /// println!("response {:?}", response);
355 /// Ok(())
356 /// }
357 /// ```
358 pub fn get_finding(&self) -> super::builder::web_security_scanner::GetFinding {
359 super::builder::web_security_scanner::GetFinding::new(self.inner.clone())
360 }
361
362 /// List Findings under a given ScanRun.
363 ///
364 /// # Example
365 /// ```
366 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
367 /// use google_cloud_gax::paginator::ItemPaginator as _;
368 /// use google_cloud_websecurityscanner_v1::Result;
369 /// async fn sample(
370 /// client: &WebSecurityScanner, parent: &str
371 /// ) -> Result<()> {
372 /// let mut list = client.list_findings()
373 /// .set_parent(parent)
374 /// .by_item();
375 /// while let Some(item) = list.next().await.transpose()? {
376 /// println!("{:?}", item);
377 /// }
378 /// Ok(())
379 /// }
380 /// ```
381 pub fn list_findings(&self) -> super::builder::web_security_scanner::ListFindings {
382 super::builder::web_security_scanner::ListFindings::new(self.inner.clone())
383 }
384
385 /// List all FindingTypeStats under a given ScanRun.
386 ///
387 /// # Example
388 /// ```
389 /// # use google_cloud_websecurityscanner_v1::client::WebSecurityScanner;
390 /// use google_cloud_websecurityscanner_v1::Result;
391 /// async fn sample(
392 /// client: &WebSecurityScanner
393 /// ) -> Result<()> {
394 /// let response = client.list_finding_type_stats()
395 /// /* set fields */
396 /// .send().await?;
397 /// println!("response {:?}", response);
398 /// Ok(())
399 /// }
400 /// ```
401 pub fn list_finding_type_stats(
402 &self,
403 ) -> super::builder::web_security_scanner::ListFindingTypeStats {
404 super::builder::web_security_scanner::ListFindingTypeStats::new(self.inner.clone())
405 }
406}