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