Skip to main content

google_cloud_modelarmor_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 Model Armor API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_modelarmor_v1::client::ModelArmor;
24/// use google_cloud_gax::paginator::ItemPaginator as _;
25/// # async fn sample() -> Result<(), Box<dyn std::error::Error>> {
26///     let client = ModelArmor::builder().build().await?;
27///     let parent = "parent_value";
28///     let mut list = client.list_templates()
29///         .set_parent(parent)
30///         .by_item();
31///     while let Some(item) = list.next().await.transpose()? {
32///         println!("{:?}", item);
33///     }
34/// # Ok(()) }
35/// ```
36///
37/// # Service Description
38///
39/// Service describing handlers for resources
40///
41/// # Configuration
42///
43/// To configure `ModelArmor` use the `with_*` methods in the type returned
44/// by [builder()][ModelArmor::builder]. The default configuration should
45/// work for most applications. Common configuration changes include
46///
47/// * [with_endpoint()]: by default this client uses the global default endpoint
48///   (`https://modelarmor.googleapis.com`). Applications using regional
49///   endpoints or running in restricted networks (e.g. a network configured
50//    with [Private Google Access with VPC Service Controls]) may want to
51///   override this default.
52/// * [with_credentials()]: by default this client uses
53///   [Application Default Credentials]. Applications using custom
54///   authentication may need to override this default.
55///
56/// [with_endpoint()]: super::builder::model_armor::ClientBuilder::with_endpoint
57/// [with_credentials()]: super::builder::model_armor::ClientBuilder::with_credentials
58/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
59/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
60///
61/// # Pooling and Cloning
62///
63/// `ModelArmor` holds a connection pool internally, it is advised to
64/// create one and reuse it. You do not need to wrap `ModelArmor` in
65/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
66/// already uses an `Arc` internally.
67#[derive(Clone, Debug)]
68pub struct ModelArmor {
69    inner: std::sync::Arc<dyn super::stub::dynamic::ModelArmor>,
70}
71
72impl ModelArmor {
73    /// Returns a builder for [ModelArmor].
74    ///
75    /// ```
76    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
77    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
78    /// let client = ModelArmor::builder().build().await?;
79    /// # Ok(()) }
80    /// ```
81    pub fn builder() -> super::builder::model_armor::ClientBuilder {
82        crate::new_client_builder(super::builder::model_armor::client::Factory)
83    }
84
85    /// Creates a new client from the provided stub.
86    ///
87    /// The most common case for calling this function is in tests mocking the
88    /// client's behavior.
89    pub fn from_stub<T>(stub: T) -> Self
90    where
91        T: super::stub::ModelArmor + 'static,
92    {
93        Self {
94            inner: std::sync::Arc::new(stub),
95        }
96    }
97
98    pub(crate) async fn new(
99        config: gaxi::options::ClientConfig,
100    ) -> crate::ClientBuilderResult<Self> {
101        let inner = Self::build_inner(config).await?;
102        Ok(Self { inner })
103    }
104
105    async fn build_inner(
106        conf: gaxi::options::ClientConfig,
107    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::ModelArmor>> {
108        if gaxi::options::tracing_enabled(&conf) {
109            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
110        }
111        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
112    }
113
114    async fn build_transport(
115        conf: gaxi::options::ClientConfig,
116    ) -> crate::ClientBuilderResult<impl super::stub::ModelArmor> {
117        super::transport::ModelArmor::new(conf).await
118    }
119
120    async fn build_with_tracing(
121        conf: gaxi::options::ClientConfig,
122    ) -> crate::ClientBuilderResult<impl super::stub::ModelArmor> {
123        Self::build_transport(conf)
124            .await
125            .map(super::tracing::ModelArmor::new)
126    }
127
128    /// Lists Templates in a given project and location.
129    ///
130    /// # Example
131    /// ```
132    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
133    /// use google_cloud_gax::paginator::ItemPaginator as _;
134    /// use google_cloud_modelarmor_v1::Result;
135    /// async fn sample(
136    ///    client: &ModelArmor, parent: &str
137    /// ) -> Result<()> {
138    ///     let mut list = client.list_templates()
139    ///         .set_parent(parent)
140    ///         .by_item();
141    ///     while let Some(item) = list.next().await.transpose()? {
142    ///         println!("{:?}", item);
143    ///     }
144    ///     Ok(())
145    /// }
146    /// ```
147    pub fn list_templates(&self) -> super::builder::model_armor::ListTemplates {
148        super::builder::model_armor::ListTemplates::new(self.inner.clone())
149    }
150
151    /// Gets details of a single Template.
152    ///
153    /// # Example
154    /// ```
155    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
156    /// use google_cloud_modelarmor_v1::Result;
157    /// async fn sample(
158    ///    client: &ModelArmor, name: &str
159    /// ) -> Result<()> {
160    ///     let response = client.get_template()
161    ///         .set_name(name)
162    ///         .send().await?;
163    ///     println!("response {:?}", response);
164    ///     Ok(())
165    /// }
166    /// ```
167    pub fn get_template(&self) -> super::builder::model_armor::GetTemplate {
168        super::builder::model_armor::GetTemplate::new(self.inner.clone())
169    }
170
171    /// Creates a new Template in a given project and location.
172    ///
173    /// # Example
174    /// ```
175    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
176    /// use google_cloud_modelarmor_v1::model::Template;
177    /// use google_cloud_modelarmor_v1::Result;
178    /// async fn sample(
179    ///    client: &ModelArmor, parent: &str
180    /// ) -> Result<()> {
181    ///     let response = client.create_template()
182    ///         .set_parent(parent)
183    ///         .set_template_id("template_id_value")
184    ///         .set_template(
185    ///             Template::new()/* set fields */
186    ///         )
187    ///         .send().await?;
188    ///     println!("response {:?}", response);
189    ///     Ok(())
190    /// }
191    /// ```
192    pub fn create_template(&self) -> super::builder::model_armor::CreateTemplate {
193        super::builder::model_armor::CreateTemplate::new(self.inner.clone())
194    }
195
196    /// Updates the parameters of a single Template.
197    ///
198    /// # Example
199    /// ```
200    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
201    /// # extern crate wkt as google_cloud_wkt;
202    /// use google_cloud_wkt::FieldMask;
203    /// use google_cloud_modelarmor_v1::model::Template;
204    /// use google_cloud_modelarmor_v1::Result;
205    /// async fn sample(
206    ///    client: &ModelArmor, name: &str
207    /// ) -> Result<()> {
208    ///     let response = client.update_template()
209    ///         .set_template(
210    ///             Template::new().set_name(name)/* set fields */
211    ///         )
212    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
213    ///         .send().await?;
214    ///     println!("response {:?}", response);
215    ///     Ok(())
216    /// }
217    /// ```
218    pub fn update_template(&self) -> super::builder::model_armor::UpdateTemplate {
219        super::builder::model_armor::UpdateTemplate::new(self.inner.clone())
220    }
221
222    /// Deletes a single Template.
223    ///
224    /// # Example
225    /// ```
226    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
227    /// use google_cloud_modelarmor_v1::Result;
228    /// async fn sample(
229    ///    client: &ModelArmor, name: &str
230    /// ) -> Result<()> {
231    ///     client.delete_template()
232    ///         .set_name(name)
233    ///         .send().await?;
234    ///     Ok(())
235    /// }
236    /// ```
237    pub fn delete_template(&self) -> super::builder::model_armor::DeleteTemplate {
238        super::builder::model_armor::DeleteTemplate::new(self.inner.clone())
239    }
240
241    /// Gets details of a single floor setting of a project
242    ///
243    /// # Example
244    /// ```
245    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
246    /// use google_cloud_modelarmor_v1::Result;
247    /// async fn sample(
248    ///    client: &ModelArmor, name: &str
249    /// ) -> Result<()> {
250    ///     let response = client.get_floor_setting()
251    ///         .set_name(name)
252    ///         .send().await?;
253    ///     println!("response {:?}", response);
254    ///     Ok(())
255    /// }
256    /// ```
257    pub fn get_floor_setting(&self) -> super::builder::model_armor::GetFloorSetting {
258        super::builder::model_armor::GetFloorSetting::new(self.inner.clone())
259    }
260
261    /// Updates the parameters of a single floor setting of a project
262    ///
263    /// # Example
264    /// ```
265    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
266    /// # extern crate wkt as google_cloud_wkt;
267    /// use google_cloud_wkt::FieldMask;
268    /// use google_cloud_modelarmor_v1::model::FloorSetting;
269    /// use google_cloud_modelarmor_v1::Result;
270    /// async fn sample(
271    ///    client: &ModelArmor, name: &str
272    /// ) -> Result<()> {
273    ///     let response = client.update_floor_setting()
274    ///         .set_floor_setting(
275    ///             FloorSetting::new().set_name(name)/* set fields */
276    ///         )
277    ///         .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
278    ///         .send().await?;
279    ///     println!("response {:?}", response);
280    ///     Ok(())
281    /// }
282    /// ```
283    pub fn update_floor_setting(&self) -> super::builder::model_armor::UpdateFloorSetting {
284        super::builder::model_armor::UpdateFloorSetting::new(self.inner.clone())
285    }
286
287    /// Sanitizes User Prompt.
288    ///
289    /// # Example
290    /// ```
291    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
292    /// use google_cloud_modelarmor_v1::Result;
293    /// async fn sample(
294    ///    client: &ModelArmor
295    /// ) -> Result<()> {
296    ///     let response = client.sanitize_user_prompt()
297    ///         /* set fields */
298    ///         .send().await?;
299    ///     println!("response {:?}", response);
300    ///     Ok(())
301    /// }
302    /// ```
303    pub fn sanitize_user_prompt(&self) -> super::builder::model_armor::SanitizeUserPrompt {
304        super::builder::model_armor::SanitizeUserPrompt::new(self.inner.clone())
305    }
306
307    /// Sanitizes Model Response.
308    ///
309    /// # Example
310    /// ```
311    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
312    /// use google_cloud_modelarmor_v1::Result;
313    /// async fn sample(
314    ///    client: &ModelArmor
315    /// ) -> Result<()> {
316    ///     let response = client.sanitize_model_response()
317    ///         /* set fields */
318    ///         .send().await?;
319    ///     println!("response {:?}", response);
320    ///     Ok(())
321    /// }
322    /// ```
323    pub fn sanitize_model_response(&self) -> super::builder::model_armor::SanitizeModelResponse {
324        super::builder::model_armor::SanitizeModelResponse::new(self.inner.clone())
325    }
326
327    /// Lists information about the supported locations for this service.
328    ///
329    /// # Example
330    /// ```
331    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
332    /// use google_cloud_gax::paginator::ItemPaginator as _;
333    /// use google_cloud_modelarmor_v1::Result;
334    /// async fn sample(
335    ///    client: &ModelArmor
336    /// ) -> Result<()> {
337    ///     let mut list = client.list_locations()
338    ///         /* set fields */
339    ///         .by_item();
340    ///     while let Some(item) = list.next().await.transpose()? {
341    ///         println!("{:?}", item);
342    ///     }
343    ///     Ok(())
344    /// }
345    /// ```
346    pub fn list_locations(&self) -> super::builder::model_armor::ListLocations {
347        super::builder::model_armor::ListLocations::new(self.inner.clone())
348    }
349
350    /// Gets information about a location.
351    ///
352    /// # Example
353    /// ```
354    /// # use google_cloud_modelarmor_v1::client::ModelArmor;
355    /// use google_cloud_modelarmor_v1::Result;
356    /// async fn sample(
357    ///    client: &ModelArmor
358    /// ) -> Result<()> {
359    ///     let response = client.get_location()
360    ///         /* set fields */
361    ///         .send().await?;
362    ///     println!("response {:?}", response);
363    ///     Ok(())
364    /// }
365    /// ```
366    pub fn get_location(&self) -> super::builder::model_armor::GetLocation {
367        super::builder::model_armor::GetLocation::new(self.inner.clone())
368    }
369}