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