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