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