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/// # Service Description
25///
26/// API for interacting with Google Cloud Shell. Each user of Cloud Shell has at
27/// least one environment, which has the ID "default". Environment consists of a
28/// Docker image defining what is installed on the environment and a home
29/// directory containing the user's data that will remain across sessions.
30/// Clients use this API to start and fetch information about their environment,
31/// which can then be used to connect to that environment via a separate SSH
32/// client.
33///
34/// # Configuration
35///
36/// `CloudShellService` has various configuration parameters, the defaults should
37/// work with most applications.
38///
39/// # Pooling and Cloning
40///
41/// `CloudShellService` holds a connection pool internally, it is advised to
42/// create one and the reuse it. You do not need to wrap `CloudShellService` in
43/// an [Rc](std::rc::Rc) or [Arc] to reuse it, because it already uses an `Arc`
44/// internally.
45#[derive(Clone, Debug)]
46pub struct CloudShellService {
47 inner: Arc<dyn crate::stubs::dynamic::CloudShellService>,
48}
49
50impl CloudShellService {
51 /// Creates a new client with the default configuration.
52 pub async fn new() -> Result<Self> {
53 Self::new_with_config(gax::options::ClientConfig::default()).await
54 }
55
56 /// Creates a new client with the specified configuration.
57 pub async fn new_with_config(conf: gax::options::ClientConfig) -> Result<Self> {
58 let inner = Self::build_inner(conf).await?;
59 Ok(Self { inner })
60 }
61
62 /// Creates a new client from the provided stub.
63 ///
64 /// The most common case for calling this function is when mocking the
65 /// client.
66 pub fn from_stub<T>(stub: T) -> Self
67 where
68 T: crate::stubs::CloudShellService + 'static,
69 {
70 Self {
71 inner: Arc::new(stub),
72 }
73 }
74
75 async fn build_inner(
76 conf: gax::options::ClientConfig,
77 ) -> Result<Arc<dyn crate::stubs::dynamic::CloudShellService>> {
78 if conf.tracing_enabled() {
79 return Ok(Arc::new(Self::build_with_tracing(conf).await?));
80 }
81 Ok(Arc::new(Self::build_transport(conf).await?))
82 }
83
84 async fn build_transport(
85 conf: gax::options::ClientConfig,
86 ) -> Result<impl crate::stubs::CloudShellService> {
87 crate::transport::CloudShellService::new(conf).await
88 }
89
90 async fn build_with_tracing(
91 conf: gax::options::ClientConfig,
92 ) -> Result<impl crate::stubs::CloudShellService> {
93 Self::build_transport(conf)
94 .await
95 .map(crate::tracing::CloudShellService::new)
96 }
97
98 /// Gets an environment. Returns NOT_FOUND if the environment does not exist.
99 pub fn get_environment(
100 &self,
101 name: impl Into<std::string::String>,
102 ) -> crate::builders::cloud_shell_service::GetEnvironment {
103 crate::builders::cloud_shell_service::GetEnvironment::new(self.inner.clone())
104 .set_name(name.into())
105 }
106
107 /// Starts an existing environment, allowing clients to connect to it. The
108 /// returned operation will contain an instance of StartEnvironmentMetadata in
109 /// its metadata field. Users can wait for the environment to start by polling
110 /// this operation via GetOperation. Once the environment has finished starting
111 /// and is ready to accept connections, the operation will contain a
112 /// StartEnvironmentResponse in its response field.
113 ///
114 /// # Long running operations
115 ///
116 /// This method is used to start, and/or poll a [long-running Operation].
117 /// The [Working with long-running operations] chapter in the [user guide]
118 /// covers these operations in detail.
119 ///
120 /// [long-running operation]: https://google.aip.dev/151
121 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
122 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
123 pub fn start_environment(
124 &self,
125 name: impl Into<std::string::String>,
126 ) -> crate::builders::cloud_shell_service::StartEnvironment {
127 crate::builders::cloud_shell_service::StartEnvironment::new(self.inner.clone())
128 .set_name(name.into())
129 }
130
131 /// Sends OAuth credentials to a running environment on behalf of a user. When
132 /// this completes, the environment will be authorized to run various Google
133 /// Cloud command line tools without requiring the user to manually
134 /// authenticate.
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 authorize_environment(
146 &self,
147 name: impl Into<std::string::String>,
148 ) -> crate::builders::cloud_shell_service::AuthorizeEnvironment {
149 crate::builders::cloud_shell_service::AuthorizeEnvironment::new(self.inner.clone())
150 .set_name(name.into())
151 }
152
153 /// Adds a public SSH key to an environment, allowing clients with the
154 /// corresponding private key to connect to that environment via SSH. If a key
155 /// with the same content already exists, this will error with ALREADY_EXISTS.
156 ///
157 /// # Long running operations
158 ///
159 /// This method is used to start, and/or poll a [long-running Operation].
160 /// The [Working with long-running operations] chapter in the [user guide]
161 /// covers these operations in detail.
162 ///
163 /// [long-running operation]: https://google.aip.dev/151
164 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
165 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
166 pub fn add_public_key(
167 &self,
168 environment: impl Into<std::string::String>,
169 ) -> crate::builders::cloud_shell_service::AddPublicKey {
170 crate::builders::cloud_shell_service::AddPublicKey::new(self.inner.clone())
171 .set_environment(environment.into())
172 }
173
174 /// Removes a public SSH key from an environment. Clients will no longer be
175 /// able to connect to the environment using the corresponding private key.
176 /// If a key with the same content is not present, this will error with
177 /// NOT_FOUND.
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 remove_public_key(
189 &self,
190 environment: impl Into<std::string::String>,
191 ) -> crate::builders::cloud_shell_service::RemovePublicKey {
192 crate::builders::cloud_shell_service::RemovePublicKey::new(self.inner.clone())
193 .set_environment(environment.into())
194 }
195
196 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
197 ///
198 /// [google.longrunning.Operations]: longrunning::client::Operations
199 pub fn get_operation(
200 &self,
201 name: impl Into<std::string::String>,
202 ) -> crate::builders::cloud_shell_service::GetOperation {
203 crate::builders::cloud_shell_service::GetOperation::new(self.inner.clone())
204 .set_name(name.into())
205 }
206}