Skip to main content

google_cloud_maintenance_api_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 Maintenance API.
20///
21/// # Example
22/// ```
23/// # use google_cloud_maintenance_api_v1::client::Maintenance;
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 = Maintenance::builder().build().await?;
30///     let mut list = client.list_resource_maintenances()
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/// Unified Maintenance service
43///
44/// # Configuration
45///
46/// To configure `Maintenance` use the `with_*` methods in the type returned
47/// by [builder()][Maintenance::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://maintenance.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::maintenance::ClientBuilder::with_endpoint
60/// [with_credentials()]: super::builder::maintenance::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/// `Maintenance` holds a connection pool internally, it is advised to
67/// create one and reuse it. You do not need to wrap `Maintenance` 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 Maintenance {
72    inner: std::sync::Arc<dyn super::stub::dynamic::Maintenance>,
73}
74
75impl Maintenance {
76    /// Returns a builder for [Maintenance].
77    ///
78    /// ```
79    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
80    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
81    /// let client = Maintenance::builder().build().await?;
82    /// # Ok(()) }
83    /// ```
84    pub fn builder() -> super::builder::maintenance::ClientBuilder {
85        crate::new_client_builder(super::builder::maintenance::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::Maintenance + '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::Maintenance>> {
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::Maintenance> {
118        super::transport::Maintenance::new(conf).await
119    }
120
121    async fn build_with_tracing(
122        conf: gaxi::options::ClientConfig,
123    ) -> crate::ClientBuilderResult<impl super::stub::Maintenance> {
124        Self::build_transport(conf)
125            .await
126            .map(super::tracing::Maintenance::new)
127    }
128
129    /// Retrieves the statistics of a specific maintenance.
130    ///
131    /// # Example
132    /// ```
133    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
134    /// use google_cloud_gax::paginator::ItemPaginator as _;
135    /// use google_cloud_maintenance_api_v1::Result;
136    /// async fn sample(
137    ///    client: &Maintenance
138    /// ) -> Result<()> {
139    ///     let mut list = client.summarize_maintenances()
140    ///         /* set fields */
141    ///         .by_item();
142    ///     while let Some(item) = list.next().await.transpose()? {
143    ///         println!("{:?}", item);
144    ///     }
145    ///     Ok(())
146    /// }
147    /// ```
148    pub fn summarize_maintenances(&self) -> super::builder::maintenance::SummarizeMaintenances {
149        super::builder::maintenance::SummarizeMaintenances::new(self.inner.clone())
150    }
151
152    /// Retrieve a collection of resource maintenances.
153    ///
154    /// # Example
155    /// ```
156    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
157    /// use google_cloud_gax::paginator::ItemPaginator as _;
158    /// use google_cloud_maintenance_api_v1::Result;
159    /// async fn sample(
160    ///    client: &Maintenance, project_id: &str, location_id: &str
161    /// ) -> Result<()> {
162    ///     let mut list = client.list_resource_maintenances()
163    ///         .set_parent(format!("projects/{project_id}/locations/{location_id}"))
164    ///         .by_item();
165    ///     while let Some(item) = list.next().await.transpose()? {
166    ///         println!("{:?}", item);
167    ///     }
168    ///     Ok(())
169    /// }
170    /// ```
171    pub fn list_resource_maintenances(
172        &self,
173    ) -> super::builder::maintenance::ListResourceMaintenances {
174        super::builder::maintenance::ListResourceMaintenances::new(self.inner.clone())
175    }
176
177    /// Retrieve a single resource maintenance.
178    ///
179    /// # Example
180    /// ```
181    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
182    /// use google_cloud_maintenance_api_v1::Result;
183    /// async fn sample(
184    ///    client: &Maintenance, project_id: &str, location_id: &str, resource_maintenance_id: &str
185    /// ) -> Result<()> {
186    ///     let response = client.get_resource_maintenance()
187    ///         .set_name(format!("projects/{project_id}/locations/{location_id}/resourceMaintenances/{resource_maintenance_id}"))
188    ///         .send().await?;
189    ///     println!("response {:?}", response);
190    ///     Ok(())
191    /// }
192    /// ```
193    pub fn get_resource_maintenance(&self) -> super::builder::maintenance::GetResourceMaintenance {
194        super::builder::maintenance::GetResourceMaintenance::new(self.inner.clone())
195    }
196
197    /// Lists information about the supported locations for this service.
198    ///
199    /// # Example
200    /// ```
201    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
202    /// use google_cloud_gax::paginator::ItemPaginator as _;
203    /// use google_cloud_maintenance_api_v1::Result;
204    /// async fn sample(
205    ///    client: &Maintenance
206    /// ) -> Result<()> {
207    ///     let mut list = client.list_locations()
208    ///         /* set fields */
209    ///         .by_item();
210    ///     while let Some(item) = list.next().await.transpose()? {
211    ///         println!("{:?}", item);
212    ///     }
213    ///     Ok(())
214    /// }
215    /// ```
216    pub fn list_locations(&self) -> super::builder::maintenance::ListLocations {
217        super::builder::maintenance::ListLocations::new(self.inner.clone())
218    }
219
220    /// Gets information about a location.
221    ///
222    /// # Example
223    /// ```
224    /// # use google_cloud_maintenance_api_v1::client::Maintenance;
225    /// use google_cloud_maintenance_api_v1::Result;
226    /// async fn sample(
227    ///    client: &Maintenance
228    /// ) -> Result<()> {
229    ///     let response = client.get_location()
230    ///         /* set fields */
231    ///         .send().await?;
232    ///     println!("response {:?}", response);
233    ///     Ok(())
234    /// }
235    /// ```
236    pub fn get_location(&self) -> super::builder::maintenance::GetLocation {
237        super::builder::maintenance::GetLocation::new(self.inner.clone())
238    }
239}