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;
20use std::sync::Arc;
21
22/// Implements a client for the Container Analysis API.
23///
24/// # Service Description
25///
26/// Retrieves analysis results of Cloud components such as Docker container
27/// images. The Container Analysis API is an implementation of the
28/// [Grafeas](https://grafeas.io) API.
29///
30/// Analysis results are stored as a series of occurrences. An `Occurrence`
31/// contains information about a specific analysis instance on a resource. An
32/// occurrence refers to a `Note`. A note contains details describing the
33/// analysis and is generally stored in a separate project, called a `Provider`.
34/// Multiple occurrences can refer to the same note.
35///
36/// For example, an SSL vulnerability could affect multiple images. In this case,
37/// there would be one note for the vulnerability and an occurrence for each
38/// image with the vulnerability referring to that note.
39///
40/// # Configuration
41///
42/// `ContainerAnalysis` has various configuration parameters, the defaults should
43/// work with most applications.
44///
45/// # Pooling and Cloning
46///
47/// `ContainerAnalysis` holds a connection pool internally, it is advised to
48/// create one and the reuse it.  You do not need to wrap `ContainerAnalysis` in
49/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
50/// internally.
51#[derive(Clone, Debug)]
52pub struct ContainerAnalysis {
53    inner: Arc<dyn crate::stubs::dynamic::ContainerAnalysis>,
54}
55
56impl ContainerAnalysis {
57    /// Creates a new client with the default configuration.
58    pub async fn new() -> Result<Self> {
59        Self::new_with_config(gax::options::ClientConfig::default()).await
60    }
61
62    /// Creates a new client with the specified configuration.
63    pub async fn new_with_config(conf: gax::options::ClientConfig) -> Result<Self> {
64        let inner = Self::build_inner(conf).await?;
65        Ok(Self { inner })
66    }
67
68    /// Creates a new client from the provided stub.
69    ///
70    /// The most common case for calling this function is when mocking the
71    /// client.
72    pub fn from_stub<T>(stub: T) -> Self
73    where
74        T: crate::stubs::ContainerAnalysis + 'static,
75    {
76        Self {
77            inner: Arc::new(stub),
78        }
79    }
80
81    async fn build_inner(
82        conf: gax::options::ClientConfig,
83    ) -> Result<Arc<dyn crate::stubs::dynamic::ContainerAnalysis>> {
84        if conf.tracing_enabled() {
85            return Ok(Arc::new(Self::build_with_tracing(conf).await?));
86        }
87        Ok(Arc::new(Self::build_transport(conf).await?))
88    }
89
90    async fn build_transport(
91        conf: gax::options::ClientConfig,
92    ) -> Result<impl crate::stubs::ContainerAnalysis> {
93        crate::transport::ContainerAnalysis::new(conf).await
94    }
95
96    async fn build_with_tracing(
97        conf: gax::options::ClientConfig,
98    ) -> Result<impl crate::stubs::ContainerAnalysis> {
99        Self::build_transport(conf)
100            .await
101            .map(crate::tracing::ContainerAnalysis::new)
102    }
103
104    /// Sets the access control policy on the specified note or occurrence.
105    /// Requires `containeranalysis.notes.setIamPolicy` or
106    /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
107    /// a note or an occurrence, respectively.
108    ///
109    /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
110    /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
111    /// occurrences.
112    pub fn set_iam_policy(
113        &self,
114        resource: impl Into<std::string::String>,
115    ) -> crate::builders::container_analysis::SetIamPolicy {
116        crate::builders::container_analysis::SetIamPolicy::new(self.inner.clone())
117            .set_resource(resource.into())
118    }
119
120    /// Gets the access control policy for a note or an occurrence resource.
121    /// Requires `containeranalysis.notes.setIamPolicy` or
122    /// `containeranalysis.occurrences.setIamPolicy` permission if the resource is
123    /// a note or occurrence, respectively.
124    ///
125    /// The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for
126    /// notes and `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for
127    /// occurrences.
128    pub fn get_iam_policy(
129        &self,
130        resource: impl Into<std::string::String>,
131    ) -> crate::builders::container_analysis::GetIamPolicy {
132        crate::builders::container_analysis::GetIamPolicy::new(self.inner.clone())
133            .set_resource(resource.into())
134    }
135
136    /// Returns the permissions that a caller has on the specified note or
137    /// occurrence. Requires list permission on the project (for example,
138    /// `containeranalysis.notes.list`).
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 test_iam_permissions(
144        &self,
145        resource: impl Into<std::string::String>,
146    ) -> crate::builders::container_analysis::TestIamPermissions {
147        crate::builders::container_analysis::TestIamPermissions::new(self.inner.clone())
148            .set_resource(resource.into())
149    }
150
151    /// Gets a summary of the number and severity of occurrences.
152    pub fn get_vulnerability_occurrences_summary(
153        &self,
154        parent: impl Into<std::string::String>,
155    ) -> crate::builders::container_analysis::GetVulnerabilityOccurrencesSummary {
156        crate::builders::container_analysis::GetVulnerabilityOccurrencesSummary::new(
157            self.inner.clone(),
158        )
159        .set_parent(parent.into())
160    }
161}