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