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/// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
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/// # 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 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
76 /// # use google_cloud_shell_v1::client::CloudShellService;
77 /// let client = CloudShellService::builder().build().await?;
78 /// # Ok(()) }
79 /// ```
80 pub fn builder() -> super::builder::cloud_shell_service::ClientBuilder {
81 crate::new_client_builder(super::builder::cloud_shell_service::client::Factory)
82 }
83
84 /// Creates a new client from the provided stub.
85 ///
86 /// The most common case for calling this function is in tests mocking the
87 /// client's behavior.
88 pub fn from_stub<T>(stub: T) -> Self
89 where
90 T: super::stub::CloudShellService + 'static,
91 {
92 Self {
93 inner: std::sync::Arc::new(stub),
94 }
95 }
96
97 pub(crate) async fn new(
98 config: gaxi::options::ClientConfig,
99 ) -> crate::ClientBuilderResult<Self> {
100 let inner = Self::build_inner(config).await?;
101 Ok(Self { inner })
102 }
103
104 async fn build_inner(
105 conf: gaxi::options::ClientConfig,
106 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::CloudShellService>>
107 {
108 if gaxi::options::tracing_enabled(&conf) {
109 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
110 }
111 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
112 }
113
114 async fn build_transport(
115 conf: gaxi::options::ClientConfig,
116 ) -> crate::ClientBuilderResult<impl super::stub::CloudShellService> {
117 super::transport::CloudShellService::new(conf).await
118 }
119
120 async fn build_with_tracing(
121 conf: gaxi::options::ClientConfig,
122 ) -> crate::ClientBuilderResult<impl super::stub::CloudShellService> {
123 Self::build_transport(conf)
124 .await
125 .map(super::tracing::CloudShellService::new)
126 }
127
128 /// Gets an environment. Returns NOT_FOUND if the environment does not exist.
129 pub fn get_environment(&self) -> super::builder::cloud_shell_service::GetEnvironment {
130 super::builder::cloud_shell_service::GetEnvironment::new(self.inner.clone())
131 }
132
133 /// Starts an existing environment, allowing clients to connect to it. The
134 /// returned operation will contain an instance of StartEnvironmentMetadata in
135 /// its metadata field. Users can wait for the environment to start by polling
136 /// this operation via GetOperation. Once the environment has finished starting
137 /// and is ready to accept connections, the operation will contain a
138 /// StartEnvironmentResponse in its response field.
139 ///
140 /// # Long running operations
141 ///
142 /// This method is used to start, and/or poll a [long-running Operation].
143 /// The [Working with long-running operations] chapter in the [user guide]
144 /// covers these operations in detail.
145 ///
146 /// [long-running operation]: https://google.aip.dev/151
147 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
148 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
149 pub fn start_environment(&self) -> super::builder::cloud_shell_service::StartEnvironment {
150 super::builder::cloud_shell_service::StartEnvironment::new(self.inner.clone())
151 }
152
153 /// Sends OAuth credentials to a running environment on behalf of a user. When
154 /// this completes, the environment will be authorized to run various Google
155 /// Cloud command line tools without requiring the user to manually
156 /// authenticate.
157 ///
158 /// # Long running operations
159 ///
160 /// This method is used to start, and/or poll a [long-running Operation].
161 /// The [Working with long-running operations] chapter in the [user guide]
162 /// covers these operations in detail.
163 ///
164 /// [long-running operation]: https://google.aip.dev/151
165 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
166 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
167 pub fn authorize_environment(
168 &self,
169 ) -> super::builder::cloud_shell_service::AuthorizeEnvironment {
170 super::builder::cloud_shell_service::AuthorizeEnvironment::new(self.inner.clone())
171 }
172
173 /// Adds a public SSH key to an environment, allowing clients with the
174 /// corresponding private key to connect to that environment via SSH. If a key
175 /// with the same content already exists, this will error with ALREADY_EXISTS.
176 ///
177 /// # Long running operations
178 ///
179 /// This method is used to start, and/or poll a [long-running Operation].
180 /// The [Working with long-running operations] chapter in the [user guide]
181 /// covers these operations in detail.
182 ///
183 /// [long-running operation]: https://google.aip.dev/151
184 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
185 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
186 pub fn add_public_key(&self) -> super::builder::cloud_shell_service::AddPublicKey {
187 super::builder::cloud_shell_service::AddPublicKey::new(self.inner.clone())
188 }
189
190 /// Removes a public SSH key from an environment. Clients will no longer be
191 /// able to connect to the environment using the corresponding private key.
192 /// If a key with the same content is not present, this will error with
193 /// NOT_FOUND.
194 ///
195 /// # Long running operations
196 ///
197 /// This method is used to start, and/or poll a [long-running Operation].
198 /// The [Working with long-running operations] chapter in the [user guide]
199 /// covers these operations in detail.
200 ///
201 /// [long-running operation]: https://google.aip.dev/151
202 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
203 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
204 pub fn remove_public_key(&self) -> super::builder::cloud_shell_service::RemovePublicKey {
205 super::builder::cloud_shell_service::RemovePublicKey::new(self.inner.clone())
206 }
207
208 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
209 ///
210 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
211 pub fn get_operation(&self) -> super::builder::cloud_shell_service::GetOperation {
212 super::builder::cloud_shell_service::GetOperation::new(self.inner.clone())
213 }
214}