Skip to main content

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/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
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/// # 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    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
82    /// # use google_cloud_containeranalysis_v1::client::ContainerAnalysis;
83    /// let client = ContainerAnalysis::builder().build().await?;
84    /// # Ok(()) }
85    /// ```
86    pub fn builder() -> super::builder::container_analysis::ClientBuilder {
87        crate::new_client_builder(super::builder::container_analysis::client::Factory)
88    }
89
90    /// Creates a new client from the provided stub.
91    ///
92    /// The most common case for calling this function is in tests mocking the
93    /// client's behavior.
94    pub fn from_stub<T>(stub: T) -> Self
95    where
96        T: super::stub::ContainerAnalysis + 'static,
97    {
98        Self {
99            inner: std::sync::Arc::new(stub),
100        }
101    }
102
103    pub(crate) async fn new(
104        config: gaxi::options::ClientConfig,
105    ) -> crate::ClientBuilderResult<Self> {
106        let inner = Self::build_inner(config).await?;
107        Ok(Self { inner })
108    }
109
110    async fn build_inner(
111        conf: gaxi::options::ClientConfig,
112    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ContainerAnalysis>>
113    {
114        if gaxi::options::tracing_enabled(&conf) {
115            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
116        }
117        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
118    }
119
120    async fn build_transport(
121        conf: gaxi::options::ClientConfig,
122    ) -> crate::ClientBuilderResult<impl super::stub::ContainerAnalysis> {
123        super::transport::ContainerAnalysis::new(conf).await
124    }
125
126    async fn build_with_tracing(
127        conf: gaxi::options::ClientConfig,
128    ) -> crate::ClientBuilderResult<impl super::stub::ContainerAnalysis> {
129        Self::build_transport(conf)
130            .await
131            .map(super::tracing::ContainerAnalysis::new)
132    }
133
134    /// Sets the access control policy on the specified note or occurrence.
135    /// Requires `containeranalysis.notes.setIamPolicy` or
136    /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
137    /// a note or an occurrence, respectively.
138    ///
139    /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
140    /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
141    /// occurrences.
142    pub fn set_iam_policy(&self) -> super::builder::container_analysis::SetIamPolicy {
143        super::builder::container_analysis::SetIamPolicy::new(self.inner.clone())
144    }
145
146    /// Gets the access control policy for a note or an occurrence resource.
147    /// Requires `containeranalysis.notes.setIamPolicy` or
148    /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
149    /// a note or occurrence, respectively.
150    ///
151    /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
152    /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
153    /// occurrences.
154    pub fn get_iam_policy(&self) -> super::builder::container_analysis::GetIamPolicy {
155        super::builder::container_analysis::GetIamPolicy::new(self.inner.clone())
156    }
157
158    /// Returns the permissions that a caller has on the specified note or
159    /// occurrence. Requires list permission on the project (for example,
160    /// `containeranalysis.notes.list`).
161    ///
162    /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
163    /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
164    /// occurrences.
165    pub fn test_iam_permissions(&self) -> super::builder::container_analysis::TestIamPermissions {
166        super::builder::container_analysis::TestIamPermissions::new(self.inner.clone())
167    }
168
169    /// Gets a summary of the number and severity of occurrences.
170    pub fn get_vulnerability_occurrences_summary(
171        &self,
172    ) -> super::builder::container_analysis::GetVulnerabilityOccurrencesSummary {
173        super::builder::container_analysis::GetVulnerabilityOccurrencesSummary::new(
174            self.inner.clone(),
175        )
176    }
177
178    /// Generates an SBOM for the given resource.
179    pub fn export_sbom(&self) -> super::builder::container_analysis::ExportSBOM {
180        super::builder::container_analysis::ExportSBOM::new(self.inner.clone())
181    }
182}