google_cloud_containeranalysis_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 Container Analysis API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
26/// async fn sample(
27/// ) -> anyhow::Result<()> {
28/// let client = ContainerAnalysis::builder().build().await?;
29/// let response = client.set_iam_policy()
30/// /* set fields */
31/// .send().await?;
32/// println!("response {:?}", response);
33/// Ok(())
34/// }
35/// ```
36///
37/// # Service Description
38///
39/// Retrieves analysis results of Cloud components such as Docker container
40/// images. The Container Analysis API is an implementation of the
41/// [Grafeas](https://grafeas.io) API.
42///
43/// Analysis results are stored as a series of occurrences. An `Occurrence`
44/// contains information about a specific analysis instance on a resource. An
45/// occurrence refers to a `Note`. A note contains details describing the
46/// analysis and is generally stored in a separate project, called a `Provider`.
47/// Multiple occurrences can refer to the same note.
48///
49/// For example, an SSL vulnerability could affect multiple images. In this case,
50/// there would be one note for the vulnerability and an occurrence for each
51/// image with the vulnerability referring to that note.
52///
53/// # Configuration
54///
55/// To configure `ContainerAnalysis` use the `with_*` methods in the type returned
56/// by [builder()][ContainerAnalysis::builder]. The default configuration should
57/// work for most applications. Common configuration changes include
58///
59/// * [with_endpoint()]: by default this client uses the global default endpoint
60/// (`https://containeranalysis.googleapis.com`). Applications using regional
61/// endpoints or running in restricted networks (e.g. a network configured
62/// with [Private Google Access with VPC Service Controls]) may want to
63/// override this default.
64/// * [with_credentials()]: by default this client uses
65/// [Application Default Credentials]. Applications using custom
66/// authentication may need to override this default.
67///
68/// [with_endpoint()]: super::builder::container_analysis::ClientBuilder::with_endpoint
69/// [with_credentials()]: super::builder::container_analysis::ClientBuilder::with_credentials
70/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
71/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
72///
73/// # Pooling and Cloning
74///
75/// `ContainerAnalysis` holds a connection pool internally, it is advised to
76/// create one and reuse it. You do not need to wrap `ContainerAnalysis` in
77/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
78/// already uses an `Arc` internally.
79#[derive(Clone, Debug)]
80pub struct ContainerAnalysis {
81 inner: std::sync::Arc<dyn super::stub::dynamic::ContainerAnalysis>,
82}
83
84impl ContainerAnalysis {
85 /// Returns a builder for [ContainerAnalysis].
86 ///
87 /// ```
88 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
89 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
90 /// let client = ContainerAnalysis::builder().build().await?;
91 /// # Ok(()) }
92 /// ```
93 pub fn builder() -> super::builder::container_analysis::ClientBuilder {
94 crate::new_client_builder(super::builder::container_analysis::client::Factory)
95 }
96
97 /// Creates a new client from the provided stub.
98 ///
99 /// The most common case for calling this function is in tests mocking the
100 /// client's behavior.
101 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
102 where
103 T: super::stub::ContainerAnalysis + 'static,
104 {
105 Self { inner: stub.into() }
106 }
107
108 pub(crate) async fn new(
109 config: gaxi::options::ClientConfig,
110 ) -> crate::ClientBuilderResult<Self> {
111 let inner = Self::build_inner(config).await?;
112 Ok(Self { inner })
113 }
114
115 async fn build_inner(
116 conf: gaxi::options::ClientConfig,
117 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ContainerAnalysis>>
118 {
119 if gaxi::options::tracing_enabled(&conf) {
120 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
121 }
122 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
123 }
124
125 async fn build_transport(
126 conf: gaxi::options::ClientConfig,
127 ) -> crate::ClientBuilderResult<impl super::stub::ContainerAnalysis> {
128 super::transport::ContainerAnalysis::new(conf).await
129 }
130
131 async fn build_with_tracing(
132 conf: gaxi::options::ClientConfig,
133 ) -> crate::ClientBuilderResult<impl super::stub::ContainerAnalysis> {
134 Self::build_transport(conf)
135 .await
136 .map(super::tracing::ContainerAnalysis::new)
137 }
138
139 /// Sets the access control policy on the specified note or occurrence.
140 /// Requires `containeranalysis.notes.setIamPolicy` or
141 /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
142 /// a note or an occurrence, respectively.
143 ///
144 /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
145 /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
146 /// occurrences.
147 ///
148 /// # Example
149 /// ```
150 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
151 /// use google_cloud_containeranalysis_v1::Result;
152 /// async fn sample(
153 /// client: &ContainerAnalysis
154 /// ) -> Result<()> {
155 /// let response = client.set_iam_policy()
156 /// /* set fields */
157 /// .send().await?;
158 /// println!("response {:?}", response);
159 /// Ok(())
160 /// }
161 /// ```
162 pub fn set_iam_policy(&self) -> super::builder::container_analysis::SetIamPolicy {
163 super::builder::container_analysis::SetIamPolicy::new(self.inner.clone())
164 }
165
166 /// Gets the access control policy for a note or an occurrence resource.
167 /// Requires `containeranalysis.notes.setIamPolicy` or
168 /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
169 /// a note or occurrence, respectively.
170 ///
171 /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
172 /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
173 /// occurrences.
174 ///
175 /// # Example
176 /// ```
177 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
178 /// use google_cloud_containeranalysis_v1::Result;
179 /// async fn sample(
180 /// client: &ContainerAnalysis
181 /// ) -> Result<()> {
182 /// let response = client.get_iam_policy()
183 /// /* set fields */
184 /// .send().await?;
185 /// println!("response {:?}", response);
186 /// Ok(())
187 /// }
188 /// ```
189 pub fn get_iam_policy(&self) -> super::builder::container_analysis::GetIamPolicy {
190 super::builder::container_analysis::GetIamPolicy::new(self.inner.clone())
191 }
192
193 /// Returns the permissions that a caller has on the specified note or
194 /// occurrence. Requires list permission on the project (for example,
195 /// `containeranalysis.notes.list`).
196 ///
197 /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
198 /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
199 /// occurrences.
200 ///
201 /// # Example
202 /// ```
203 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
204 /// use google_cloud_containeranalysis_v1::Result;
205 /// async fn sample(
206 /// client: &ContainerAnalysis
207 /// ) -> Result<()> {
208 /// let response = client.test_iam_permissions()
209 /// /* set fields */
210 /// .send().await?;
211 /// println!("response {:?}", response);
212 /// Ok(())
213 /// }
214 /// ```
215 pub fn test_iam_permissions(&self) -> super::builder::container_analysis::TestIamPermissions {
216 super::builder::container_analysis::TestIamPermissions::new(self.inner.clone())
217 }
218
219 /// Gets a summary of the number and severity of occurrences.
220 ///
221 /// # Example
222 /// ```
223 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
224 /// use google_cloud_containeranalysis_v1::Result;
225 /// async fn sample(
226 /// client: &ContainerAnalysis
227 /// ) -> Result<()> {
228 /// let response = client.get_vulnerability_occurrences_summary()
229 /// /* set fields */
230 /// .send().await?;
231 /// println!("response {:?}", response);
232 /// Ok(())
233 /// }
234 /// ```
235 pub fn get_vulnerability_occurrences_summary(
236 &self,
237 ) -> super::builder::container_analysis::GetVulnerabilityOccurrencesSummary {
238 super::builder::container_analysis::GetVulnerabilityOccurrencesSummary::new(
239 self.inner.clone(),
240 )
241 }
242
243 /// Generates an SBOM for the given resource.
244 ///
245 /// # Example
246 /// ```
247 /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
248 /// use google_cloud_containeranalysis_v1::Result;
249 /// async fn sample(
250 /// client: &ContainerAnalysis
251 /// ) -> Result<()> {
252 /// let response = client.export_sbom()
253 /// /* set fields */
254 /// .send().await?;
255 /// println!("response {:?}", response);
256 /// Ok(())
257 /// }
258 /// ```
259 pub fn export_sbom(&self) -> super::builder::container_analysis::ExportSBOM {
260 super::builder::container_analysis::ExportSBOM::new(self.inner.clone())
261 }
262}