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