Skip to main content

google_cloud_notebooks_v2/
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 Notebooks API.
20///
21/// # Example
22/// ```
23/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
24/// # use google_cloud_notebooks_v2::client::NotebookService;
25/// let client = NotebookService::builder().build().await?;
26/// // use `client` to make requests to the Notebooks API.
27/// # Ok(()) }
28/// ```
29///
30/// # Service Description
31///
32/// API v2 service for Workbench Notebooks Instances.
33///
34/// # Configuration
35///
36/// To configure `NotebookService` use the `with_*` methods in the type returned
37/// by [builder()][NotebookService::builder]. The default configuration should
38/// work for most applications. Common configuration changes include
39///
40/// * [with_endpoint()]: by default this client uses the global default endpoint
41///   (`https://notebooks.googleapis.com`). Applications using regional
42///   endpoints or running in restricted networks (e.g. a network configured
43//    with [Private Google Access with VPC Service Controls]) may want to
44///   override this default.
45/// * [with_credentials()]: by default this client uses
46///   [Application Default Credentials]. Applications using custom
47///   authentication may need to override this default.
48///
49/// [with_endpoint()]: super::builder::notebook_service::ClientBuilder::with_endpoint
50/// [with_credentials()]: super::builder::notebook_service::ClientBuilder::credentials
51/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
52/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
53///
54/// # Pooling and Cloning
55///
56/// `NotebookService` holds a connection pool internally, it is advised to
57/// create one and the reuse it.  You do not need to wrap `NotebookService` in
58/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
59/// already uses an `Arc` internally.
60#[derive(Clone, Debug)]
61pub struct NotebookService {
62    inner: std::sync::Arc<dyn super::stub::dynamic::NotebookService>,
63}
64
65impl NotebookService {
66    /// Returns a builder for [NotebookService].
67    ///
68    /// ```
69    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
70    /// # use google_cloud_notebooks_v2::client::NotebookService;
71    /// let client = NotebookService::builder().build().await?;
72    /// # Ok(()) }
73    /// ```
74    pub fn builder() -> super::builder::notebook_service::ClientBuilder {
75        crate::new_client_builder(super::builder::notebook_service::client::Factory)
76    }
77
78    /// Creates a new client from the provided stub.
79    ///
80    /// The most common case for calling this function is in tests mocking the
81    /// client's behavior.
82    pub fn from_stub<T>(stub: T) -> Self
83    where
84        T: super::stub::NotebookService + 'static,
85    {
86        Self {
87            inner: std::sync::Arc::new(stub),
88        }
89    }
90
91    pub(crate) async fn new(
92        config: gaxi::options::ClientConfig,
93    ) -> crate::ClientBuilderResult<Self> {
94        let inner = Self::build_inner(config).await?;
95        Ok(Self { inner })
96    }
97
98    async fn build_inner(
99        conf: gaxi::options::ClientConfig,
100    ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::NotebookService>> {
101        if gaxi::options::tracing_enabled(&conf) {
102            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
103        }
104        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
105    }
106
107    async fn build_transport(
108        conf: gaxi::options::ClientConfig,
109    ) -> crate::ClientBuilderResult<impl super::stub::NotebookService> {
110        super::transport::NotebookService::new(conf).await
111    }
112
113    async fn build_with_tracing(
114        conf: gaxi::options::ClientConfig,
115    ) -> crate::ClientBuilderResult<impl super::stub::NotebookService> {
116        Self::build_transport(conf)
117            .await
118            .map(super::tracing::NotebookService::new)
119    }
120
121    /// Lists instances in a given project and location.
122    pub fn list_instances(&self) -> super::builder::notebook_service::ListInstances {
123        super::builder::notebook_service::ListInstances::new(self.inner.clone())
124    }
125
126    /// Gets details of a single Instance.
127    pub fn get_instance(&self) -> super::builder::notebook_service::GetInstance {
128        super::builder::notebook_service::GetInstance::new(self.inner.clone())
129    }
130
131    /// Creates a new Instance in a given project and location.
132    ///
133    /// # Long running operations
134    ///
135    /// This method is used to start, and/or poll a [long-running Operation].
136    /// The [Working with long-running operations] chapter in the [user guide]
137    /// covers these operations in detail.
138    ///
139    /// [long-running operation]: https://google.aip.dev/151
140    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
141    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
142    pub fn create_instance(&self) -> super::builder::notebook_service::CreateInstance {
143        super::builder::notebook_service::CreateInstance::new(self.inner.clone())
144    }
145
146    /// UpdateInstance updates an Instance.
147    ///
148    /// # Long running operations
149    ///
150    /// This method is used to start, and/or poll a [long-running Operation].
151    /// The [Working with long-running operations] chapter in the [user guide]
152    /// covers these operations in detail.
153    ///
154    /// [long-running operation]: https://google.aip.dev/151
155    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
156    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
157    pub fn update_instance(&self) -> super::builder::notebook_service::UpdateInstance {
158        super::builder::notebook_service::UpdateInstance::new(self.inner.clone())
159    }
160
161    /// Deletes a single Instance.
162    ///
163    /// # Long running operations
164    ///
165    /// This method is used to start, and/or poll a [long-running Operation].
166    /// The [Working with long-running operations] chapter in the [user guide]
167    /// covers these operations in detail.
168    ///
169    /// [long-running operation]: https://google.aip.dev/151
170    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
171    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
172    pub fn delete_instance(&self) -> super::builder::notebook_service::DeleteInstance {
173        super::builder::notebook_service::DeleteInstance::new(self.inner.clone())
174    }
175
176    /// Starts a notebook instance.
177    ///
178    /// # Long running operations
179    ///
180    /// This method is used to start, and/or poll a [long-running Operation].
181    /// The [Working with long-running operations] chapter in the [user guide]
182    /// covers these operations in detail.
183    ///
184    /// [long-running operation]: https://google.aip.dev/151
185    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
186    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
187    pub fn start_instance(&self) -> super::builder::notebook_service::StartInstance {
188        super::builder::notebook_service::StartInstance::new(self.inner.clone())
189    }
190
191    /// Stops a notebook instance.
192    ///
193    /// # Long running operations
194    ///
195    /// This method is used to start, and/or poll a [long-running Operation].
196    /// The [Working with long-running operations] chapter in the [user guide]
197    /// covers these operations in detail.
198    ///
199    /// [long-running operation]: https://google.aip.dev/151
200    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
201    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
202    pub fn stop_instance(&self) -> super::builder::notebook_service::StopInstance {
203        super::builder::notebook_service::StopInstance::new(self.inner.clone())
204    }
205
206    /// Resets a notebook instance.
207    ///
208    /// # Long running operations
209    ///
210    /// This method is used to start, and/or poll a [long-running Operation].
211    /// The [Working with long-running operations] chapter in the [user guide]
212    /// covers these operations in detail.
213    ///
214    /// [long-running operation]: https://google.aip.dev/151
215    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
216    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
217    pub fn reset_instance(&self) -> super::builder::notebook_service::ResetInstance {
218        super::builder::notebook_service::ResetInstance::new(self.inner.clone())
219    }
220
221    /// Checks whether a notebook instance is upgradable.
222    pub fn check_instance_upgradability(
223        &self,
224    ) -> super::builder::notebook_service::CheckInstanceUpgradability {
225        super::builder::notebook_service::CheckInstanceUpgradability::new(self.inner.clone())
226    }
227
228    /// Upgrades a notebook instance to the latest version.
229    ///
230    /// # Long running operations
231    ///
232    /// This method is used to start, and/or poll a [long-running Operation].
233    /// The [Working with long-running operations] chapter in the [user guide]
234    /// covers these operations in detail.
235    ///
236    /// [long-running operation]: https://google.aip.dev/151
237    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
238    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
239    pub fn upgrade_instance(&self) -> super::builder::notebook_service::UpgradeInstance {
240        super::builder::notebook_service::UpgradeInstance::new(self.inner.clone())
241    }
242
243    /// Rollbacks a notebook instance to the previous version.
244    ///
245    /// # Long running operations
246    ///
247    /// This method is used to start, and/or poll a [long-running Operation].
248    /// The [Working with long-running operations] chapter in the [user guide]
249    /// covers these operations in detail.
250    ///
251    /// [long-running operation]: https://google.aip.dev/151
252    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
253    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
254    pub fn rollback_instance(&self) -> super::builder::notebook_service::RollbackInstance {
255        super::builder::notebook_service::RollbackInstance::new(self.inner.clone())
256    }
257
258    /// Creates a Diagnostic File and runs Diagnostic Tool given an Instance.
259    ///
260    /// # Long running operations
261    ///
262    /// This method is used to start, and/or poll a [long-running Operation].
263    /// The [Working with long-running operations] chapter in the [user guide]
264    /// covers these operations in detail.
265    ///
266    /// [long-running operation]: https://google.aip.dev/151
267    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
268    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
269    pub fn diagnose_instance(&self) -> super::builder::notebook_service::DiagnoseInstance {
270        super::builder::notebook_service::DiagnoseInstance::new(self.inner.clone())
271    }
272
273    /// Lists information about the supported locations for this service.
274    pub fn list_locations(&self) -> super::builder::notebook_service::ListLocations {
275        super::builder::notebook_service::ListLocations::new(self.inner.clone())
276    }
277
278    /// Gets information about a location.
279    pub fn get_location(&self) -> super::builder::notebook_service::GetLocation {
280        super::builder::notebook_service::GetLocation::new(self.inner.clone())
281    }
282
283    /// Sets the access control policy on the specified resource. Replaces
284    /// any existing policy.
285    ///
286    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
287    /// errors.
288    pub fn set_iam_policy(&self) -> super::builder::notebook_service::SetIamPolicy {
289        super::builder::notebook_service::SetIamPolicy::new(self.inner.clone())
290    }
291
292    /// Gets the access control policy for a resource. Returns an empty policy
293    /// if the resource exists and does not have a policy set.
294    pub fn get_iam_policy(&self) -> super::builder::notebook_service::GetIamPolicy {
295        super::builder::notebook_service::GetIamPolicy::new(self.inner.clone())
296    }
297
298    /// Returns permissions that a caller has on the specified resource. If the
299    /// resource does not exist, this will return an empty set of
300    /// permissions, not a `NOT_FOUND` error.
301    ///
302    /// Note: This operation is designed to be used for building
303    /// permission-aware UIs and command-line tools, not for authorization
304    /// checking. This operation may "fail open" without warning.
305    pub fn test_iam_permissions(&self) -> super::builder::notebook_service::TestIamPermissions {
306        super::builder::notebook_service::TestIamPermissions::new(self.inner.clone())
307    }
308
309    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
310    ///
311    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
312    pub fn list_operations(&self) -> super::builder::notebook_service::ListOperations {
313        super::builder::notebook_service::ListOperations::new(self.inner.clone())
314    }
315
316    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
317    ///
318    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
319    pub fn get_operation(&self) -> super::builder::notebook_service::GetOperation {
320        super::builder::notebook_service::GetOperation::new(self.inner.clone())
321    }
322
323    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
324    ///
325    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
326    pub fn delete_operation(&self) -> super::builder::notebook_service::DeleteOperation {
327        super::builder::notebook_service::DeleteOperation::new(self.inner.clone())
328    }
329
330    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
331    ///
332    /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
333    pub fn cancel_operation(&self) -> super::builder::notebook_service::CancelOperation {
334        super::builder::notebook_service::CancelOperation::new(self.inner.clone())
335    }
336}