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