google_cloud_shell_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;
20
21/// Implements a client for the Cloud Shell API.
22///
23/// # Example
24/// ```
25/// # tokio_test::block_on(async {
26/// # use google_cloud_shell_v1::client::CloudShellService;
27/// let client = CloudShellService::builder().build().await?;
28/// // use `client` to make requests to the Cloud Shell API.
29/// # gax::Result::<()>::Ok(()) });
30/// ```
31///
32/// # Service Description
33///
34/// API for interacting with Google Cloud Shell. Each user of Cloud Shell has at
35/// least one environment, which has the ID "default". Environment consists of a
36/// Docker image defining what is installed on the environment and a home
37/// directory containing the user's data that will remain across sessions.
38/// Clients use this API to start and fetch information about their environment,
39/// which can then be used to connect to that environment via a separate SSH
40/// client.
41///
42/// # Configuration
43///
44/// To configure `CloudShellService` use the `with_*` methods in the type returned
45/// by [builder()][CloudShellService::builder]. The default configuration should
46/// work for most applications. Common configuration changes include
47///
48/// * [with_endpoint()]: by default this client uses the global default endpoint
49/// (`https://cloudshell.googleapis.com`). Applications using regional
50/// endpoints or running in restricted networks (e.g. a network configured
51// with [Private Google Access with VPC Service Controls]) may want to
52/// override this default.
53/// * [with_credentials()]: by default this client uses
54/// [Application Default Credentials]. Applications using custom
55/// authentication may need to override this default.
56///
57/// [with_endpoint()]: super::builder::cloud_shell_service::ClientBuilder::with_endpoint
58/// [with_credentials()]: super::builder::cloud_shell_service::ClientBuilder::credentials
59/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
60/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
61///
62/// # Pooling and Cloning
63///
64/// `CloudShellService` holds a connection pool internally, it is advised to
65/// create one and the reuse it. You do not need to wrap `CloudShellService` in
66/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
67/// already uses an `Arc` internally.
68#[derive(Clone, Debug)]
69pub struct CloudShellService {
70 inner: std::sync::Arc<dyn super::stub::dynamic::CloudShellService>,
71}
72
73impl CloudShellService {
74 /// Returns a builder for [CloudShellService].
75 ///
76 /// ```
77 /// # tokio_test::block_on(async {
78 /// # use google_cloud_shell_v1::client::CloudShellService;
79 /// let client = CloudShellService::builder().build().await?;
80 /// # gax::Result::<()>::Ok(()) });
81 /// ```
82 pub fn builder() -> super::builder::cloud_shell_service::ClientBuilder {
83 gax::client_builder::internal::new_builder(
84 super::builder::cloud_shell_service::client::Factory,
85 )
86 }
87
88 /// Creates a new client from the provided stub.
89 ///
90 /// The most common case for calling this function is in tests mocking the
91 /// client's behavior.
92 pub fn from_stub<T>(stub: T) -> Self
93 where
94 T: super::stub::CloudShellService + 'static,
95 {
96 Self {
97 inner: std::sync::Arc::new(stub),
98 }
99 }
100
101 pub(crate) async fn new(config: gaxi::options::ClientConfig) -> Result<Self> {
102 let inner = Self::build_inner(config).await?;
103 Ok(Self { inner })
104 }
105
106 async fn build_inner(
107 conf: gaxi::options::ClientConfig,
108 ) -> Result<std::sync::Arc<dyn super::stub::dynamic::CloudShellService>> {
109 if gaxi::options::tracing_enabled(&conf) {
110 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
111 }
112 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
113 }
114
115 async fn build_transport(
116 conf: gaxi::options::ClientConfig,
117 ) -> Result<impl super::stub::CloudShellService> {
118 super::transport::CloudShellService::new(conf).await
119 }
120
121 async fn build_with_tracing(
122 conf: gaxi::options::ClientConfig,
123 ) -> Result<impl super::stub::CloudShellService> {
124 Self::build_transport(conf)
125 .await
126 .map(super::tracing::CloudShellService::new)
127 }
128
129 /// Gets an environment. Returns NOT_FOUND if the environment does not exist.
130 pub fn get_environment(&self) -> super::builder::cloud_shell_service::GetEnvironment {
131 super::builder::cloud_shell_service::GetEnvironment::new(self.inner.clone())
132 }
133
134 /// Starts an existing environment, allowing clients to connect to it. The
135 /// returned operation will contain an instance of StartEnvironmentMetadata in
136 /// its metadata field. Users can wait for the environment to start by polling
137 /// this operation via GetOperation. Once the environment has finished starting
138 /// and is ready to accept connections, the operation will contain a
139 /// StartEnvironmentResponse in its response field.
140 ///
141 /// # Long running operations
142 ///
143 /// This method is used to start, and/or poll a [long-running Operation].
144 /// The [Working with long-running operations] chapter in the [user guide]
145 /// covers these operations in detail.
146 ///
147 /// [long-running operation]: https://google.aip.dev/151
148 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
149 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
150 pub fn start_environment(&self) -> super::builder::cloud_shell_service::StartEnvironment {
151 super::builder::cloud_shell_service::StartEnvironment::new(self.inner.clone())
152 }
153
154 /// Sends OAuth credentials to a running environment on behalf of a user. When
155 /// this completes, the environment will be authorized to run various Google
156 /// Cloud command line tools without requiring the user to manually
157 /// authenticate.
158 ///
159 /// # Long running operations
160 ///
161 /// This method is used to start, and/or poll a [long-running Operation].
162 /// The [Working with long-running operations] chapter in the [user guide]
163 /// covers these operations in detail.
164 ///
165 /// [long-running operation]: https://google.aip.dev/151
166 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
167 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
168 pub fn authorize_environment(
169 &self,
170 ) -> super::builder::cloud_shell_service::AuthorizeEnvironment {
171 super::builder::cloud_shell_service::AuthorizeEnvironment::new(self.inner.clone())
172 }
173
174 /// Adds a public SSH key to an environment, allowing clients with the
175 /// corresponding private key to connect to that environment via SSH. If a key
176 /// with the same content already exists, this will error with ALREADY_EXISTS.
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 add_public_key(&self) -> super::builder::cloud_shell_service::AddPublicKey {
188 super::builder::cloud_shell_service::AddPublicKey::new(self.inner.clone())
189 }
190
191 /// Removes a public SSH key from an environment. Clients will no longer be
192 /// able to connect to the environment using the corresponding private key.
193 /// If a key with the same content is not present, this will error with
194 /// NOT_FOUND.
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 remove_public_key(&self) -> super::builder::cloud_shell_service::RemovePublicKey {
206 super::builder::cloud_shell_service::RemovePublicKey::new(self.inner.clone())
207 }
208
209 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
210 ///
211 /// [google.longrunning.Operations]: longrunning::client::Operations
212 pub fn get_operation(&self) -> super::builder::cloud_shell_service::GetOperation {
213 super::builder::cloud_shell_service::GetOperation::new(self.inner.clone())
214 }
215}