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