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/// # tokio_test::block_on(async {
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/// # gax::client_builder::Result::<()>::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    /// # tokio_test::block_on(async {
70    /// # use google_cloud_notebooks_v2::client::NotebookService;
71    /// let client = NotebookService::builder().build().await?;
72    /// # gax::client_builder::Result::<()>::Ok(()) });
73    /// ```
74    pub fn builder() -> super::builder::notebook_service::ClientBuilder {
75        gax::client_builder::internal::new_builder(
76            super::builder::notebook_service::client::Factory,
77        )
78    }
79
80    /// Creates a new client from the provided stub.
81    ///
82    /// The most common case for calling this function is in tests mocking the
83    /// client's behavior.
84    pub fn from_stub<T>(stub: T) -> Self
85    where
86        T: super::stub::NotebookService + 'static,
87    {
88        Self {
89            inner: std::sync::Arc::new(stub),
90        }
91    }
92
93    pub(crate) async fn new(
94        config: gaxi::options::ClientConfig,
95    ) -> gax::client_builder::Result<Self> {
96        let inner = Self::build_inner(config).await?;
97        Ok(Self { inner })
98    }
99
100    async fn build_inner(
101        conf: gaxi::options::ClientConfig,
102    ) -> gax::client_builder::Result<std::sync::Arc<dyn super::stub::dynamic::NotebookService>>
103    {
104        if gaxi::options::tracing_enabled(&conf) {
105            return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
106        }
107        Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
108    }
109
110    async fn build_transport(
111        conf: gaxi::options::ClientConfig,
112    ) -> gax::client_builder::Result<impl super::stub::NotebookService> {
113        super::transport::NotebookService::new(conf).await
114    }
115
116    async fn build_with_tracing(
117        conf: gaxi::options::ClientConfig,
118    ) -> gax::client_builder::Result<impl super::stub::NotebookService> {
119        Self::build_transport(conf)
120            .await
121            .map(super::tracing::NotebookService::new)
122    }
123
124    /// Lists instances in a given project and location.
125    pub fn list_instances(&self) -> super::builder::notebook_service::ListInstances {
126        super::builder::notebook_service::ListInstances::new(self.inner.clone())
127    }
128
129    /// Gets details of a single Instance.
130    pub fn get_instance(&self) -> super::builder::notebook_service::GetInstance {
131        super::builder::notebook_service::GetInstance::new(self.inner.clone())
132    }
133
134    /// Creates a new Instance in a given project and location.
135    ///
136    /// # Long running operations
137    ///
138    /// This method is used to start, and/or poll a [long-running Operation].
139    /// The [Working with long-running operations] chapter in the [user guide]
140    /// covers these operations in detail.
141    ///
142    /// [long-running operation]: https://google.aip.dev/151
143    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
144    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
145    pub fn create_instance(&self) -> super::builder::notebook_service::CreateInstance {
146        super::builder::notebook_service::CreateInstance::new(self.inner.clone())
147    }
148
149    /// UpdateInstance updates an Instance.
150    ///
151    /// # Long running operations
152    ///
153    /// This method is used to start, and/or poll a [long-running Operation].
154    /// The [Working with long-running operations] chapter in the [user guide]
155    /// covers these operations in detail.
156    ///
157    /// [long-running operation]: https://google.aip.dev/151
158    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
159    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
160    pub fn update_instance(&self) -> super::builder::notebook_service::UpdateInstance {
161        super::builder::notebook_service::UpdateInstance::new(self.inner.clone())
162    }
163
164    /// Deletes a single Instance.
165    ///
166    /// # Long running operations
167    ///
168    /// This method is used to start, and/or poll a [long-running Operation].
169    /// The [Working with long-running operations] chapter in the [user guide]
170    /// covers these operations in detail.
171    ///
172    /// [long-running operation]: https://google.aip.dev/151
173    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
174    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
175    pub fn delete_instance(&self) -> super::builder::notebook_service::DeleteInstance {
176        super::builder::notebook_service::DeleteInstance::new(self.inner.clone())
177    }
178
179    /// Starts a notebook instance.
180    ///
181    /// # Long running operations
182    ///
183    /// This method is used to start, and/or poll a [long-running Operation].
184    /// The [Working with long-running operations] chapter in the [user guide]
185    /// covers these operations in detail.
186    ///
187    /// [long-running operation]: https://google.aip.dev/151
188    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
189    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
190    pub fn start_instance(&self) -> super::builder::notebook_service::StartInstance {
191        super::builder::notebook_service::StartInstance::new(self.inner.clone())
192    }
193
194    /// Stops a notebook instance.
195    ///
196    /// # Long running operations
197    ///
198    /// This method is used to start, and/or poll a [long-running Operation].
199    /// The [Working with long-running operations] chapter in the [user guide]
200    /// covers these operations in detail.
201    ///
202    /// [long-running operation]: https://google.aip.dev/151
203    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
204    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
205    pub fn stop_instance(&self) -> super::builder::notebook_service::StopInstance {
206        super::builder::notebook_service::StopInstance::new(self.inner.clone())
207    }
208
209    /// Resets a notebook instance.
210    ///
211    /// # Long running operations
212    ///
213    /// This method is used to start, and/or poll a [long-running Operation].
214    /// The [Working with long-running operations] chapter in the [user guide]
215    /// covers these operations in detail.
216    ///
217    /// [long-running operation]: https://google.aip.dev/151
218    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
219    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
220    pub fn reset_instance(&self) -> super::builder::notebook_service::ResetInstance {
221        super::builder::notebook_service::ResetInstance::new(self.inner.clone())
222    }
223
224    /// Checks whether a notebook instance is upgradable.
225    pub fn check_instance_upgradability(
226        &self,
227    ) -> super::builder::notebook_service::CheckInstanceUpgradability {
228        super::builder::notebook_service::CheckInstanceUpgradability::new(self.inner.clone())
229    }
230
231    /// Upgrades a notebook instance to the latest version.
232    ///
233    /// # Long running operations
234    ///
235    /// This method is used to start, and/or poll a [long-running Operation].
236    /// The [Working with long-running operations] chapter in the [user guide]
237    /// covers these operations in detail.
238    ///
239    /// [long-running operation]: https://google.aip.dev/151
240    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
241    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
242    pub fn upgrade_instance(&self) -> super::builder::notebook_service::UpgradeInstance {
243        super::builder::notebook_service::UpgradeInstance::new(self.inner.clone())
244    }
245
246    /// Rollbacks a notebook instance to the previous version.
247    ///
248    /// # Long running operations
249    ///
250    /// This method is used to start, and/or poll a [long-running Operation].
251    /// The [Working with long-running operations] chapter in the [user guide]
252    /// covers these operations in detail.
253    ///
254    /// [long-running operation]: https://google.aip.dev/151
255    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
256    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
257    pub fn rollback_instance(&self) -> super::builder::notebook_service::RollbackInstance {
258        super::builder::notebook_service::RollbackInstance::new(self.inner.clone())
259    }
260
261    /// Creates a Diagnostic File and runs Diagnostic Tool given an Instance.
262    ///
263    /// # Long running operations
264    ///
265    /// This method is used to start, and/or poll a [long-running Operation].
266    /// The [Working with long-running operations] chapter in the [user guide]
267    /// covers these operations in detail.
268    ///
269    /// [long-running operation]: https://google.aip.dev/151
270    /// [user guide]: https://googleapis.github.io/google-cloud-rust/
271    /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
272    pub fn diagnose_instance(&self) -> super::builder::notebook_service::DiagnoseInstance {
273        super::builder::notebook_service::DiagnoseInstance::new(self.inner.clone())
274    }
275
276    /// Lists information about the supported locations for this service.
277    pub fn list_locations(&self) -> super::builder::notebook_service::ListLocations {
278        super::builder::notebook_service::ListLocations::new(self.inner.clone())
279    }
280
281    /// Gets information about a location.
282    pub fn get_location(&self) -> super::builder::notebook_service::GetLocation {
283        super::builder::notebook_service::GetLocation::new(self.inner.clone())
284    }
285
286    /// Sets the access control policy on the specified resource. Replaces
287    /// any existing policy.
288    ///
289    /// Can return `NOT_FOUND`, `INVALID_ARGUMENT`, and `PERMISSION_DENIED`
290    /// errors.
291    pub fn set_iam_policy(&self) -> super::builder::notebook_service::SetIamPolicy {
292        super::builder::notebook_service::SetIamPolicy::new(self.inner.clone())
293    }
294
295    /// Gets the access control policy for a resource. Returns an empty policy
296    /// if the resource exists and does not have a policy set.
297    pub fn get_iam_policy(&self) -> super::builder::notebook_service::GetIamPolicy {
298        super::builder::notebook_service::GetIamPolicy::new(self.inner.clone())
299    }
300
301    /// Returns permissions that a caller has on the specified resource. If the
302    /// resource does not exist, this will return an empty set of
303    /// permissions, not a `NOT_FOUND` error.
304    ///
305    /// Note: This operation is designed to be used for building
306    /// permission-aware UIs and command-line tools, not for authorization
307    /// checking. This operation may "fail open" without warning.
308    pub fn test_iam_permissions(&self) -> super::builder::notebook_service::TestIamPermissions {
309        super::builder::notebook_service::TestIamPermissions::new(self.inner.clone())
310    }
311
312    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
313    ///
314    /// [google.longrunning.Operations]: longrunning::client::Operations
315    pub fn list_operations(&self) -> super::builder::notebook_service::ListOperations {
316        super::builder::notebook_service::ListOperations::new(self.inner.clone())
317    }
318
319    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
320    ///
321    /// [google.longrunning.Operations]: longrunning::client::Operations
322    pub fn get_operation(&self) -> super::builder::notebook_service::GetOperation {
323        super::builder::notebook_service::GetOperation::new(self.inner.clone())
324    }
325
326    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
327    ///
328    /// [google.longrunning.Operations]: longrunning::client::Operations
329    pub fn delete_operation(&self) -> super::builder::notebook_service::DeleteOperation {
330        super::builder::notebook_service::DeleteOperation::new(self.inner.clone())
331    }
332
333    /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
334    ///
335    /// [google.longrunning.Operations]: longrunning::client::Operations
336    pub fn cancel_operation(&self) -> super::builder::notebook_service::CancelOperation {
337        super::builder::notebook_service::CancelOperation::new(self.inner.clone())
338    }
339}