google_cloud_api_cloudquotas_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 Cloud Quotas API.
20///
21/// # Example
22/// ```
23/// # tokio_test::block_on(async {
24/// # use google_cloud_api_cloudquotas_v1::client::CloudQuotas;
25/// let client = CloudQuotas::builder().build().await?;
26/// // use `client` to make requests to the Cloud Quotas API.
27/// # gax::client_builder::Result::<()>::Ok(()) });
28/// ```
29///
30/// # Service Description
31///
32/// The Cloud Quotas API is an infrastructure service for Google Cloud that lets
33/// service consumers list and manage their resource usage limits.
34///
35/// - List/Get the metadata and current status of the quotas for a service.
36/// - Create/Update quota preferencess that declare the preferred quota values.
37/// - Check the status of a quota preference request.
38/// - List/Get pending and historical quota preference.
39///
40/// # Configuration
41///
42/// To configure `CloudQuotas` use the `with_*` methods in the type returned
43/// by [builder()][CloudQuotas::builder]. The default configuration should
44/// work for most applications. Common configuration changes include
45///
46/// * [with_endpoint()]: by default this client uses the global default endpoint
47/// (`https://cloudquotas.googleapis.com`). Applications using regional
48/// endpoints or running in restricted networks (e.g. a network configured
49// with [Private Google Access with VPC Service Controls]) may want to
50/// override this default.
51/// * [with_credentials()]: by default this client uses
52/// [Application Default Credentials]. Applications using custom
53/// authentication may need to override this default.
54///
55/// [with_endpoint()]: super::builder::cloud_quotas::ClientBuilder::with_endpoint
56/// [with_credentials()]: super::builder::cloud_quotas::ClientBuilder::credentials
57/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
58/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
59///
60/// # Pooling and Cloning
61///
62/// `CloudQuotas` holds a connection pool internally, it is advised to
63/// create one and the reuse it. You do not need to wrap `CloudQuotas` in
64/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
65/// already uses an `Arc` internally.
66#[derive(Clone, Debug)]
67pub struct CloudQuotas {
68 inner: std::sync::Arc<dyn super::stub::dynamic::CloudQuotas>,
69}
70
71impl CloudQuotas {
72 /// Returns a builder for [CloudQuotas].
73 ///
74 /// ```
75 /// # tokio_test::block_on(async {
76 /// # use google_cloud_api_cloudquotas_v1::client::CloudQuotas;
77 /// let client = CloudQuotas::builder().build().await?;
78 /// # gax::client_builder::Result::<()>::Ok(()) });
79 /// ```
80 pub fn builder() -> super::builder::cloud_quotas::ClientBuilder {
81 gax::client_builder::internal::new_builder(super::builder::cloud_quotas::client::Factory)
82 }
83
84 /// Creates a new client from the provided stub.
85 ///
86 /// The most common case for calling this function is in tests mocking the
87 /// client's behavior.
88 pub fn from_stub<T>(stub: T) -> Self
89 where
90 T: super::stub::CloudQuotas + 'static,
91 {
92 Self {
93 inner: std::sync::Arc::new(stub),
94 }
95 }
96
97 pub(crate) async fn new(
98 config: gaxi::options::ClientConfig,
99 ) -> gax::client_builder::Result<Self> {
100 let inner = Self::build_inner(config).await?;
101 Ok(Self { inner })
102 }
103
104 async fn build_inner(
105 conf: gaxi::options::ClientConfig,
106 ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::CloudQuotas>> {
107 if gaxi::options::tracing_enabled(&conf) {
108 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
109 }
110 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
111 }
112
113 async fn build_transport(
114 conf: gaxi::options::ClientConfig,
115 ) -> gax::client_builder::Result<impl super::stub::CloudQuotas> {
116 super::transport::CloudQuotas::new(conf).await
117 }
118
119 async fn build_with_tracing(
120 conf: gaxi::options::ClientConfig,
121 ) -> gax::client_builder::Result<impl super::stub::CloudQuotas> {
122 Self::build_transport(conf)
123 .await
124 .map(super::tracing::CloudQuotas::new)
125 }
126
127 /// Lists QuotaInfos of all quotas for a given project, folder or organization.
128 pub fn list_quota_infos(&self) -> super::builder::cloud_quotas::ListQuotaInfos {
129 super::builder::cloud_quotas::ListQuotaInfos::new(self.inner.clone())
130 }
131
132 /// Retrieve the QuotaInfo of a quota for a project, folder or organization.
133 pub fn get_quota_info(&self) -> super::builder::cloud_quotas::GetQuotaInfo {
134 super::builder::cloud_quotas::GetQuotaInfo::new(self.inner.clone())
135 }
136
137 /// Lists QuotaPreferences in a given project, folder or organization.
138 pub fn list_quota_preferences(&self) -> super::builder::cloud_quotas::ListQuotaPreferences {
139 super::builder::cloud_quotas::ListQuotaPreferences::new(self.inner.clone())
140 }
141
142 /// Gets details of a single QuotaPreference.
143 pub fn get_quota_preference(&self) -> super::builder::cloud_quotas::GetQuotaPreference {
144 super::builder::cloud_quotas::GetQuotaPreference::new(self.inner.clone())
145 }
146
147 /// Creates a new QuotaPreference that declares the desired value for a quota.
148 pub fn create_quota_preference(&self) -> super::builder::cloud_quotas::CreateQuotaPreference {
149 super::builder::cloud_quotas::CreateQuotaPreference::new(self.inner.clone())
150 }
151
152 /// Updates the parameters of a single QuotaPreference. It can updates the
153 /// config in any states, not just the ones pending approval.
154 pub fn update_quota_preference(&self) -> super::builder::cloud_quotas::UpdateQuotaPreference {
155 super::builder::cloud_quotas::UpdateQuotaPreference::new(self.inner.clone())
156 }
157}