google_cloud_securityposture_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 Security Posture API.
23///
24/// # Service Description
25///
26/// Service describing handlers for resources.
27///
28/// # Configuration
29///
30/// `SecurityPosture` has various configuration parameters, the defaults should
31/// work with most applications.
32///
33/// # Pooling and Cloning
34///
35/// `SecurityPosture` holds a connection pool internally, it is advised to
36/// create one and the reuse it.  You do not need to wrap `SecurityPosture` in
37/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
38/// internally.
39#[derive(Clone, Debug)]
40pub struct SecurityPosture {
41    inner: Arc<dyn crate::stubs::dynamic::SecurityPosture>,
42}
43
44impl SecurityPosture {
45    /// Creates a new client with the default configuration.
46    pub async fn new() -> Result<Self> {
47        Self::new_with_config(gax::options::ClientConfig::default()).await
48    }
49
50    /// Creates a new client with the specified configuration.
51    pub async fn new_with_config(conf: gax::options::ClientConfig) -> Result<Self> {
52        let inner = Self::build_inner(conf).await?;
53        Ok(Self { inner })
54    }
55
56    /// Creates a new client from the provided stub.
57    ///
58    /// The most common case for calling this function is when mocking the
59    /// client.
60    pub fn from_stub<T>(stub: T) -> Self
61    where
62        T: crate::stubs::SecurityPosture + 'static,
63    {
64        Self {
65            inner: Arc::new(stub),
66        }
67    }
68
69    async fn build_inner(
70        conf: gax::options::ClientConfig,
71    ) -> Result<Arc<dyn crate::stubs::dynamic::SecurityPosture>> {
72        if conf.tracing_enabled() {
73            return Ok(Arc::new(Self::build_with_tracing(conf).await?));
74        }
75        Ok(Arc::new(Self::build_transport(conf).await?))
76    }
77
78    async fn build_transport(
79        conf: gax::options::ClientConfig,
80    ) -> Result<impl crate::stubs::SecurityPosture> {
81        crate::transport::SecurityPosture::new(conf).await
82    }
83
84    async fn build_with_tracing(
85        conf: gax::options::ClientConfig,
86    ) -> Result<impl crate::stubs::SecurityPosture> {
87        Self::build_transport(conf)
88            .await
89            .map(crate::tracing::SecurityPosture::new)
90    }
91
92    /// (-- This option restricts the visibility of the API to only projects that
93    /// will
94    /// (-- be labeled as `PREVIEW` or `GOOGLE_INTERNAL` by the service.
95    /// (-- option (google.api.api_visibility).restriction =
96    /// "PREVIEW,GOOGLE_INTERNAL"; Postures Lists Postures in a given organization
97    /// and location. In case a posture has multiple revisions, the latest revision
98    /// as per UpdateTime will be returned.
99    pub fn list_postures(
100        &self,
101        parent: impl Into<std::string::String>,
102    ) -> crate::builders::security_posture::ListPostures {
103        crate::builders::security_posture::ListPostures::new(self.inner.clone())
104            .set_parent(parent.into())
105    }
106
107    /// Lists revisions of a Posture in a given organization and location.
108    pub fn list_posture_revisions(
109        &self,
110        name: impl Into<std::string::String>,
111    ) -> crate::builders::security_posture::ListPostureRevisions {
112        crate::builders::security_posture::ListPostureRevisions::new(self.inner.clone())
113            .set_name(name.into())
114    }
115
116    /// Gets a posture in a given organization and location.
117    /// User must provide revision_id to retrieve a specific revision of the
118    /// resource.
119    /// NOT_FOUND error is returned if the revision_id or the Posture name does not
120    /// exist. In case revision_id is not provided then the latest Posture revision
121    /// by UpdateTime is returned.
122    pub fn get_posture(
123        &self,
124        name: impl Into<std::string::String>,
125    ) -> crate::builders::security_posture::GetPosture {
126        crate::builders::security_posture::GetPosture::new(self.inner.clone()).set_name(name.into())
127    }
128
129    /// Creates a new Posture resource.
130    /// If a Posture with the specified name already exists in the specified
131    /// organization and location, the long running operation returns a
132    /// [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error.
133    ///
134    /// # Long running operations
135    ///
136    /// This method is used to start, and/or poll a [long-running Operation].
137    /// The [Working with long-running operations] chapter in the [user guide]
138    /// covers these operations in detail.
139    ///
140    /// [long-running operation]: https://google.aip.dev/151
141    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
142    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
143    pub fn create_posture(
144        &self,
145        parent: impl Into<std::string::String>,
146    ) -> crate::builders::security_posture::CreatePosture {
147        crate::builders::security_posture::CreatePosture::new(self.inner.clone())
148            .set_parent(parent.into())
149    }
150
151    /// Updates an existing Posture.
152    /// A new revision of the posture will be created if the revision to be
153    /// updated is currently deployed on a workload.
154    /// Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the
155    /// Posture does not exist.
156    /// Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag
157    /// supplied in the request does not match the persisted etag of the Posture.
158    /// Updatable fields are state, description and policy_sets.
159    /// State update operation cannot be clubbed with update of description and
160    /// policy_sets.
161    /// An ACTIVE posture can be updated to both DRAFT or DEPRECATED states.
162    /// Postures in DRAFT or DEPRECATED states can only be updated to ACTIVE state.
163    ///
164    /// # Long running operations
165    ///
166    /// This method is used to start, and/or poll a [long-running Operation].
167    /// The [Working with long-running operations] chapter in the [user guide]
168    /// covers these operations in detail.
169    ///
170    /// [long-running operation]: https://google.aip.dev/151
171    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
172    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
173    pub fn update_posture(
174        &self,
175        posture: impl Into<crate::model::Posture>,
176    ) -> crate::builders::security_posture::UpdatePosture {
177        crate::builders::security_posture::UpdatePosture::new(self.inner.clone())
178            .set_posture(posture.into())
179    }
180
181    /// Deletes all the revisions of a resource.
182    /// A posture can only be deleted when none of the revisions are deployed to
183    /// any workload.
184    ///
185    /// # Long running operations
186    ///
187    /// This method is used to start, and/or poll a [long-running Operation].
188    /// The [Working with long-running operations] chapter in the [user guide]
189    /// covers these operations in detail.
190    ///
191    /// [long-running operation]: https://google.aip.dev/151
192    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
193    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
194    pub fn delete_posture(
195        &self,
196        name: impl Into<std::string::String>,
197    ) -> crate::builders::security_posture::DeletePosture {
198        crate::builders::security_posture::DeletePosture::new(self.inner.clone())
199            .set_name(name.into())
200    }
201
202    /// Extracts existing policies on a workload as a posture.
203    /// If a Posture on the given workload already exists, the long running
204    /// operation returns a [ALREADY_EXISTS][google.rpc.Code.ALREADY_EXISTS] error.
205    ///
206    /// # Long running operations
207    ///
208    /// This method is used to start, and/or poll a [long-running Operation].
209    /// The [Working with long-running operations] chapter in the [user guide]
210    /// covers these operations in detail.
211    ///
212    /// [long-running operation]: https://google.aip.dev/151
213    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
214    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
215    pub fn extract_posture(
216        &self,
217        parent: impl Into<std::string::String>,
218    ) -> crate::builders::security_posture::ExtractPosture {
219        crate::builders::security_posture::ExtractPosture::new(self.inner.clone())
220            .set_parent(parent.into())
221    }
222
223    /// PostureDeployments
224    /// Lists PostureDeployments in a given project and location.
225    pub fn list_posture_deployments(
226        &self,
227        parent: impl Into<std::string::String>,
228    ) -> crate::builders::security_posture::ListPostureDeployments {
229        crate::builders::security_posture::ListPostureDeployments::new(self.inner.clone())
230            .set_parent(parent.into())
231    }
232
233    /// Gets details of a single PostureDeployment.
234    pub fn get_posture_deployment(
235        &self,
236        name: impl Into<std::string::String>,
237    ) -> crate::builders::security_posture::GetPostureDeployment {
238        crate::builders::security_posture::GetPostureDeployment::new(self.inner.clone())
239            .set_name(name.into())
240    }
241
242    /// Creates a new PostureDeployment in a given project and location.
243    ///
244    /// # Long running operations
245    ///
246    /// This method is used to start, and/or poll a [long-running Operation].
247    /// The [Working with long-running operations] chapter in the [user guide]
248    /// covers these operations in detail.
249    ///
250    /// [long-running operation]: https://google.aip.dev/151
251    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
252    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
253    pub fn create_posture_deployment(
254        &self,
255        parent: impl Into<std::string::String>,
256    ) -> crate::builders::security_posture::CreatePostureDeployment {
257        crate::builders::security_posture::CreatePostureDeployment::new(self.inner.clone())
258            .set_parent(parent.into())
259    }
260
261    /// Updates the parameters of a single PostureDeployment.
262    ///
263    /// # Long running operations
264    ///
265    /// This method is used to start, and/or poll a [long-running Operation].
266    /// The [Working with long-running operations] chapter in the [user guide]
267    /// covers these operations in detail.
268    ///
269    /// [long-running operation]: https://google.aip.dev/151
270    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
271    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
272    pub fn update_posture_deployment(
273        &self,
274        posture_deployment: impl Into<crate::model::PostureDeployment>,
275    ) -> crate::builders::security_posture::UpdatePostureDeployment {
276        crate::builders::security_posture::UpdatePostureDeployment::new(self.inner.clone())
277            .set_posture_deployment(posture_deployment.into())
278    }
279
280    /// Deletes a single PostureDeployment.
281    ///
282    /// # Long running operations
283    ///
284    /// This method is used to start, and/or poll a [long-running Operation].
285    /// The [Working with long-running operations] chapter in the [user guide]
286    /// covers these operations in detail.
287    ///
288    /// [long-running operation]: https://google.aip.dev/151
289    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
290    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
291    pub fn delete_posture_deployment(
292        &self,
293        name: impl Into<std::string::String>,
294    ) -> crate::builders::security_posture::DeletePostureDeployment {
295        crate::builders::security_posture::DeletePostureDeployment::new(self.inner.clone())
296            .set_name(name.into())
297    }
298
299    /// PostureTemplates
300    /// Lists all the PostureTemplates available to the user.
301    pub fn list_posture_templates(
302        &self,
303        parent: impl Into<std::string::String>,
304    ) -> crate::builders::security_posture::ListPostureTemplates {
305        crate::builders::security_posture::ListPostureTemplates::new(self.inner.clone())
306            .set_parent(parent.into())
307    }
308
309    /// Gets a PostureTemplate.
310    /// User must provide revision_id to retrieve a specific revision of the
311    /// resource.
312    /// NOT_FOUND error is returned if the revision_id or the PostureTemplate name
313    /// does not exist. In case revision_id is not provided then the
314    /// PostureTemplate with latest revision_id is returned.
315    pub fn get_posture_template(
316        &self,
317        name: impl Into<std::string::String>,
318    ) -> crate::builders::security_posture::GetPostureTemplate {
319        crate::builders::security_posture::GetPostureTemplate::new(self.inner.clone())
320            .set_name(name.into())
321    }
322
323    /// Lists information about the supported locations for this service.
324    pub fn list_locations(
325        &self,
326        name: impl Into<std::string::String>,
327    ) -> crate::builders::security_posture::ListLocations {
328        crate::builders::security_posture::ListLocations::new(self.inner.clone())
329            .set_name(name.into())
330    }
331
332    /// Gets information about a location.
333    pub fn get_location(
334        &self,
335        name: impl Into<std::string::String>,
336    ) -> crate::builders::security_posture::GetLocation {
337        crate::builders::security_posture::GetLocation::new(self.inner.clone())
338            .set_name(name.into())
339    }
340
341    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
342    ///
343    /// [google.longrunning.Operations]: longrunning::client::Operations
344    pub fn list_operations(
345        &self,
346        name: impl Into<std::string::String>,
347    ) -> crate::builders::security_posture::ListOperations {
348        crate::builders::security_posture::ListOperations::new(self.inner.clone())
349            .set_name(name.into())
350    }
351
352    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
353    ///
354    /// [google.longrunning.Operations]: longrunning::client::Operations
355    pub fn get_operation(
356        &self,
357        name: impl Into<std::string::String>,
358    ) -> crate::builders::security_posture::GetOperation {
359        crate::builders::security_posture::GetOperation::new(self.inner.clone())
360            .set_name(name.into())
361    }
362
363    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
364    ///
365    /// [google.longrunning.Operations]: longrunning::client::Operations
366    pub fn delete_operation(
367        &self,
368        name: impl Into<std::string::String>,
369    ) -> crate::builders::security_posture::DeleteOperation {
370        crate::builders::security_posture::DeleteOperation::new(self.inner.clone())
371            .set_name(name.into())
372    }
373
374    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
375    ///
376    /// [google.longrunning.Operations]: longrunning::client::Operations
377    pub fn cancel_operation(
378        &self,
379        name: impl Into<std::string::String>,
380    ) -> crate::builders::security_posture::CancelOperation {
381        crate::builders::security_posture::CancelOperation::new(self.inner.clone())
382            .set_name(name.into())
383    }
384}