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