google_cloud_memcache_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
19use crate::Result;
20use std::sync::Arc;
21
22/// Implements a client for the Cloud Memorystore for Memcached API.
23///
24/// # Example
25/// ```
26/// # tokio_test::block_on(async {
27/// # use google_cloud_memcache_v1::client::CloudMemcache;
28/// let client = CloudMemcache::builder().build().await?;
29/// // use `client` to make requests to the {Codec.APITitle}}.
30/// # gax::Result::<()>::Ok(()) });
31/// ```
32///
33/// # Service Description
34///
35/// Configures and manages Cloud Memorystore for Memcached instances.
36///
37/// The `memcache.googleapis.com` service implements the Google Cloud Memorystore
38/// for Memcached API and defines the following resource model for managing
39/// Memorystore Memcached (also called Memcached below) instances:
40///
41/// * The service works with a collection of cloud projects, named: `/projects/*`
42/// * Each project has a collection of available locations, named: `/locations/*`
43/// * Each location has a collection of Memcached instances, named:
44///   `/instances/*`
45/// * As such, Memcached instances are resources of the form:
46///   `/projects/{project_id}/locations/{location_id}/instances/{instance_id}`
47///
48/// Note that location_id must be a GCP `region`; for example:
49///
50/// * `projects/my-memcached-project/locations/us-central1/instances/my-memcached`
51///
52/// # Configuration
53///
54/// To configure `CloudMemcache` use the `with_*` methods in the type returned
55/// by [builder()][CloudMemcache::builder]. The default configuration should
56/// work for most applications. Common configuration changes include
57///
58/// * [with_endpoint()]: by default this client uses the global default endpoint
59///   (`https://memcache.googleapis.com`). Applications using regional
60///   endpoints or running in restricted networks (e.g. a network configured
61//    with [Private Google Access with VPC Service Controls]) may want to
62///   override this default.
63/// * [with_credentials()]: by default this client uses
64///   [Application Default Credentials]. Applications using custom
65///   authentication may need to override this default.
66///
67/// [with_endpoint()]: super::builder::cloud_memcache::ClientBuilder::with_endpoint
68/// [with_credentials()]: super::builder::cloud_memcache::ClientBuilder::credentials
69/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
70/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
71///
72/// # Pooling and Cloning
73///
74/// `CloudMemcache` holds a connection pool internally, it is advised to
75/// create one and the reuse it.  You do not need to wrap `CloudMemcache` in
76/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
77/// internally.
78#[derive(Clone, Debug)]
79pub struct CloudMemcache {
80    inner: Arc<dyn super::stub::dynamic::CloudMemcache>,
81}
82
83impl CloudMemcache {
84    /// Returns a builder for [CloudMemcache].
85    ///
86    /// ```
87    /// # tokio_test::block_on(async {
88    /// # use google_cloud_memcache_v1::client::CloudMemcache;
89    /// let client = CloudMemcache::builder().build().await?;
90    /// # gax::Result::<()>::Ok(()) });
91    /// ```
92    pub fn builder() -> super::builder::cloud_memcache::ClientBuilder {
93        gax::client_builder::internal::new_builder(super::builder::cloud_memcache::client::Factory)
94    }
95
96    /// Creates a new client from the provided stub.
97    ///
98    /// The most common case for calling this function is in tests mocking the
99    /// client's behavior.
100    pub fn from_stub<T>(stub: T) -> Self
101    where
102        T: super::stub::CloudMemcache + 'static,
103    {
104        Self {
105            inner: Arc::new(stub),
106        }
107    }
108
109    pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
110        let inner = Self::build_inner(config).await?;
111        Ok(Self { inner })
112    }
113
114    async fn build_inner(
115        conf: gaxi::options::ClientConfig,
116    ) -> Result<Arc<dyn super::stub::dynamic::CloudMemcache>> {
117        if gaxi::options::tracing_enabled(&conf) {
118            return Ok(Arc::new(Self::build_with_tracing(conf).await?));
119        }
120        Ok(Arc::new(Self::build_transport(conf).await?))
121    }
122
123    async fn build_transport(
124        conf: gaxi::options::ClientConfig,
125    ) -> Result<impl super::stub::CloudMemcache> {
126        super::transport::CloudMemcache::new(conf).await
127    }
128
129    async fn build_with_tracing(
130        conf: gaxi::options::ClientConfig,
131    ) -> Result<impl super::stub::CloudMemcache> {
132        Self::build_transport(conf)
133            .await
134            .map(super::tracing::CloudMemcache::new)
135    }
136
137    /// Lists Instances in a given location.
138    pub fn list_instances(
139        &self,
140        parent: impl Into<std::string::String>,
141    ) -> super::builder::cloud_memcache::ListInstances {
142        super::builder::cloud_memcache::ListInstances::new(self.inner.clone())
143            .set_parent(parent.into())
144    }
145
146    /// Gets details of a single Instance.
147    pub fn get_instance(
148        &self,
149        name: impl Into<std::string::String>,
150    ) -> super::builder::cloud_memcache::GetInstance {
151        super::builder::cloud_memcache::GetInstance::new(self.inner.clone()).set_name(name.into())
152    }
153
154    /// Creates a new Instance in a given location.
155    ///
156    /// # Long running operations
157    ///
158    /// This method is used to start, and/or poll a [long-running Operation].
159    /// The [Working with long-running operations] chapter in the [user guide]
160    /// covers these operations in detail.
161    ///
162    /// [long-running operation]: https://google.aip.dev/151
163    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
164    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
165    pub fn create_instance(
166        &self,
167        parent: impl Into<std::string::String>,
168    ) -> super::builder::cloud_memcache::CreateInstance {
169        super::builder::cloud_memcache::CreateInstance::new(self.inner.clone())
170            .set_parent(parent.into())
171    }
172
173    /// Updates an existing Instance in a given project and location.
174    ///
175    /// # Long running operations
176    ///
177    /// This method is used to start, and/or poll a [long-running Operation].
178    /// The [Working with long-running operations] chapter in the [user guide]
179    /// covers these operations in detail.
180    ///
181    /// [long-running operation]: https://google.aip.dev/151
182    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
183    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
184    pub fn update_instance(
185        &self,
186        instance: impl Into<crate::model::Instance>,
187    ) -> super::builder::cloud_memcache::UpdateInstance {
188        super::builder::cloud_memcache::UpdateInstance::new(self.inner.clone())
189            .set_instance(instance.into())
190    }
191
192    /// Updates the defined Memcached parameters for an existing instance.
193    /// This method only stages the parameters, it must be followed by
194    /// `ApplyParameters` to apply the parameters to nodes of the Memcached
195    /// instance.
196    ///
197    /// # Long running operations
198    ///
199    /// This method is used to start, and/or poll a [long-running Operation].
200    /// The [Working with long-running operations] chapter in the [user guide]
201    /// covers these operations in detail.
202    ///
203    /// [long-running operation]: https://google.aip.dev/151
204    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
205    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
206    pub fn update_parameters(
207        &self,
208        name: impl Into<std::string::String>,
209    ) -> super::builder::cloud_memcache::UpdateParameters {
210        super::builder::cloud_memcache::UpdateParameters::new(self.inner.clone())
211            .set_name(name.into())
212    }
213
214    /// Deletes a single Instance.
215    ///
216    /// # Long running operations
217    ///
218    /// This method is used to start, and/or poll a [long-running Operation].
219    /// The [Working with long-running operations] chapter in the [user guide]
220    /// covers these operations in detail.
221    ///
222    /// [long-running operation]: https://google.aip.dev/151
223    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
224    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
225    pub fn delete_instance(
226        &self,
227        name: impl Into<std::string::String>,
228    ) -> super::builder::cloud_memcache::DeleteInstance {
229        super::builder::cloud_memcache::DeleteInstance::new(self.inner.clone())
230            .set_name(name.into())
231    }
232
233    /// `ApplyParameters` restarts the set of specified nodes in order to update
234    /// them to the current set of parameters for the Memcached Instance.
235    ///
236    /// # Long running operations
237    ///
238    /// This method is used to start, and/or poll a [long-running Operation].
239    /// The [Working with long-running operations] chapter in the [user guide]
240    /// covers these operations in detail.
241    ///
242    /// [long-running operation]: https://google.aip.dev/151
243    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
244    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
245    pub fn apply_parameters(
246        &self,
247        name: impl Into<std::string::String>,
248    ) -> super::builder::cloud_memcache::ApplyParameters {
249        super::builder::cloud_memcache::ApplyParameters::new(self.inner.clone())
250            .set_name(name.into())
251    }
252
253    /// Reschedules upcoming maintenance event.
254    ///
255    /// # Long running operations
256    ///
257    /// This method is used to start, and/or poll a [long-running Operation].
258    /// The [Working with long-running operations] chapter in the [user guide]
259    /// covers these operations in detail.
260    ///
261    /// [long-running operation]: https://google.aip.dev/151
262    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
263    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
264    pub fn reschedule_maintenance(
265        &self,
266        instance: impl Into<std::string::String>,
267    ) -> super::builder::cloud_memcache::RescheduleMaintenance {
268        super::builder::cloud_memcache::RescheduleMaintenance::new(self.inner.clone())
269            .set_instance(instance.into())
270    }
271
272    /// Lists information about the supported locations for this service.
273    pub fn list_locations(
274        &self,
275        name: impl Into<std::string::String>,
276    ) -> super::builder::cloud_memcache::ListLocations {
277        super::builder::cloud_memcache::ListLocations::new(self.inner.clone()).set_name(name.into())
278    }
279
280    /// Gets information about a location.
281    pub fn get_location(
282        &self,
283        name: impl Into<std::string::String>,
284    ) -> super::builder::cloud_memcache::GetLocation {
285        super::builder::cloud_memcache::GetLocation::new(self.inner.clone()).set_name(name.into())
286    }
287
288    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
289    ///
290    /// [google.longrunning.Operations]: longrunning::client::Operations
291    pub fn list_operations(
292        &self,
293        name: impl Into<std::string::String>,
294    ) -> super::builder::cloud_memcache::ListOperations {
295        super::builder::cloud_memcache::ListOperations::new(self.inner.clone())
296            .set_name(name.into())
297    }
298
299    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
300    ///
301    /// [google.longrunning.Operations]: longrunning::client::Operations
302    pub fn get_operation(
303        &self,
304        name: impl Into<std::string::String>,
305    ) -> super::builder::cloud_memcache::GetOperation {
306        super::builder::cloud_memcache::GetOperation::new(self.inner.clone()).set_name(name.into())
307    }
308
309    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
310    ///
311    /// [google.longrunning.Operations]: longrunning::client::Operations
312    pub fn delete_operation(
313        &self,
314        name: impl Into<std::string::String>,
315    ) -> super::builder::cloud_memcache::DeleteOperation {
316        super::builder::cloud_memcache::DeleteOperation::new(self.inner.clone())
317            .set_name(name.into())
318    }
319
320    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
321    ///
322    /// [google.longrunning.Operations]: longrunning::client::Operations
323    pub fn cancel_operation(
324        &self,
325        name: impl Into<std::string::String>,
326    ) -> super::builder::cloud_memcache::CancelOperation {
327        super::builder::cloud_memcache::CancelOperation::new(self.inner.clone())
328            .set_name(name.into())
329    }
330}