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