google_cloudshell1/api.rs
1#![allow(clippy::ptr_arg)]
2
3use std::collections::{BTreeSet, HashMap};
4
5use tokio::time::sleep;
6
7// ##############
8// UTILITIES ###
9// ############
10
11/// Identifies the an OAuth2 authorization scope.
12/// A scope is needed when requesting an
13/// [authorization token](https://developers.google.com/youtube/v3/guides/authentication).
14#[derive(PartialEq, Eq, Ord, PartialOrd, Hash, Debug, Clone, Copy)]
15pub enum Scope {
16 /// See, edit, configure, and delete your Google Cloud data and see the email address for your Google Account.
17 CloudPlatform,
18}
19
20impl AsRef<str> for Scope {
21 fn as_ref(&self) -> &str {
22 match *self {
23 Scope::CloudPlatform => "https://www.googleapis.com/auth/cloud-platform",
24 }
25 }
26}
27
28#[allow(clippy::derivable_impls)]
29impl Default for Scope {
30 fn default() -> Scope {
31 Scope::CloudPlatform
32 }
33}
34
35// ########
36// HUB ###
37// ######
38
39/// Central instance to access all CloudShell related resource activities
40///
41/// # Examples
42///
43/// Instantiate a new hub
44///
45/// ```test_harness,no_run
46/// extern crate hyper;
47/// extern crate hyper_rustls;
48/// extern crate google_cloudshell1 as cloudshell1;
49/// use cloudshell1::{Result, Error};
50/// # async fn dox() {
51/// use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
52///
53/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
54/// // `client_secret`, among other things.
55/// let secret: yup_oauth2::ApplicationSecret = Default::default();
56/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
57/// // unless you replace `None` with the desired Flow.
58/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
59/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
60/// // retrieve them from storage.
61/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
62/// secret,
63/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
64/// ).build().await.unwrap();
65///
66/// let client = hyper_util::client::legacy::Client::builder(
67/// hyper_util::rt::TokioExecutor::new()
68/// )
69/// .build(
70/// hyper_rustls::HttpsConnectorBuilder::new()
71/// .with_native_roots()
72/// .unwrap()
73/// .https_or_http()
74/// .enable_http1()
75/// .build()
76/// );
77/// let mut hub = CloudShell::new(client, auth);
78/// // You can configure optional parameters by calling the respective setters at will, and
79/// // execute the final call using `doit()`.
80/// // Values shown here are possibly random and not representative !
81/// let result = hub.operations().list("name")
82/// .page_token("takimata")
83/// .page_size(-52)
84/// .filter("duo")
85/// .doit().await;
86///
87/// match result {
88/// Err(e) => match e {
89/// // The Error enum provides details about what exactly happened.
90/// // You can also just use its `Debug`, `Display` or `Error` traits
91/// Error::HttpError(_)
92/// |Error::Io(_)
93/// |Error::MissingAPIKey
94/// |Error::MissingToken(_)
95/// |Error::Cancelled
96/// |Error::UploadSizeLimitExceeded(_, _)
97/// |Error::Failure(_)
98/// |Error::BadRequest(_)
99/// |Error::FieldClash(_)
100/// |Error::JsonDecodeError(_, _) => println!("{}", e),
101/// },
102/// Ok(res) => println!("Success: {:?}", res),
103/// }
104/// # }
105/// ```
106#[derive(Clone)]
107pub struct CloudShell<C> {
108 pub client: common::Client<C>,
109 pub auth: Box<dyn common::GetToken>,
110 _user_agent: String,
111 _base_url: String,
112 _root_url: String,
113}
114
115impl<C> common::Hub for CloudShell<C> {}
116
117impl<'a, C> CloudShell<C> {
118 pub fn new<A: 'static + common::GetToken>(client: common::Client<C>, auth: A) -> CloudShell<C> {
119 CloudShell {
120 client,
121 auth: Box::new(auth),
122 _user_agent: "google-api-rust-client/6.0.0".to_string(),
123 _base_url: "https://cloudshell.googleapis.com/".to_string(),
124 _root_url: "https://cloudshell.googleapis.com/".to_string(),
125 }
126 }
127
128 pub fn operations(&'a self) -> OperationMethods<'a, C> {
129 OperationMethods { hub: self }
130 }
131 pub fn users(&'a self) -> UserMethods<'a, C> {
132 UserMethods { hub: self }
133 }
134
135 /// Set the user-agent header field to use in all requests to the server.
136 /// It defaults to `google-api-rust-client/6.0.0`.
137 ///
138 /// Returns the previously set user-agent.
139 pub fn user_agent(&mut self, agent_name: String) -> String {
140 std::mem::replace(&mut self._user_agent, agent_name)
141 }
142
143 /// Set the base url to use in all requests to the server.
144 /// It defaults to `https://cloudshell.googleapis.com/`.
145 ///
146 /// Returns the previously set base url.
147 pub fn base_url(&mut self, new_base_url: String) -> String {
148 std::mem::replace(&mut self._base_url, new_base_url)
149 }
150
151 /// Set the root url to use in all requests to the server.
152 /// It defaults to `https://cloudshell.googleapis.com/`.
153 ///
154 /// Returns the previously set root url.
155 pub fn root_url(&mut self, new_root_url: String) -> String {
156 std::mem::replace(&mut self._root_url, new_root_url)
157 }
158}
159
160// ############
161// SCHEMAS ###
162// ##########
163/// Request message for AddPublicKey.
164///
165/// # Activities
166///
167/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
168/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
169///
170/// * [environments add public key users](UserEnvironmentAddPublicKeyCall) (request)
171#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
172#[serde_with::serde_as]
173#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
174pub struct AddPublicKeyRequest {
175 /// Key that should be added to the environment. Supported formats are `ssh-dss` (see RFC4253), `ssh-rsa` (see RFC4253), `ecdsa-sha2-nistp256` (see RFC5656), `ecdsa-sha2-nistp384` (see RFC5656) and `ecdsa-sha2-nistp521` (see RFC5656). It should be structured as <format> <content>, where <content> part is encoded with Base64.
176 pub key: Option<String>,
177}
178
179impl common::RequestValue for AddPublicKeyRequest {}
180
181/// Request message for AuthorizeEnvironment.
182///
183/// # Activities
184///
185/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
186/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
187///
188/// * [environments authorize users](UserEnvironmentAuthorizeCall) (request)
189#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
190#[serde_with::serde_as]
191#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
192pub struct AuthorizeEnvironmentRequest {
193 /// The OAuth access token that should be sent to the environment.
194 #[serde(rename = "accessToken")]
195 pub access_token: Option<String>,
196 /// The time when the credentials expire. If not set, defaults to one hour from when the server received the request.
197 #[serde(rename = "expireTime")]
198 pub expire_time: Option<chrono::DateTime<chrono::offset::Utc>>,
199 /// The OAuth ID token that should be sent to the environment.
200 #[serde(rename = "idToken")]
201 pub id_token: Option<String>,
202}
203
204impl common::RequestValue for AuthorizeEnvironmentRequest {}
205
206/// The request message for Operations.CancelOperation.
207///
208/// # Activities
209///
210/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
211/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
212///
213/// * [cancel operations](OperationCancelCall) (request)
214#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
215#[serde_with::serde_as]
216#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
217pub struct CancelOperationRequest {
218 _never_set: Option<bool>,
219}
220
221impl common::RequestValue for CancelOperationRequest {}
222
223/// A generic empty message that you can re-use to avoid defining duplicated empty messages in your APIs. A typical example is to use it as the request or the response type of an API method. For instance: service Foo { rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); }
224///
225/// # Activities
226///
227/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
228/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
229///
230/// * [cancel operations](OperationCancelCall) (response)
231/// * [delete operations](OperationDeleteCall) (response)
232#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
233#[serde_with::serde_as]
234#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
235pub struct Empty {
236 _never_set: Option<bool>,
237}
238
239impl common::ResponseResult for Empty {}
240
241/// A Cloud Shell environment, which is defined as the combination of a Docker image specifying what is installed on the environment and a home directory containing the user’s data that will remain across sessions. Each user has at least an environment with the ID “default”.
242///
243/// # Activities
244///
245/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
246/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
247///
248/// * [environments get users](UserEnvironmentGetCall) (response)
249#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
250#[serde_with::serde_as]
251#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
252pub struct Environment {
253 /// Required. Immutable. Full path to the Docker image used to run this environment, e.g. "gcr.io/dev-con/cloud-devshell:latest".
254 #[serde(rename = "dockerImage")]
255 pub docker_image: Option<String>,
256 /// Output only. The environment's identifier, unique among the user's environments.
257 pub id: Option<String>,
258 /// Immutable. Full name of this resource, in the format `users/{owner_email}/environments/{environment_id}`. `{owner_email}` is the email address of the user to whom this environment belongs, and `{environment_id}` is the identifier of this environment. For example, `users/someone@example.com/environments/default`.
259 pub name: Option<String>,
260 /// Output only. Public keys associated with the environment. Clients can connect to this environment via SSH only if they possess a private key corresponding to at least one of these public keys. Keys can be added to or removed from the environment using the AddPublicKey and RemovePublicKey methods.
261 #[serde(rename = "publicKeys")]
262 pub public_keys: Option<Vec<String>>,
263 /// Output only. Host to which clients can connect to initiate SSH sessions with the environment.
264 #[serde(rename = "sshHost")]
265 pub ssh_host: Option<String>,
266 /// Output only. Port to which clients can connect to initiate SSH sessions with the environment.
267 #[serde(rename = "sshPort")]
268 pub ssh_port: Option<i32>,
269 /// Output only. Username that clients should use when initiating SSH sessions with the environment.
270 #[serde(rename = "sshUsername")]
271 pub ssh_username: Option<String>,
272 /// Output only. Current execution state of this environment.
273 pub state: Option<String>,
274 /// Output only. Host to which clients can connect to initiate HTTPS or WSS connections with the environment.
275 #[serde(rename = "webHost")]
276 pub web_host: Option<String>,
277}
278
279impl common::ResponseResult for Environment {}
280
281/// The response message for Operations.ListOperations.
282///
283/// # Activities
284///
285/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
286/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
287///
288/// * [list operations](OperationListCall) (response)
289#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
290#[serde_with::serde_as]
291#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
292pub struct ListOperationsResponse {
293 /// The standard List next-page token.
294 #[serde(rename = "nextPageToken")]
295 pub next_page_token: Option<String>,
296 /// A list of operations that matches the specified filter in the request.
297 pub operations: Option<Vec<Operation>>,
298}
299
300impl common::ResponseResult for ListOperationsResponse {}
301
302/// This resource represents a long-running operation that is the result of a network API call.
303///
304/// # Activities
305///
306/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
307/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
308///
309/// * [cancel operations](OperationCancelCall) (none)
310/// * [delete operations](OperationDeleteCall) (none)
311/// * [get operations](OperationGetCall) (response)
312/// * [list operations](OperationListCall) (none)
313/// * [environments add public key users](UserEnvironmentAddPublicKeyCall) (response)
314/// * [environments authorize users](UserEnvironmentAuthorizeCall) (response)
315/// * [environments remove public key users](UserEnvironmentRemovePublicKeyCall) (response)
316/// * [environments start users](UserEnvironmentStartCall) (response)
317#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
318#[serde_with::serde_as]
319#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
320pub struct Operation {
321 /// If the value is `false`, it means the operation is still in progress. If `true`, the operation is completed, and either `error` or `response` is available.
322 pub done: Option<bool>,
323 /// The error result of the operation in case of failure or cancellation.
324 pub error: Option<Status>,
325 /// Service-specific metadata associated with the operation. It typically contains progress information and common metadata such as create time. Some services might not provide such metadata. Any method that returns a long-running operation should document the metadata type, if any.
326 pub metadata: Option<HashMap<String, serde_json::Value>>,
327 /// The server-assigned name, which is only unique within the same service that originally returns it. If you use the default HTTP mapping, the `name` should be a resource name ending with `operations/{unique_id}`.
328 pub name: Option<String>,
329 /// The normal, successful response of the operation. If the original method returns no data on success, such as `Delete`, the response is `google.protobuf.Empty`. If the original method is standard `Get`/`Create`/`Update`, the response should be the resource. For other methods, the response should have the type `XxxResponse`, where `Xxx` is the original method name. For example, if the original method name is `TakeSnapshot()`, the inferred response type is `TakeSnapshotResponse`.
330 pub response: Option<HashMap<String, serde_json::Value>>,
331}
332
333impl common::Resource for Operation {}
334impl common::ResponseResult for Operation {}
335
336/// Request message for RemovePublicKey.
337///
338/// # Activities
339///
340/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
341/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
342///
343/// * [environments remove public key users](UserEnvironmentRemovePublicKeyCall) (request)
344#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
345#[serde_with::serde_as]
346#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
347pub struct RemovePublicKeyRequest {
348 /// Key that should be removed from the environment.
349 pub key: Option<String>,
350}
351
352impl common::RequestValue for RemovePublicKeyRequest {}
353
354/// Request message for StartEnvironment.
355///
356/// # Activities
357///
358/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
359/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
360///
361/// * [environments start users](UserEnvironmentStartCall) (request)
362#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
363#[serde_with::serde_as]
364#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
365pub struct StartEnvironmentRequest {
366 /// The initial access token passed to the environment. If this is present and valid, the environment will be pre-authenticated with gcloud so that the user can run gcloud commands in Cloud Shell without having to log in. This code can be updated later by calling AuthorizeEnvironment.
367 #[serde(rename = "accessToken")]
368 pub access_token: Option<String>,
369 /// Public keys that should be added to the environment before it is started.
370 #[serde(rename = "publicKeys")]
371 pub public_keys: Option<Vec<String>>,
372}
373
374impl common::RequestValue for StartEnvironmentRequest {}
375
376/// The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details. You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).
377///
378/// This type is not used in any activity, and only used as *part* of another schema.
379///
380#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
381#[serde_with::serde_as]
382#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
383pub struct Status {
384 /// The status code, which should be an enum value of google.rpc.Code.
385 pub code: Option<i32>,
386 /// A list of messages that carry the error details. There is a common set of message types for APIs to use.
387 pub details: Option<Vec<HashMap<String, serde_json::Value>>>,
388 /// A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the google.rpc.Status.details field, or localized by the client.
389 pub message: Option<String>,
390}
391
392impl common::Part for Status {}
393
394// ###################
395// MethodBuilders ###
396// #################
397
398/// A builder providing access to all methods supported on *operation* resources.
399/// It is not used directly, but through the [`CloudShell`] hub.
400///
401/// # Example
402///
403/// Instantiate a resource builder
404///
405/// ```test_harness,no_run
406/// extern crate hyper;
407/// extern crate hyper_rustls;
408/// extern crate google_cloudshell1 as cloudshell1;
409///
410/// # async fn dox() {
411/// use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
412///
413/// let secret: yup_oauth2::ApplicationSecret = Default::default();
414/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
415/// secret,
416/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
417/// ).build().await.unwrap();
418///
419/// let client = hyper_util::client::legacy::Client::builder(
420/// hyper_util::rt::TokioExecutor::new()
421/// )
422/// .build(
423/// hyper_rustls::HttpsConnectorBuilder::new()
424/// .with_native_roots()
425/// .unwrap()
426/// .https_or_http()
427/// .enable_http1()
428/// .build()
429/// );
430/// let mut hub = CloudShell::new(client, auth);
431/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
432/// // like `cancel(...)`, `delete(...)`, `get(...)` and `list(...)`
433/// // to build up your call.
434/// let rb = hub.operations();
435/// # }
436/// ```
437pub struct OperationMethods<'a, C>
438where
439 C: 'a,
440{
441 hub: &'a CloudShell<C>,
442}
443
444impl<'a, C> common::MethodsBuilder for OperationMethods<'a, C> {}
445
446impl<'a, C> OperationMethods<'a, C> {
447 /// Create a builder to help you perform the following task:
448 ///
449 /// Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to `Code.CANCELLED`.
450 ///
451 /// # Arguments
452 ///
453 /// * `request` - No description provided.
454 /// * `name` - The name of the operation resource to be cancelled.
455 pub fn cancel(
456 &self,
457 request: CancelOperationRequest,
458 name: &str,
459 ) -> OperationCancelCall<'a, C> {
460 OperationCancelCall {
461 hub: self.hub,
462 _request: request,
463 _name: name.to_string(),
464 _delegate: Default::default(),
465 _additional_params: Default::default(),
466 _scopes: Default::default(),
467 }
468 }
469
470 /// Create a builder to help you perform the following task:
471 ///
472 /// Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`.
473 ///
474 /// # Arguments
475 ///
476 /// * `name` - The name of the operation resource to be deleted.
477 pub fn delete(&self, name: &str) -> OperationDeleteCall<'a, C> {
478 OperationDeleteCall {
479 hub: self.hub,
480 _name: name.to_string(),
481 _delegate: Default::default(),
482 _additional_params: Default::default(),
483 _scopes: Default::default(),
484 }
485 }
486
487 /// Create a builder to help you perform the following task:
488 ///
489 /// Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.
490 ///
491 /// # Arguments
492 ///
493 /// * `name` - The name of the operation resource.
494 pub fn get(&self, name: &str) -> OperationGetCall<'a, C> {
495 OperationGetCall {
496 hub: self.hub,
497 _name: name.to_string(),
498 _delegate: Default::default(),
499 _additional_params: Default::default(),
500 _scopes: Default::default(),
501 }
502 }
503
504 /// Create a builder to help you perform the following task:
505 ///
506 /// Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns `UNIMPLEMENTED`.
507 ///
508 /// # Arguments
509 ///
510 /// * `name` - The name of the operation's parent resource.
511 pub fn list(&self, name: &str) -> OperationListCall<'a, C> {
512 OperationListCall {
513 hub: self.hub,
514 _name: name.to_string(),
515 _page_token: Default::default(),
516 _page_size: Default::default(),
517 _filter: Default::default(),
518 _delegate: Default::default(),
519 _additional_params: Default::default(),
520 _scopes: Default::default(),
521 }
522 }
523}
524
525/// A builder providing access to all methods supported on *user* resources.
526/// It is not used directly, but through the [`CloudShell`] hub.
527///
528/// # Example
529///
530/// Instantiate a resource builder
531///
532/// ```test_harness,no_run
533/// extern crate hyper;
534/// extern crate hyper_rustls;
535/// extern crate google_cloudshell1 as cloudshell1;
536///
537/// # async fn dox() {
538/// use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
539///
540/// let secret: yup_oauth2::ApplicationSecret = Default::default();
541/// let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
542/// secret,
543/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
544/// ).build().await.unwrap();
545///
546/// let client = hyper_util::client::legacy::Client::builder(
547/// hyper_util::rt::TokioExecutor::new()
548/// )
549/// .build(
550/// hyper_rustls::HttpsConnectorBuilder::new()
551/// .with_native_roots()
552/// .unwrap()
553/// .https_or_http()
554/// .enable_http1()
555/// .build()
556/// );
557/// let mut hub = CloudShell::new(client, auth);
558/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
559/// // like `environments_add_public_key(...)`, `environments_authorize(...)`, `environments_get(...)`, `environments_remove_public_key(...)` and `environments_start(...)`
560/// // to build up your call.
561/// let rb = hub.users();
562/// # }
563/// ```
564pub struct UserMethods<'a, C>
565where
566 C: 'a,
567{
568 hub: &'a CloudShell<C>,
569}
570
571impl<'a, C> common::MethodsBuilder for UserMethods<'a, C> {}
572
573impl<'a, C> UserMethods<'a, C> {
574 /// Create a builder to help you perform the following task:
575 ///
576 /// Adds a public SSH key to an environment, allowing clients with the corresponding private key to connect to that environment via SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS.
577 ///
578 /// # Arguments
579 ///
580 /// * `request` - No description provided.
581 /// * `environment` - Environment this key should be added to, e.g. `users/me/environments/default`.
582 pub fn environments_add_public_key(
583 &self,
584 request: AddPublicKeyRequest,
585 environment: &str,
586 ) -> UserEnvironmentAddPublicKeyCall<'a, C> {
587 UserEnvironmentAddPublicKeyCall {
588 hub: self.hub,
589 _request: request,
590 _environment: environment.to_string(),
591 _delegate: Default::default(),
592 _additional_params: Default::default(),
593 _scopes: Default::default(),
594 }
595 }
596
597 /// Create a builder to help you perform the following task:
598 ///
599 /// Sends OAuth credentials to a running environment on behalf of a user. When this completes, the environment will be authorized to run various Google Cloud command line tools without requiring the user to manually authenticate.
600 ///
601 /// # Arguments
602 ///
603 /// * `request` - No description provided.
604 /// * `name` - Name of the resource that should receive the credentials, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
605 pub fn environments_authorize(
606 &self,
607 request: AuthorizeEnvironmentRequest,
608 name: &str,
609 ) -> UserEnvironmentAuthorizeCall<'a, C> {
610 UserEnvironmentAuthorizeCall {
611 hub: self.hub,
612 _request: request,
613 _name: name.to_string(),
614 _delegate: Default::default(),
615 _additional_params: Default::default(),
616 _scopes: Default::default(),
617 }
618 }
619
620 /// Create a builder to help you perform the following task:
621 ///
622 /// Gets an environment. Returns NOT_FOUND if the environment does not exist.
623 ///
624 /// # Arguments
625 ///
626 /// * `name` - Required. Name of the requested resource, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
627 pub fn environments_get(&self, name: &str) -> UserEnvironmentGetCall<'a, C> {
628 UserEnvironmentGetCall {
629 hub: self.hub,
630 _name: name.to_string(),
631 _delegate: Default::default(),
632 _additional_params: Default::default(),
633 _scopes: Default::default(),
634 }
635 }
636
637 /// Create a builder to help you perform the following task:
638 ///
639 /// Removes a public SSH key from an environment. Clients will no longer be able to connect to the environment using the corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND.
640 ///
641 /// # Arguments
642 ///
643 /// * `request` - No description provided.
644 /// * `environment` - Environment this key should be removed from, e.g. `users/me/environments/default`.
645 pub fn environments_remove_public_key(
646 &self,
647 request: RemovePublicKeyRequest,
648 environment: &str,
649 ) -> UserEnvironmentRemovePublicKeyCall<'a, C> {
650 UserEnvironmentRemovePublicKeyCall {
651 hub: self.hub,
652 _request: request,
653 _environment: environment.to_string(),
654 _delegate: Default::default(),
655 _additional_params: Default::default(),
656 _scopes: Default::default(),
657 }
658 }
659
660 /// Create a builder to help you perform the following task:
661 ///
662 /// Starts an existing environment, allowing clients to connect to it. The returned operation will contain an instance of StartEnvironmentMetadata in its metadata field. Users can wait for the environment to start by polling this operation via GetOperation. Once the environment has finished starting and is ready to accept connections, the operation will contain a StartEnvironmentResponse in its response field.
663 ///
664 /// # Arguments
665 ///
666 /// * `request` - No description provided.
667 /// * `name` - Name of the resource that should be started, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
668 pub fn environments_start(
669 &self,
670 request: StartEnvironmentRequest,
671 name: &str,
672 ) -> UserEnvironmentStartCall<'a, C> {
673 UserEnvironmentStartCall {
674 hub: self.hub,
675 _request: request,
676 _name: name.to_string(),
677 _delegate: Default::default(),
678 _additional_params: Default::default(),
679 _scopes: Default::default(),
680 }
681 }
682}
683
684// ###################
685// CallBuilders ###
686// #################
687
688/// Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`. Clients can use Operations.GetOperation or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to `Code.CANCELLED`.
689///
690/// A builder for the *cancel* method supported by a *operation* resource.
691/// It is not used directly, but through a [`OperationMethods`] instance.
692///
693/// # Example
694///
695/// Instantiate a resource method builder
696///
697/// ```test_harness,no_run
698/// # extern crate hyper;
699/// # extern crate hyper_rustls;
700/// # extern crate google_cloudshell1 as cloudshell1;
701/// use cloudshell1::api::CancelOperationRequest;
702/// # async fn dox() {
703/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
704///
705/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
706/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
707/// # secret,
708/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
709/// # ).build().await.unwrap();
710///
711/// # let client = hyper_util::client::legacy::Client::builder(
712/// # hyper_util::rt::TokioExecutor::new()
713/// # )
714/// # .build(
715/// # hyper_rustls::HttpsConnectorBuilder::new()
716/// # .with_native_roots()
717/// # .unwrap()
718/// # .https_or_http()
719/// # .enable_http1()
720/// # .build()
721/// # );
722/// # let mut hub = CloudShell::new(client, auth);
723/// // As the method needs a request, you would usually fill it with the desired information
724/// // into the respective structure. Some of the parts shown here might not be applicable !
725/// // Values shown here are possibly random and not representative !
726/// let mut req = CancelOperationRequest::default();
727///
728/// // You can configure optional parameters by calling the respective setters at will, and
729/// // execute the final call using `doit()`.
730/// // Values shown here are possibly random and not representative !
731/// let result = hub.operations().cancel(req, "name")
732/// .doit().await;
733/// # }
734/// ```
735pub struct OperationCancelCall<'a, C>
736where
737 C: 'a,
738{
739 hub: &'a CloudShell<C>,
740 _request: CancelOperationRequest,
741 _name: String,
742 _delegate: Option<&'a mut dyn common::Delegate>,
743 _additional_params: HashMap<String, String>,
744 _scopes: BTreeSet<String>,
745}
746
747impl<'a, C> common::CallBuilder for OperationCancelCall<'a, C> {}
748
749impl<'a, C> OperationCancelCall<'a, C>
750where
751 C: common::Connector,
752{
753 /// Perform the operation you have build so far.
754 pub async fn doit(mut self) -> common::Result<(common::Response, Empty)> {
755 use std::borrow::Cow;
756 use std::io::{Read, Seek};
757
758 use common::{url::Params, ToParts};
759 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
760
761 let mut dd = common::DefaultDelegate;
762 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
763 dlg.begin(common::MethodInfo {
764 id: "cloudshell.operations.cancel",
765 http_method: hyper::Method::POST,
766 });
767
768 for &field in ["alt", "name"].iter() {
769 if self._additional_params.contains_key(field) {
770 dlg.finished(false);
771 return Err(common::Error::FieldClash(field));
772 }
773 }
774
775 let mut params = Params::with_capacity(4 + self._additional_params.len());
776 params.push("name", self._name);
777
778 params.extend(self._additional_params.iter());
779
780 params.push("alt", "json");
781 let mut url = self.hub._base_url.clone() + "v1/{+name}:cancel";
782 if self._scopes.is_empty() {
783 self._scopes
784 .insert(Scope::CloudPlatform.as_ref().to_string());
785 }
786
787 #[allow(clippy::single_element_loop)]
788 for &(find_this, param_name) in [("{+name}", "name")].iter() {
789 url = params.uri_replacement(url, param_name, find_this, true);
790 }
791 {
792 let to_remove = ["name"];
793 params.remove_params(&to_remove);
794 }
795
796 let url = params.parse_with_url(&url);
797
798 let mut json_mime_type = mime::APPLICATION_JSON;
799 let mut request_value_reader = {
800 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
801 common::remove_json_null_values(&mut value);
802 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
803 serde_json::to_writer(&mut dst, &value).unwrap();
804 dst
805 };
806 let request_size = request_value_reader
807 .seek(std::io::SeekFrom::End(0))
808 .unwrap();
809 request_value_reader
810 .seek(std::io::SeekFrom::Start(0))
811 .unwrap();
812
813 loop {
814 let token = match self
815 .hub
816 .auth
817 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
818 .await
819 {
820 Ok(token) => token,
821 Err(e) => match dlg.token(e) {
822 Ok(token) => token,
823 Err(e) => {
824 dlg.finished(false);
825 return Err(common::Error::MissingToken(e));
826 }
827 },
828 };
829 request_value_reader
830 .seek(std::io::SeekFrom::Start(0))
831 .unwrap();
832 let mut req_result = {
833 let client = &self.hub.client;
834 dlg.pre_request();
835 let mut req_builder = hyper::Request::builder()
836 .method(hyper::Method::POST)
837 .uri(url.as_str())
838 .header(USER_AGENT, self.hub._user_agent.clone());
839
840 if let Some(token) = token.as_ref() {
841 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
842 }
843
844 let request = req_builder
845 .header(CONTENT_TYPE, json_mime_type.to_string())
846 .header(CONTENT_LENGTH, request_size as u64)
847 .body(common::to_body(
848 request_value_reader.get_ref().clone().into(),
849 ));
850
851 client.request(request.unwrap()).await
852 };
853
854 match req_result {
855 Err(err) => {
856 if let common::Retry::After(d) = dlg.http_error(&err) {
857 sleep(d).await;
858 continue;
859 }
860 dlg.finished(false);
861 return Err(common::Error::HttpError(err));
862 }
863 Ok(res) => {
864 let (mut parts, body) = res.into_parts();
865 let mut body = common::Body::new(body);
866 if !parts.status.is_success() {
867 let bytes = common::to_bytes(body).await.unwrap_or_default();
868 let error = serde_json::from_str(&common::to_string(&bytes));
869 let response = common::to_response(parts, bytes.into());
870
871 if let common::Retry::After(d) =
872 dlg.http_failure(&response, error.as_ref().ok())
873 {
874 sleep(d).await;
875 continue;
876 }
877
878 dlg.finished(false);
879
880 return Err(match error {
881 Ok(value) => common::Error::BadRequest(value),
882 _ => common::Error::Failure(response),
883 });
884 }
885 let response = {
886 let bytes = common::to_bytes(body).await.unwrap_or_default();
887 let encoded = common::to_string(&bytes);
888 match serde_json::from_str(&encoded) {
889 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
890 Err(error) => {
891 dlg.response_json_decode_error(&encoded, &error);
892 return Err(common::Error::JsonDecodeError(
893 encoded.to_string(),
894 error,
895 ));
896 }
897 }
898 };
899
900 dlg.finished(true);
901 return Ok(response);
902 }
903 }
904 }
905 }
906
907 ///
908 /// Sets the *request* property to the given value.
909 ///
910 /// Even though the property as already been set when instantiating this call,
911 /// we provide this method for API completeness.
912 pub fn request(mut self, new_value: CancelOperationRequest) -> OperationCancelCall<'a, C> {
913 self._request = new_value;
914 self
915 }
916 /// The name of the operation resource to be cancelled.
917 ///
918 /// Sets the *name* path property to the given value.
919 ///
920 /// Even though the property as already been set when instantiating this call,
921 /// we provide this method for API completeness.
922 pub fn name(mut self, new_value: &str) -> OperationCancelCall<'a, C> {
923 self._name = new_value.to_string();
924 self
925 }
926 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
927 /// while executing the actual API request.
928 ///
929 /// ````text
930 /// It should be used to handle progress information, and to implement a certain level of resilience.
931 /// ````
932 ///
933 /// Sets the *delegate* property to the given value.
934 pub fn delegate(
935 mut self,
936 new_value: &'a mut dyn common::Delegate,
937 ) -> OperationCancelCall<'a, C> {
938 self._delegate = Some(new_value);
939 self
940 }
941
942 /// Set any additional parameter of the query string used in the request.
943 /// It should be used to set parameters which are not yet available through their own
944 /// setters.
945 ///
946 /// Please note that this method must not be used to set any of the known parameters
947 /// which have their own setter method. If done anyway, the request will fail.
948 ///
949 /// # Additional Parameters
950 ///
951 /// * *$.xgafv* (query-string) - V1 error format.
952 /// * *access_token* (query-string) - OAuth access token.
953 /// * *alt* (query-string) - Data format for response.
954 /// * *callback* (query-string) - JSONP
955 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
956 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
957 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
958 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
959 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
960 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
961 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
962 pub fn param<T>(mut self, name: T, value: T) -> OperationCancelCall<'a, C>
963 where
964 T: AsRef<str>,
965 {
966 self._additional_params
967 .insert(name.as_ref().to_string(), value.as_ref().to_string());
968 self
969 }
970
971 /// Identifies the authorization scope for the method you are building.
972 ///
973 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
974 /// [`Scope::CloudPlatform`].
975 ///
976 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
977 /// tokens for more than one scope.
978 ///
979 /// Usually there is more than one suitable scope to authorize an operation, some of which may
980 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
981 /// sufficient, a read-write scope will do as well.
982 pub fn add_scope<St>(mut self, scope: St) -> OperationCancelCall<'a, C>
983 where
984 St: AsRef<str>,
985 {
986 self._scopes.insert(String::from(scope.as_ref()));
987 self
988 }
989 /// Identifies the authorization scope(s) for the method you are building.
990 ///
991 /// See [`Self::add_scope()`] for details.
992 pub fn add_scopes<I, St>(mut self, scopes: I) -> OperationCancelCall<'a, C>
993 where
994 I: IntoIterator<Item = St>,
995 St: AsRef<str>,
996 {
997 self._scopes
998 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
999 self
1000 }
1001
1002 /// Removes all scopes, and no default scope will be used either.
1003 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1004 /// for details).
1005 pub fn clear_scopes(mut self) -> OperationCancelCall<'a, C> {
1006 self._scopes.clear();
1007 self
1008 }
1009}
1010
1011/// Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns `google.rpc.Code.UNIMPLEMENTED`.
1012///
1013/// A builder for the *delete* method supported by a *operation* resource.
1014/// It is not used directly, but through a [`OperationMethods`] instance.
1015///
1016/// # Example
1017///
1018/// Instantiate a resource method builder
1019///
1020/// ```test_harness,no_run
1021/// # extern crate hyper;
1022/// # extern crate hyper_rustls;
1023/// # extern crate google_cloudshell1 as cloudshell1;
1024/// # async fn dox() {
1025/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1026///
1027/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1028/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1029/// # secret,
1030/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1031/// # ).build().await.unwrap();
1032///
1033/// # let client = hyper_util::client::legacy::Client::builder(
1034/// # hyper_util::rt::TokioExecutor::new()
1035/// # )
1036/// # .build(
1037/// # hyper_rustls::HttpsConnectorBuilder::new()
1038/// # .with_native_roots()
1039/// # .unwrap()
1040/// # .https_or_http()
1041/// # .enable_http1()
1042/// # .build()
1043/// # );
1044/// # let mut hub = CloudShell::new(client, auth);
1045/// // You can configure optional parameters by calling the respective setters at will, and
1046/// // execute the final call using `doit()`.
1047/// // Values shown here are possibly random and not representative !
1048/// let result = hub.operations().delete("name")
1049/// .doit().await;
1050/// # }
1051/// ```
1052pub struct OperationDeleteCall<'a, C>
1053where
1054 C: 'a,
1055{
1056 hub: &'a CloudShell<C>,
1057 _name: String,
1058 _delegate: Option<&'a mut dyn common::Delegate>,
1059 _additional_params: HashMap<String, String>,
1060 _scopes: BTreeSet<String>,
1061}
1062
1063impl<'a, C> common::CallBuilder for OperationDeleteCall<'a, C> {}
1064
1065impl<'a, C> OperationDeleteCall<'a, C>
1066where
1067 C: common::Connector,
1068{
1069 /// Perform the operation you have build so far.
1070 pub async fn doit(mut self) -> common::Result<(common::Response, Empty)> {
1071 use std::borrow::Cow;
1072 use std::io::{Read, Seek};
1073
1074 use common::{url::Params, ToParts};
1075 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1076
1077 let mut dd = common::DefaultDelegate;
1078 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1079 dlg.begin(common::MethodInfo {
1080 id: "cloudshell.operations.delete",
1081 http_method: hyper::Method::DELETE,
1082 });
1083
1084 for &field in ["alt", "name"].iter() {
1085 if self._additional_params.contains_key(field) {
1086 dlg.finished(false);
1087 return Err(common::Error::FieldClash(field));
1088 }
1089 }
1090
1091 let mut params = Params::with_capacity(3 + self._additional_params.len());
1092 params.push("name", self._name);
1093
1094 params.extend(self._additional_params.iter());
1095
1096 params.push("alt", "json");
1097 let mut url = self.hub._base_url.clone() + "v1/{+name}";
1098 if self._scopes.is_empty() {
1099 self._scopes
1100 .insert(Scope::CloudPlatform.as_ref().to_string());
1101 }
1102
1103 #[allow(clippy::single_element_loop)]
1104 for &(find_this, param_name) in [("{+name}", "name")].iter() {
1105 url = params.uri_replacement(url, param_name, find_this, true);
1106 }
1107 {
1108 let to_remove = ["name"];
1109 params.remove_params(&to_remove);
1110 }
1111
1112 let url = params.parse_with_url(&url);
1113
1114 loop {
1115 let token = match self
1116 .hub
1117 .auth
1118 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1119 .await
1120 {
1121 Ok(token) => token,
1122 Err(e) => match dlg.token(e) {
1123 Ok(token) => token,
1124 Err(e) => {
1125 dlg.finished(false);
1126 return Err(common::Error::MissingToken(e));
1127 }
1128 },
1129 };
1130 let mut req_result = {
1131 let client = &self.hub.client;
1132 dlg.pre_request();
1133 let mut req_builder = hyper::Request::builder()
1134 .method(hyper::Method::DELETE)
1135 .uri(url.as_str())
1136 .header(USER_AGENT, self.hub._user_agent.clone());
1137
1138 if let Some(token) = token.as_ref() {
1139 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1140 }
1141
1142 let request = req_builder
1143 .header(CONTENT_LENGTH, 0_u64)
1144 .body(common::to_body::<String>(None));
1145
1146 client.request(request.unwrap()).await
1147 };
1148
1149 match req_result {
1150 Err(err) => {
1151 if let common::Retry::After(d) = dlg.http_error(&err) {
1152 sleep(d).await;
1153 continue;
1154 }
1155 dlg.finished(false);
1156 return Err(common::Error::HttpError(err));
1157 }
1158 Ok(res) => {
1159 let (mut parts, body) = res.into_parts();
1160 let mut body = common::Body::new(body);
1161 if !parts.status.is_success() {
1162 let bytes = common::to_bytes(body).await.unwrap_or_default();
1163 let error = serde_json::from_str(&common::to_string(&bytes));
1164 let response = common::to_response(parts, bytes.into());
1165
1166 if let common::Retry::After(d) =
1167 dlg.http_failure(&response, error.as_ref().ok())
1168 {
1169 sleep(d).await;
1170 continue;
1171 }
1172
1173 dlg.finished(false);
1174
1175 return Err(match error {
1176 Ok(value) => common::Error::BadRequest(value),
1177 _ => common::Error::Failure(response),
1178 });
1179 }
1180 let response = {
1181 let bytes = common::to_bytes(body).await.unwrap_or_default();
1182 let encoded = common::to_string(&bytes);
1183 match serde_json::from_str(&encoded) {
1184 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1185 Err(error) => {
1186 dlg.response_json_decode_error(&encoded, &error);
1187 return Err(common::Error::JsonDecodeError(
1188 encoded.to_string(),
1189 error,
1190 ));
1191 }
1192 }
1193 };
1194
1195 dlg.finished(true);
1196 return Ok(response);
1197 }
1198 }
1199 }
1200 }
1201
1202 /// The name of the operation resource to be deleted.
1203 ///
1204 /// Sets the *name* path property to the given value.
1205 ///
1206 /// Even though the property as already been set when instantiating this call,
1207 /// we provide this method for API completeness.
1208 pub fn name(mut self, new_value: &str) -> OperationDeleteCall<'a, C> {
1209 self._name = new_value.to_string();
1210 self
1211 }
1212 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1213 /// while executing the actual API request.
1214 ///
1215 /// ````text
1216 /// It should be used to handle progress information, and to implement a certain level of resilience.
1217 /// ````
1218 ///
1219 /// Sets the *delegate* property to the given value.
1220 pub fn delegate(
1221 mut self,
1222 new_value: &'a mut dyn common::Delegate,
1223 ) -> OperationDeleteCall<'a, C> {
1224 self._delegate = Some(new_value);
1225 self
1226 }
1227
1228 /// Set any additional parameter of the query string used in the request.
1229 /// It should be used to set parameters which are not yet available through their own
1230 /// setters.
1231 ///
1232 /// Please note that this method must not be used to set any of the known parameters
1233 /// which have their own setter method. If done anyway, the request will fail.
1234 ///
1235 /// # Additional Parameters
1236 ///
1237 /// * *$.xgafv* (query-string) - V1 error format.
1238 /// * *access_token* (query-string) - OAuth access token.
1239 /// * *alt* (query-string) - Data format for response.
1240 /// * *callback* (query-string) - JSONP
1241 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1242 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1243 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1244 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1245 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1246 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1247 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1248 pub fn param<T>(mut self, name: T, value: T) -> OperationDeleteCall<'a, C>
1249 where
1250 T: AsRef<str>,
1251 {
1252 self._additional_params
1253 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1254 self
1255 }
1256
1257 /// Identifies the authorization scope for the method you are building.
1258 ///
1259 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1260 /// [`Scope::CloudPlatform`].
1261 ///
1262 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1263 /// tokens for more than one scope.
1264 ///
1265 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1266 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1267 /// sufficient, a read-write scope will do as well.
1268 pub fn add_scope<St>(mut self, scope: St) -> OperationDeleteCall<'a, C>
1269 where
1270 St: AsRef<str>,
1271 {
1272 self._scopes.insert(String::from(scope.as_ref()));
1273 self
1274 }
1275 /// Identifies the authorization scope(s) for the method you are building.
1276 ///
1277 /// See [`Self::add_scope()`] for details.
1278 pub fn add_scopes<I, St>(mut self, scopes: I) -> OperationDeleteCall<'a, C>
1279 where
1280 I: IntoIterator<Item = St>,
1281 St: AsRef<str>,
1282 {
1283 self._scopes
1284 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1285 self
1286 }
1287
1288 /// Removes all scopes, and no default scope will be used either.
1289 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1290 /// for details).
1291 pub fn clear_scopes(mut self) -> OperationDeleteCall<'a, C> {
1292 self._scopes.clear();
1293 self
1294 }
1295}
1296
1297/// Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.
1298///
1299/// A builder for the *get* method supported by a *operation* resource.
1300/// It is not used directly, but through a [`OperationMethods`] instance.
1301///
1302/// # Example
1303///
1304/// Instantiate a resource method builder
1305///
1306/// ```test_harness,no_run
1307/// # extern crate hyper;
1308/// # extern crate hyper_rustls;
1309/// # extern crate google_cloudshell1 as cloudshell1;
1310/// # async fn dox() {
1311/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1312///
1313/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1314/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1315/// # secret,
1316/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1317/// # ).build().await.unwrap();
1318///
1319/// # let client = hyper_util::client::legacy::Client::builder(
1320/// # hyper_util::rt::TokioExecutor::new()
1321/// # )
1322/// # .build(
1323/// # hyper_rustls::HttpsConnectorBuilder::new()
1324/// # .with_native_roots()
1325/// # .unwrap()
1326/// # .https_or_http()
1327/// # .enable_http1()
1328/// # .build()
1329/// # );
1330/// # let mut hub = CloudShell::new(client, auth);
1331/// // You can configure optional parameters by calling the respective setters at will, and
1332/// // execute the final call using `doit()`.
1333/// // Values shown here are possibly random and not representative !
1334/// let result = hub.operations().get("name")
1335/// .doit().await;
1336/// # }
1337/// ```
1338pub struct OperationGetCall<'a, C>
1339where
1340 C: 'a,
1341{
1342 hub: &'a CloudShell<C>,
1343 _name: String,
1344 _delegate: Option<&'a mut dyn common::Delegate>,
1345 _additional_params: HashMap<String, String>,
1346 _scopes: BTreeSet<String>,
1347}
1348
1349impl<'a, C> common::CallBuilder for OperationGetCall<'a, C> {}
1350
1351impl<'a, C> OperationGetCall<'a, C>
1352where
1353 C: common::Connector,
1354{
1355 /// Perform the operation you have build so far.
1356 pub async fn doit(mut self) -> common::Result<(common::Response, Operation)> {
1357 use std::borrow::Cow;
1358 use std::io::{Read, Seek};
1359
1360 use common::{url::Params, ToParts};
1361 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1362
1363 let mut dd = common::DefaultDelegate;
1364 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1365 dlg.begin(common::MethodInfo {
1366 id: "cloudshell.operations.get",
1367 http_method: hyper::Method::GET,
1368 });
1369
1370 for &field in ["alt", "name"].iter() {
1371 if self._additional_params.contains_key(field) {
1372 dlg.finished(false);
1373 return Err(common::Error::FieldClash(field));
1374 }
1375 }
1376
1377 let mut params = Params::with_capacity(3 + self._additional_params.len());
1378 params.push("name", self._name);
1379
1380 params.extend(self._additional_params.iter());
1381
1382 params.push("alt", "json");
1383 let mut url = self.hub._base_url.clone() + "v1/{+name}";
1384 if self._scopes.is_empty() {
1385 self._scopes
1386 .insert(Scope::CloudPlatform.as_ref().to_string());
1387 }
1388
1389 #[allow(clippy::single_element_loop)]
1390 for &(find_this, param_name) in [("{+name}", "name")].iter() {
1391 url = params.uri_replacement(url, param_name, find_this, true);
1392 }
1393 {
1394 let to_remove = ["name"];
1395 params.remove_params(&to_remove);
1396 }
1397
1398 let url = params.parse_with_url(&url);
1399
1400 loop {
1401 let token = match self
1402 .hub
1403 .auth
1404 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1405 .await
1406 {
1407 Ok(token) => token,
1408 Err(e) => match dlg.token(e) {
1409 Ok(token) => token,
1410 Err(e) => {
1411 dlg.finished(false);
1412 return Err(common::Error::MissingToken(e));
1413 }
1414 },
1415 };
1416 let mut req_result = {
1417 let client = &self.hub.client;
1418 dlg.pre_request();
1419 let mut req_builder = hyper::Request::builder()
1420 .method(hyper::Method::GET)
1421 .uri(url.as_str())
1422 .header(USER_AGENT, self.hub._user_agent.clone());
1423
1424 if let Some(token) = token.as_ref() {
1425 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1426 }
1427
1428 let request = req_builder
1429 .header(CONTENT_LENGTH, 0_u64)
1430 .body(common::to_body::<String>(None));
1431
1432 client.request(request.unwrap()).await
1433 };
1434
1435 match req_result {
1436 Err(err) => {
1437 if let common::Retry::After(d) = dlg.http_error(&err) {
1438 sleep(d).await;
1439 continue;
1440 }
1441 dlg.finished(false);
1442 return Err(common::Error::HttpError(err));
1443 }
1444 Ok(res) => {
1445 let (mut parts, body) = res.into_parts();
1446 let mut body = common::Body::new(body);
1447 if !parts.status.is_success() {
1448 let bytes = common::to_bytes(body).await.unwrap_or_default();
1449 let error = serde_json::from_str(&common::to_string(&bytes));
1450 let response = common::to_response(parts, bytes.into());
1451
1452 if let common::Retry::After(d) =
1453 dlg.http_failure(&response, error.as_ref().ok())
1454 {
1455 sleep(d).await;
1456 continue;
1457 }
1458
1459 dlg.finished(false);
1460
1461 return Err(match error {
1462 Ok(value) => common::Error::BadRequest(value),
1463 _ => common::Error::Failure(response),
1464 });
1465 }
1466 let response = {
1467 let bytes = common::to_bytes(body).await.unwrap_or_default();
1468 let encoded = common::to_string(&bytes);
1469 match serde_json::from_str(&encoded) {
1470 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1471 Err(error) => {
1472 dlg.response_json_decode_error(&encoded, &error);
1473 return Err(common::Error::JsonDecodeError(
1474 encoded.to_string(),
1475 error,
1476 ));
1477 }
1478 }
1479 };
1480
1481 dlg.finished(true);
1482 return Ok(response);
1483 }
1484 }
1485 }
1486 }
1487
1488 /// The name of the operation resource.
1489 ///
1490 /// Sets the *name* path property to the given value.
1491 ///
1492 /// Even though the property as already been set when instantiating this call,
1493 /// we provide this method for API completeness.
1494 pub fn name(mut self, new_value: &str) -> OperationGetCall<'a, C> {
1495 self._name = new_value.to_string();
1496 self
1497 }
1498 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1499 /// while executing the actual API request.
1500 ///
1501 /// ````text
1502 /// It should be used to handle progress information, and to implement a certain level of resilience.
1503 /// ````
1504 ///
1505 /// Sets the *delegate* property to the given value.
1506 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> OperationGetCall<'a, C> {
1507 self._delegate = Some(new_value);
1508 self
1509 }
1510
1511 /// Set any additional parameter of the query string used in the request.
1512 /// It should be used to set parameters which are not yet available through their own
1513 /// setters.
1514 ///
1515 /// Please note that this method must not be used to set any of the known parameters
1516 /// which have their own setter method. If done anyway, the request will fail.
1517 ///
1518 /// # Additional Parameters
1519 ///
1520 /// * *$.xgafv* (query-string) - V1 error format.
1521 /// * *access_token* (query-string) - OAuth access token.
1522 /// * *alt* (query-string) - Data format for response.
1523 /// * *callback* (query-string) - JSONP
1524 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1525 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1526 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1527 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1528 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1529 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1530 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1531 pub fn param<T>(mut self, name: T, value: T) -> OperationGetCall<'a, C>
1532 where
1533 T: AsRef<str>,
1534 {
1535 self._additional_params
1536 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1537 self
1538 }
1539
1540 /// Identifies the authorization scope for the method you are building.
1541 ///
1542 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1543 /// [`Scope::CloudPlatform`].
1544 ///
1545 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1546 /// tokens for more than one scope.
1547 ///
1548 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1549 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1550 /// sufficient, a read-write scope will do as well.
1551 pub fn add_scope<St>(mut self, scope: St) -> OperationGetCall<'a, C>
1552 where
1553 St: AsRef<str>,
1554 {
1555 self._scopes.insert(String::from(scope.as_ref()));
1556 self
1557 }
1558 /// Identifies the authorization scope(s) for the method you are building.
1559 ///
1560 /// See [`Self::add_scope()`] for details.
1561 pub fn add_scopes<I, St>(mut self, scopes: I) -> OperationGetCall<'a, C>
1562 where
1563 I: IntoIterator<Item = St>,
1564 St: AsRef<str>,
1565 {
1566 self._scopes
1567 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1568 self
1569 }
1570
1571 /// Removes all scopes, and no default scope will be used either.
1572 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1573 /// for details).
1574 pub fn clear_scopes(mut self) -> OperationGetCall<'a, C> {
1575 self._scopes.clear();
1576 self
1577 }
1578}
1579
1580/// Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns `UNIMPLEMENTED`.
1581///
1582/// A builder for the *list* method supported by a *operation* resource.
1583/// It is not used directly, but through a [`OperationMethods`] instance.
1584///
1585/// # Example
1586///
1587/// Instantiate a resource method builder
1588///
1589/// ```test_harness,no_run
1590/// # extern crate hyper;
1591/// # extern crate hyper_rustls;
1592/// # extern crate google_cloudshell1 as cloudshell1;
1593/// # async fn dox() {
1594/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1595///
1596/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1597/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1598/// # secret,
1599/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1600/// # ).build().await.unwrap();
1601///
1602/// # let client = hyper_util::client::legacy::Client::builder(
1603/// # hyper_util::rt::TokioExecutor::new()
1604/// # )
1605/// # .build(
1606/// # hyper_rustls::HttpsConnectorBuilder::new()
1607/// # .with_native_roots()
1608/// # .unwrap()
1609/// # .https_or_http()
1610/// # .enable_http1()
1611/// # .build()
1612/// # );
1613/// # let mut hub = CloudShell::new(client, auth);
1614/// // You can configure optional parameters by calling the respective setters at will, and
1615/// // execute the final call using `doit()`.
1616/// // Values shown here are possibly random and not representative !
1617/// let result = hub.operations().list("name")
1618/// .page_token("eos")
1619/// .page_size(-4)
1620/// .filter("ea")
1621/// .doit().await;
1622/// # }
1623/// ```
1624pub struct OperationListCall<'a, C>
1625where
1626 C: 'a,
1627{
1628 hub: &'a CloudShell<C>,
1629 _name: String,
1630 _page_token: Option<String>,
1631 _page_size: Option<i32>,
1632 _filter: Option<String>,
1633 _delegate: Option<&'a mut dyn common::Delegate>,
1634 _additional_params: HashMap<String, String>,
1635 _scopes: BTreeSet<String>,
1636}
1637
1638impl<'a, C> common::CallBuilder for OperationListCall<'a, C> {}
1639
1640impl<'a, C> OperationListCall<'a, C>
1641where
1642 C: common::Connector,
1643{
1644 /// Perform the operation you have build so far.
1645 pub async fn doit(mut self) -> common::Result<(common::Response, ListOperationsResponse)> {
1646 use std::borrow::Cow;
1647 use std::io::{Read, Seek};
1648
1649 use common::{url::Params, ToParts};
1650 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1651
1652 let mut dd = common::DefaultDelegate;
1653 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1654 dlg.begin(common::MethodInfo {
1655 id: "cloudshell.operations.list",
1656 http_method: hyper::Method::GET,
1657 });
1658
1659 for &field in ["alt", "name", "pageToken", "pageSize", "filter"].iter() {
1660 if self._additional_params.contains_key(field) {
1661 dlg.finished(false);
1662 return Err(common::Error::FieldClash(field));
1663 }
1664 }
1665
1666 let mut params = Params::with_capacity(6 + self._additional_params.len());
1667 params.push("name", self._name);
1668 if let Some(value) = self._page_token.as_ref() {
1669 params.push("pageToken", value);
1670 }
1671 if let Some(value) = self._page_size.as_ref() {
1672 params.push("pageSize", value.to_string());
1673 }
1674 if let Some(value) = self._filter.as_ref() {
1675 params.push("filter", value);
1676 }
1677
1678 params.extend(self._additional_params.iter());
1679
1680 params.push("alt", "json");
1681 let mut url = self.hub._base_url.clone() + "v1/{+name}";
1682 if self._scopes.is_empty() {
1683 self._scopes
1684 .insert(Scope::CloudPlatform.as_ref().to_string());
1685 }
1686
1687 #[allow(clippy::single_element_loop)]
1688 for &(find_this, param_name) in [("{+name}", "name")].iter() {
1689 url = params.uri_replacement(url, param_name, find_this, true);
1690 }
1691 {
1692 let to_remove = ["name"];
1693 params.remove_params(&to_remove);
1694 }
1695
1696 let url = params.parse_with_url(&url);
1697
1698 loop {
1699 let token = match self
1700 .hub
1701 .auth
1702 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1703 .await
1704 {
1705 Ok(token) => token,
1706 Err(e) => match dlg.token(e) {
1707 Ok(token) => token,
1708 Err(e) => {
1709 dlg.finished(false);
1710 return Err(common::Error::MissingToken(e));
1711 }
1712 },
1713 };
1714 let mut req_result = {
1715 let client = &self.hub.client;
1716 dlg.pre_request();
1717 let mut req_builder = hyper::Request::builder()
1718 .method(hyper::Method::GET)
1719 .uri(url.as_str())
1720 .header(USER_AGENT, self.hub._user_agent.clone());
1721
1722 if let Some(token) = token.as_ref() {
1723 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1724 }
1725
1726 let request = req_builder
1727 .header(CONTENT_LENGTH, 0_u64)
1728 .body(common::to_body::<String>(None));
1729
1730 client.request(request.unwrap()).await
1731 };
1732
1733 match req_result {
1734 Err(err) => {
1735 if let common::Retry::After(d) = dlg.http_error(&err) {
1736 sleep(d).await;
1737 continue;
1738 }
1739 dlg.finished(false);
1740 return Err(common::Error::HttpError(err));
1741 }
1742 Ok(res) => {
1743 let (mut parts, body) = res.into_parts();
1744 let mut body = common::Body::new(body);
1745 if !parts.status.is_success() {
1746 let bytes = common::to_bytes(body).await.unwrap_or_default();
1747 let error = serde_json::from_str(&common::to_string(&bytes));
1748 let response = common::to_response(parts, bytes.into());
1749
1750 if let common::Retry::After(d) =
1751 dlg.http_failure(&response, error.as_ref().ok())
1752 {
1753 sleep(d).await;
1754 continue;
1755 }
1756
1757 dlg.finished(false);
1758
1759 return Err(match error {
1760 Ok(value) => common::Error::BadRequest(value),
1761 _ => common::Error::Failure(response),
1762 });
1763 }
1764 let response = {
1765 let bytes = common::to_bytes(body).await.unwrap_or_default();
1766 let encoded = common::to_string(&bytes);
1767 match serde_json::from_str(&encoded) {
1768 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1769 Err(error) => {
1770 dlg.response_json_decode_error(&encoded, &error);
1771 return Err(common::Error::JsonDecodeError(
1772 encoded.to_string(),
1773 error,
1774 ));
1775 }
1776 }
1777 };
1778
1779 dlg.finished(true);
1780 return Ok(response);
1781 }
1782 }
1783 }
1784 }
1785
1786 /// The name of the operation's parent resource.
1787 ///
1788 /// Sets the *name* path property to the given value.
1789 ///
1790 /// Even though the property as already been set when instantiating this call,
1791 /// we provide this method for API completeness.
1792 pub fn name(mut self, new_value: &str) -> OperationListCall<'a, C> {
1793 self._name = new_value.to_string();
1794 self
1795 }
1796 /// The standard list page token.
1797 ///
1798 /// Sets the *page token* query property to the given value.
1799 pub fn page_token(mut self, new_value: &str) -> OperationListCall<'a, C> {
1800 self._page_token = Some(new_value.to_string());
1801 self
1802 }
1803 /// The standard list page size.
1804 ///
1805 /// Sets the *page size* query property to the given value.
1806 pub fn page_size(mut self, new_value: i32) -> OperationListCall<'a, C> {
1807 self._page_size = Some(new_value);
1808 self
1809 }
1810 /// The standard list filter.
1811 ///
1812 /// Sets the *filter* query property to the given value.
1813 pub fn filter(mut self, new_value: &str) -> OperationListCall<'a, C> {
1814 self._filter = Some(new_value.to_string());
1815 self
1816 }
1817 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1818 /// while executing the actual API request.
1819 ///
1820 /// ````text
1821 /// It should be used to handle progress information, and to implement a certain level of resilience.
1822 /// ````
1823 ///
1824 /// Sets the *delegate* property to the given value.
1825 pub fn delegate(mut self, new_value: &'a mut dyn common::Delegate) -> OperationListCall<'a, C> {
1826 self._delegate = Some(new_value);
1827 self
1828 }
1829
1830 /// Set any additional parameter of the query string used in the request.
1831 /// It should be used to set parameters which are not yet available through their own
1832 /// setters.
1833 ///
1834 /// Please note that this method must not be used to set any of the known parameters
1835 /// which have their own setter method. If done anyway, the request will fail.
1836 ///
1837 /// # Additional Parameters
1838 ///
1839 /// * *$.xgafv* (query-string) - V1 error format.
1840 /// * *access_token* (query-string) - OAuth access token.
1841 /// * *alt* (query-string) - Data format for response.
1842 /// * *callback* (query-string) - JSONP
1843 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1844 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
1845 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1846 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1847 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
1848 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1849 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1850 pub fn param<T>(mut self, name: T, value: T) -> OperationListCall<'a, C>
1851 where
1852 T: AsRef<str>,
1853 {
1854 self._additional_params
1855 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1856 self
1857 }
1858
1859 /// Identifies the authorization scope for the method you are building.
1860 ///
1861 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1862 /// [`Scope::CloudPlatform`].
1863 ///
1864 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1865 /// tokens for more than one scope.
1866 ///
1867 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1868 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1869 /// sufficient, a read-write scope will do as well.
1870 pub fn add_scope<St>(mut self, scope: St) -> OperationListCall<'a, C>
1871 where
1872 St: AsRef<str>,
1873 {
1874 self._scopes.insert(String::from(scope.as_ref()));
1875 self
1876 }
1877 /// Identifies the authorization scope(s) for the method you are building.
1878 ///
1879 /// See [`Self::add_scope()`] for details.
1880 pub fn add_scopes<I, St>(mut self, scopes: I) -> OperationListCall<'a, C>
1881 where
1882 I: IntoIterator<Item = St>,
1883 St: AsRef<str>,
1884 {
1885 self._scopes
1886 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1887 self
1888 }
1889
1890 /// Removes all scopes, and no default scope will be used either.
1891 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1892 /// for details).
1893 pub fn clear_scopes(mut self) -> OperationListCall<'a, C> {
1894 self._scopes.clear();
1895 self
1896 }
1897}
1898
1899/// Adds a public SSH key to an environment, allowing clients with the corresponding private key to connect to that environment via SSH. If a key with the same content already exists, this will error with ALREADY_EXISTS.
1900///
1901/// A builder for the *environments.addPublicKey* method supported by a *user* resource.
1902/// It is not used directly, but through a [`UserMethods`] instance.
1903///
1904/// # Example
1905///
1906/// Instantiate a resource method builder
1907///
1908/// ```test_harness,no_run
1909/// # extern crate hyper;
1910/// # extern crate hyper_rustls;
1911/// # extern crate google_cloudshell1 as cloudshell1;
1912/// use cloudshell1::api::AddPublicKeyRequest;
1913/// # async fn dox() {
1914/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1915///
1916/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1917/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
1918/// # secret,
1919/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1920/// # ).build().await.unwrap();
1921///
1922/// # let client = hyper_util::client::legacy::Client::builder(
1923/// # hyper_util::rt::TokioExecutor::new()
1924/// # )
1925/// # .build(
1926/// # hyper_rustls::HttpsConnectorBuilder::new()
1927/// # .with_native_roots()
1928/// # .unwrap()
1929/// # .https_or_http()
1930/// # .enable_http1()
1931/// # .build()
1932/// # );
1933/// # let mut hub = CloudShell::new(client, auth);
1934/// // As the method needs a request, you would usually fill it with the desired information
1935/// // into the respective structure. Some of the parts shown here might not be applicable !
1936/// // Values shown here are possibly random and not representative !
1937/// let mut req = AddPublicKeyRequest::default();
1938///
1939/// // You can configure optional parameters by calling the respective setters at will, and
1940/// // execute the final call using `doit()`.
1941/// // Values shown here are possibly random and not representative !
1942/// let result = hub.users().environments_add_public_key(req, "environment")
1943/// .doit().await;
1944/// # }
1945/// ```
1946pub struct UserEnvironmentAddPublicKeyCall<'a, C>
1947where
1948 C: 'a,
1949{
1950 hub: &'a CloudShell<C>,
1951 _request: AddPublicKeyRequest,
1952 _environment: String,
1953 _delegate: Option<&'a mut dyn common::Delegate>,
1954 _additional_params: HashMap<String, String>,
1955 _scopes: BTreeSet<String>,
1956}
1957
1958impl<'a, C> common::CallBuilder for UserEnvironmentAddPublicKeyCall<'a, C> {}
1959
1960impl<'a, C> UserEnvironmentAddPublicKeyCall<'a, C>
1961where
1962 C: common::Connector,
1963{
1964 /// Perform the operation you have build so far.
1965 pub async fn doit(mut self) -> common::Result<(common::Response, Operation)> {
1966 use std::borrow::Cow;
1967 use std::io::{Read, Seek};
1968
1969 use common::{url::Params, ToParts};
1970 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1971
1972 let mut dd = common::DefaultDelegate;
1973 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1974 dlg.begin(common::MethodInfo {
1975 id: "cloudshell.users.environments.addPublicKey",
1976 http_method: hyper::Method::POST,
1977 });
1978
1979 for &field in ["alt", "environment"].iter() {
1980 if self._additional_params.contains_key(field) {
1981 dlg.finished(false);
1982 return Err(common::Error::FieldClash(field));
1983 }
1984 }
1985
1986 let mut params = Params::with_capacity(4 + self._additional_params.len());
1987 params.push("environment", self._environment);
1988
1989 params.extend(self._additional_params.iter());
1990
1991 params.push("alt", "json");
1992 let mut url = self.hub._base_url.clone() + "v1/{+environment}:addPublicKey";
1993 if self._scopes.is_empty() {
1994 self._scopes
1995 .insert(Scope::CloudPlatform.as_ref().to_string());
1996 }
1997
1998 #[allow(clippy::single_element_loop)]
1999 for &(find_this, param_name) in [("{+environment}", "environment")].iter() {
2000 url = params.uri_replacement(url, param_name, find_this, true);
2001 }
2002 {
2003 let to_remove = ["environment"];
2004 params.remove_params(&to_remove);
2005 }
2006
2007 let url = params.parse_with_url(&url);
2008
2009 let mut json_mime_type = mime::APPLICATION_JSON;
2010 let mut request_value_reader = {
2011 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2012 common::remove_json_null_values(&mut value);
2013 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2014 serde_json::to_writer(&mut dst, &value).unwrap();
2015 dst
2016 };
2017 let request_size = request_value_reader
2018 .seek(std::io::SeekFrom::End(0))
2019 .unwrap();
2020 request_value_reader
2021 .seek(std::io::SeekFrom::Start(0))
2022 .unwrap();
2023
2024 loop {
2025 let token = match self
2026 .hub
2027 .auth
2028 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2029 .await
2030 {
2031 Ok(token) => token,
2032 Err(e) => match dlg.token(e) {
2033 Ok(token) => token,
2034 Err(e) => {
2035 dlg.finished(false);
2036 return Err(common::Error::MissingToken(e));
2037 }
2038 },
2039 };
2040 request_value_reader
2041 .seek(std::io::SeekFrom::Start(0))
2042 .unwrap();
2043 let mut req_result = {
2044 let client = &self.hub.client;
2045 dlg.pre_request();
2046 let mut req_builder = hyper::Request::builder()
2047 .method(hyper::Method::POST)
2048 .uri(url.as_str())
2049 .header(USER_AGENT, self.hub._user_agent.clone());
2050
2051 if let Some(token) = token.as_ref() {
2052 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2053 }
2054
2055 let request = req_builder
2056 .header(CONTENT_TYPE, json_mime_type.to_string())
2057 .header(CONTENT_LENGTH, request_size as u64)
2058 .body(common::to_body(
2059 request_value_reader.get_ref().clone().into(),
2060 ));
2061
2062 client.request(request.unwrap()).await
2063 };
2064
2065 match req_result {
2066 Err(err) => {
2067 if let common::Retry::After(d) = dlg.http_error(&err) {
2068 sleep(d).await;
2069 continue;
2070 }
2071 dlg.finished(false);
2072 return Err(common::Error::HttpError(err));
2073 }
2074 Ok(res) => {
2075 let (mut parts, body) = res.into_parts();
2076 let mut body = common::Body::new(body);
2077 if !parts.status.is_success() {
2078 let bytes = common::to_bytes(body).await.unwrap_or_default();
2079 let error = serde_json::from_str(&common::to_string(&bytes));
2080 let response = common::to_response(parts, bytes.into());
2081
2082 if let common::Retry::After(d) =
2083 dlg.http_failure(&response, error.as_ref().ok())
2084 {
2085 sleep(d).await;
2086 continue;
2087 }
2088
2089 dlg.finished(false);
2090
2091 return Err(match error {
2092 Ok(value) => common::Error::BadRequest(value),
2093 _ => common::Error::Failure(response),
2094 });
2095 }
2096 let response = {
2097 let bytes = common::to_bytes(body).await.unwrap_or_default();
2098 let encoded = common::to_string(&bytes);
2099 match serde_json::from_str(&encoded) {
2100 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2101 Err(error) => {
2102 dlg.response_json_decode_error(&encoded, &error);
2103 return Err(common::Error::JsonDecodeError(
2104 encoded.to_string(),
2105 error,
2106 ));
2107 }
2108 }
2109 };
2110
2111 dlg.finished(true);
2112 return Ok(response);
2113 }
2114 }
2115 }
2116 }
2117
2118 ///
2119 /// Sets the *request* property to the given value.
2120 ///
2121 /// Even though the property as already been set when instantiating this call,
2122 /// we provide this method for API completeness.
2123 pub fn request(
2124 mut self,
2125 new_value: AddPublicKeyRequest,
2126 ) -> UserEnvironmentAddPublicKeyCall<'a, C> {
2127 self._request = new_value;
2128 self
2129 }
2130 /// Environment this key should be added to, e.g. `users/me/environments/default`.
2131 ///
2132 /// Sets the *environment* path property to the given value.
2133 ///
2134 /// Even though the property as already been set when instantiating this call,
2135 /// we provide this method for API completeness.
2136 pub fn environment(mut self, new_value: &str) -> UserEnvironmentAddPublicKeyCall<'a, C> {
2137 self._environment = new_value.to_string();
2138 self
2139 }
2140 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2141 /// while executing the actual API request.
2142 ///
2143 /// ````text
2144 /// It should be used to handle progress information, and to implement a certain level of resilience.
2145 /// ````
2146 ///
2147 /// Sets the *delegate* property to the given value.
2148 pub fn delegate(
2149 mut self,
2150 new_value: &'a mut dyn common::Delegate,
2151 ) -> UserEnvironmentAddPublicKeyCall<'a, C> {
2152 self._delegate = Some(new_value);
2153 self
2154 }
2155
2156 /// Set any additional parameter of the query string used in the request.
2157 /// It should be used to set parameters which are not yet available through their own
2158 /// setters.
2159 ///
2160 /// Please note that this method must not be used to set any of the known parameters
2161 /// which have their own setter method. If done anyway, the request will fail.
2162 ///
2163 /// # Additional Parameters
2164 ///
2165 /// * *$.xgafv* (query-string) - V1 error format.
2166 /// * *access_token* (query-string) - OAuth access token.
2167 /// * *alt* (query-string) - Data format for response.
2168 /// * *callback* (query-string) - JSONP
2169 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2170 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2171 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2172 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2173 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
2174 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2175 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2176 pub fn param<T>(mut self, name: T, value: T) -> UserEnvironmentAddPublicKeyCall<'a, C>
2177 where
2178 T: AsRef<str>,
2179 {
2180 self._additional_params
2181 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2182 self
2183 }
2184
2185 /// Identifies the authorization scope for the method you are building.
2186 ///
2187 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2188 /// [`Scope::CloudPlatform`].
2189 ///
2190 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2191 /// tokens for more than one scope.
2192 ///
2193 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2194 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2195 /// sufficient, a read-write scope will do as well.
2196 pub fn add_scope<St>(mut self, scope: St) -> UserEnvironmentAddPublicKeyCall<'a, C>
2197 where
2198 St: AsRef<str>,
2199 {
2200 self._scopes.insert(String::from(scope.as_ref()));
2201 self
2202 }
2203 /// Identifies the authorization scope(s) for the method you are building.
2204 ///
2205 /// See [`Self::add_scope()`] for details.
2206 pub fn add_scopes<I, St>(mut self, scopes: I) -> UserEnvironmentAddPublicKeyCall<'a, C>
2207 where
2208 I: IntoIterator<Item = St>,
2209 St: AsRef<str>,
2210 {
2211 self._scopes
2212 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2213 self
2214 }
2215
2216 /// Removes all scopes, and no default scope will be used either.
2217 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2218 /// for details).
2219 pub fn clear_scopes(mut self) -> UserEnvironmentAddPublicKeyCall<'a, C> {
2220 self._scopes.clear();
2221 self
2222 }
2223}
2224
2225/// Sends OAuth credentials to a running environment on behalf of a user. When this completes, the environment will be authorized to run various Google Cloud command line tools without requiring the user to manually authenticate.
2226///
2227/// A builder for the *environments.authorize* method supported by a *user* resource.
2228/// It is not used directly, but through a [`UserMethods`] instance.
2229///
2230/// # Example
2231///
2232/// Instantiate a resource method builder
2233///
2234/// ```test_harness,no_run
2235/// # extern crate hyper;
2236/// # extern crate hyper_rustls;
2237/// # extern crate google_cloudshell1 as cloudshell1;
2238/// use cloudshell1::api::AuthorizeEnvironmentRequest;
2239/// # async fn dox() {
2240/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2241///
2242/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2243/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2244/// # secret,
2245/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2246/// # ).build().await.unwrap();
2247///
2248/// # let client = hyper_util::client::legacy::Client::builder(
2249/// # hyper_util::rt::TokioExecutor::new()
2250/// # )
2251/// # .build(
2252/// # hyper_rustls::HttpsConnectorBuilder::new()
2253/// # .with_native_roots()
2254/// # .unwrap()
2255/// # .https_or_http()
2256/// # .enable_http1()
2257/// # .build()
2258/// # );
2259/// # let mut hub = CloudShell::new(client, auth);
2260/// // As the method needs a request, you would usually fill it with the desired information
2261/// // into the respective structure. Some of the parts shown here might not be applicable !
2262/// // Values shown here are possibly random and not representative !
2263/// let mut req = AuthorizeEnvironmentRequest::default();
2264///
2265/// // You can configure optional parameters by calling the respective setters at will, and
2266/// // execute the final call using `doit()`.
2267/// // Values shown here are possibly random and not representative !
2268/// let result = hub.users().environments_authorize(req, "name")
2269/// .doit().await;
2270/// # }
2271/// ```
2272pub struct UserEnvironmentAuthorizeCall<'a, C>
2273where
2274 C: 'a,
2275{
2276 hub: &'a CloudShell<C>,
2277 _request: AuthorizeEnvironmentRequest,
2278 _name: String,
2279 _delegate: Option<&'a mut dyn common::Delegate>,
2280 _additional_params: HashMap<String, String>,
2281 _scopes: BTreeSet<String>,
2282}
2283
2284impl<'a, C> common::CallBuilder for UserEnvironmentAuthorizeCall<'a, C> {}
2285
2286impl<'a, C> UserEnvironmentAuthorizeCall<'a, C>
2287where
2288 C: common::Connector,
2289{
2290 /// Perform the operation you have build so far.
2291 pub async fn doit(mut self) -> common::Result<(common::Response, Operation)> {
2292 use std::borrow::Cow;
2293 use std::io::{Read, Seek};
2294
2295 use common::{url::Params, ToParts};
2296 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2297
2298 let mut dd = common::DefaultDelegate;
2299 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2300 dlg.begin(common::MethodInfo {
2301 id: "cloudshell.users.environments.authorize",
2302 http_method: hyper::Method::POST,
2303 });
2304
2305 for &field in ["alt", "name"].iter() {
2306 if self._additional_params.contains_key(field) {
2307 dlg.finished(false);
2308 return Err(common::Error::FieldClash(field));
2309 }
2310 }
2311
2312 let mut params = Params::with_capacity(4 + self._additional_params.len());
2313 params.push("name", self._name);
2314
2315 params.extend(self._additional_params.iter());
2316
2317 params.push("alt", "json");
2318 let mut url = self.hub._base_url.clone() + "v1/{+name}:authorize";
2319 if self._scopes.is_empty() {
2320 self._scopes
2321 .insert(Scope::CloudPlatform.as_ref().to_string());
2322 }
2323
2324 #[allow(clippy::single_element_loop)]
2325 for &(find_this, param_name) in [("{+name}", "name")].iter() {
2326 url = params.uri_replacement(url, param_name, find_this, true);
2327 }
2328 {
2329 let to_remove = ["name"];
2330 params.remove_params(&to_remove);
2331 }
2332
2333 let url = params.parse_with_url(&url);
2334
2335 let mut json_mime_type = mime::APPLICATION_JSON;
2336 let mut request_value_reader = {
2337 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2338 common::remove_json_null_values(&mut value);
2339 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2340 serde_json::to_writer(&mut dst, &value).unwrap();
2341 dst
2342 };
2343 let request_size = request_value_reader
2344 .seek(std::io::SeekFrom::End(0))
2345 .unwrap();
2346 request_value_reader
2347 .seek(std::io::SeekFrom::Start(0))
2348 .unwrap();
2349
2350 loop {
2351 let token = match self
2352 .hub
2353 .auth
2354 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2355 .await
2356 {
2357 Ok(token) => token,
2358 Err(e) => match dlg.token(e) {
2359 Ok(token) => token,
2360 Err(e) => {
2361 dlg.finished(false);
2362 return Err(common::Error::MissingToken(e));
2363 }
2364 },
2365 };
2366 request_value_reader
2367 .seek(std::io::SeekFrom::Start(0))
2368 .unwrap();
2369 let mut req_result = {
2370 let client = &self.hub.client;
2371 dlg.pre_request();
2372 let mut req_builder = hyper::Request::builder()
2373 .method(hyper::Method::POST)
2374 .uri(url.as_str())
2375 .header(USER_AGENT, self.hub._user_agent.clone());
2376
2377 if let Some(token) = token.as_ref() {
2378 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2379 }
2380
2381 let request = req_builder
2382 .header(CONTENT_TYPE, json_mime_type.to_string())
2383 .header(CONTENT_LENGTH, request_size as u64)
2384 .body(common::to_body(
2385 request_value_reader.get_ref().clone().into(),
2386 ));
2387
2388 client.request(request.unwrap()).await
2389 };
2390
2391 match req_result {
2392 Err(err) => {
2393 if let common::Retry::After(d) = dlg.http_error(&err) {
2394 sleep(d).await;
2395 continue;
2396 }
2397 dlg.finished(false);
2398 return Err(common::Error::HttpError(err));
2399 }
2400 Ok(res) => {
2401 let (mut parts, body) = res.into_parts();
2402 let mut body = common::Body::new(body);
2403 if !parts.status.is_success() {
2404 let bytes = common::to_bytes(body).await.unwrap_or_default();
2405 let error = serde_json::from_str(&common::to_string(&bytes));
2406 let response = common::to_response(parts, bytes.into());
2407
2408 if let common::Retry::After(d) =
2409 dlg.http_failure(&response, error.as_ref().ok())
2410 {
2411 sleep(d).await;
2412 continue;
2413 }
2414
2415 dlg.finished(false);
2416
2417 return Err(match error {
2418 Ok(value) => common::Error::BadRequest(value),
2419 _ => common::Error::Failure(response),
2420 });
2421 }
2422 let response = {
2423 let bytes = common::to_bytes(body).await.unwrap_or_default();
2424 let encoded = common::to_string(&bytes);
2425 match serde_json::from_str(&encoded) {
2426 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2427 Err(error) => {
2428 dlg.response_json_decode_error(&encoded, &error);
2429 return Err(common::Error::JsonDecodeError(
2430 encoded.to_string(),
2431 error,
2432 ));
2433 }
2434 }
2435 };
2436
2437 dlg.finished(true);
2438 return Ok(response);
2439 }
2440 }
2441 }
2442 }
2443
2444 ///
2445 /// Sets the *request* property to the given value.
2446 ///
2447 /// Even though the property as already been set when instantiating this call,
2448 /// we provide this method for API completeness.
2449 pub fn request(
2450 mut self,
2451 new_value: AuthorizeEnvironmentRequest,
2452 ) -> UserEnvironmentAuthorizeCall<'a, C> {
2453 self._request = new_value;
2454 self
2455 }
2456 /// Name of the resource that should receive the credentials, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
2457 ///
2458 /// Sets the *name* path property to the given value.
2459 ///
2460 /// Even though the property as already been set when instantiating this call,
2461 /// we provide this method for API completeness.
2462 pub fn name(mut self, new_value: &str) -> UserEnvironmentAuthorizeCall<'a, C> {
2463 self._name = new_value.to_string();
2464 self
2465 }
2466 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2467 /// while executing the actual API request.
2468 ///
2469 /// ````text
2470 /// It should be used to handle progress information, and to implement a certain level of resilience.
2471 /// ````
2472 ///
2473 /// Sets the *delegate* property to the given value.
2474 pub fn delegate(
2475 mut self,
2476 new_value: &'a mut dyn common::Delegate,
2477 ) -> UserEnvironmentAuthorizeCall<'a, C> {
2478 self._delegate = Some(new_value);
2479 self
2480 }
2481
2482 /// Set any additional parameter of the query string used in the request.
2483 /// It should be used to set parameters which are not yet available through their own
2484 /// setters.
2485 ///
2486 /// Please note that this method must not be used to set any of the known parameters
2487 /// which have their own setter method. If done anyway, the request will fail.
2488 ///
2489 /// # Additional Parameters
2490 ///
2491 /// * *$.xgafv* (query-string) - V1 error format.
2492 /// * *access_token* (query-string) - OAuth access token.
2493 /// * *alt* (query-string) - Data format for response.
2494 /// * *callback* (query-string) - JSONP
2495 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2496 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2497 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2498 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2499 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
2500 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2501 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2502 pub fn param<T>(mut self, name: T, value: T) -> UserEnvironmentAuthorizeCall<'a, C>
2503 where
2504 T: AsRef<str>,
2505 {
2506 self._additional_params
2507 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2508 self
2509 }
2510
2511 /// Identifies the authorization scope for the method you are building.
2512 ///
2513 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2514 /// [`Scope::CloudPlatform`].
2515 ///
2516 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2517 /// tokens for more than one scope.
2518 ///
2519 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2520 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2521 /// sufficient, a read-write scope will do as well.
2522 pub fn add_scope<St>(mut self, scope: St) -> UserEnvironmentAuthorizeCall<'a, C>
2523 where
2524 St: AsRef<str>,
2525 {
2526 self._scopes.insert(String::from(scope.as_ref()));
2527 self
2528 }
2529 /// Identifies the authorization scope(s) for the method you are building.
2530 ///
2531 /// See [`Self::add_scope()`] for details.
2532 pub fn add_scopes<I, St>(mut self, scopes: I) -> UserEnvironmentAuthorizeCall<'a, C>
2533 where
2534 I: IntoIterator<Item = St>,
2535 St: AsRef<str>,
2536 {
2537 self._scopes
2538 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2539 self
2540 }
2541
2542 /// Removes all scopes, and no default scope will be used either.
2543 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2544 /// for details).
2545 pub fn clear_scopes(mut self) -> UserEnvironmentAuthorizeCall<'a, C> {
2546 self._scopes.clear();
2547 self
2548 }
2549}
2550
2551/// Gets an environment. Returns NOT_FOUND if the environment does not exist.
2552///
2553/// A builder for the *environments.get* method supported by a *user* resource.
2554/// It is not used directly, but through a [`UserMethods`] instance.
2555///
2556/// # Example
2557///
2558/// Instantiate a resource method builder
2559///
2560/// ```test_harness,no_run
2561/// # extern crate hyper;
2562/// # extern crate hyper_rustls;
2563/// # extern crate google_cloudshell1 as cloudshell1;
2564/// # async fn dox() {
2565/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2566///
2567/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2568/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2569/// # secret,
2570/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2571/// # ).build().await.unwrap();
2572///
2573/// # let client = hyper_util::client::legacy::Client::builder(
2574/// # hyper_util::rt::TokioExecutor::new()
2575/// # )
2576/// # .build(
2577/// # hyper_rustls::HttpsConnectorBuilder::new()
2578/// # .with_native_roots()
2579/// # .unwrap()
2580/// # .https_or_http()
2581/// # .enable_http1()
2582/// # .build()
2583/// # );
2584/// # let mut hub = CloudShell::new(client, auth);
2585/// // You can configure optional parameters by calling the respective setters at will, and
2586/// // execute the final call using `doit()`.
2587/// // Values shown here are possibly random and not representative !
2588/// let result = hub.users().environments_get("name")
2589/// .doit().await;
2590/// # }
2591/// ```
2592pub struct UserEnvironmentGetCall<'a, C>
2593where
2594 C: 'a,
2595{
2596 hub: &'a CloudShell<C>,
2597 _name: String,
2598 _delegate: Option<&'a mut dyn common::Delegate>,
2599 _additional_params: HashMap<String, String>,
2600 _scopes: BTreeSet<String>,
2601}
2602
2603impl<'a, C> common::CallBuilder for UserEnvironmentGetCall<'a, C> {}
2604
2605impl<'a, C> UserEnvironmentGetCall<'a, C>
2606where
2607 C: common::Connector,
2608{
2609 /// Perform the operation you have build so far.
2610 pub async fn doit(mut self) -> common::Result<(common::Response, Environment)> {
2611 use std::borrow::Cow;
2612 use std::io::{Read, Seek};
2613
2614 use common::{url::Params, ToParts};
2615 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2616
2617 let mut dd = common::DefaultDelegate;
2618 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2619 dlg.begin(common::MethodInfo {
2620 id: "cloudshell.users.environments.get",
2621 http_method: hyper::Method::GET,
2622 });
2623
2624 for &field in ["alt", "name"].iter() {
2625 if self._additional_params.contains_key(field) {
2626 dlg.finished(false);
2627 return Err(common::Error::FieldClash(field));
2628 }
2629 }
2630
2631 let mut params = Params::with_capacity(3 + self._additional_params.len());
2632 params.push("name", self._name);
2633
2634 params.extend(self._additional_params.iter());
2635
2636 params.push("alt", "json");
2637 let mut url = self.hub._base_url.clone() + "v1/{+name}";
2638 if self._scopes.is_empty() {
2639 self._scopes
2640 .insert(Scope::CloudPlatform.as_ref().to_string());
2641 }
2642
2643 #[allow(clippy::single_element_loop)]
2644 for &(find_this, param_name) in [("{+name}", "name")].iter() {
2645 url = params.uri_replacement(url, param_name, find_this, true);
2646 }
2647 {
2648 let to_remove = ["name"];
2649 params.remove_params(&to_remove);
2650 }
2651
2652 let url = params.parse_with_url(&url);
2653
2654 loop {
2655 let token = match self
2656 .hub
2657 .auth
2658 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2659 .await
2660 {
2661 Ok(token) => token,
2662 Err(e) => match dlg.token(e) {
2663 Ok(token) => token,
2664 Err(e) => {
2665 dlg.finished(false);
2666 return Err(common::Error::MissingToken(e));
2667 }
2668 },
2669 };
2670 let mut req_result = {
2671 let client = &self.hub.client;
2672 dlg.pre_request();
2673 let mut req_builder = hyper::Request::builder()
2674 .method(hyper::Method::GET)
2675 .uri(url.as_str())
2676 .header(USER_AGENT, self.hub._user_agent.clone());
2677
2678 if let Some(token) = token.as_ref() {
2679 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2680 }
2681
2682 let request = req_builder
2683 .header(CONTENT_LENGTH, 0_u64)
2684 .body(common::to_body::<String>(None));
2685
2686 client.request(request.unwrap()).await
2687 };
2688
2689 match req_result {
2690 Err(err) => {
2691 if let common::Retry::After(d) = dlg.http_error(&err) {
2692 sleep(d).await;
2693 continue;
2694 }
2695 dlg.finished(false);
2696 return Err(common::Error::HttpError(err));
2697 }
2698 Ok(res) => {
2699 let (mut parts, body) = res.into_parts();
2700 let mut body = common::Body::new(body);
2701 if !parts.status.is_success() {
2702 let bytes = common::to_bytes(body).await.unwrap_or_default();
2703 let error = serde_json::from_str(&common::to_string(&bytes));
2704 let response = common::to_response(parts, bytes.into());
2705
2706 if let common::Retry::After(d) =
2707 dlg.http_failure(&response, error.as_ref().ok())
2708 {
2709 sleep(d).await;
2710 continue;
2711 }
2712
2713 dlg.finished(false);
2714
2715 return Err(match error {
2716 Ok(value) => common::Error::BadRequest(value),
2717 _ => common::Error::Failure(response),
2718 });
2719 }
2720 let response = {
2721 let bytes = common::to_bytes(body).await.unwrap_or_default();
2722 let encoded = common::to_string(&bytes);
2723 match serde_json::from_str(&encoded) {
2724 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2725 Err(error) => {
2726 dlg.response_json_decode_error(&encoded, &error);
2727 return Err(common::Error::JsonDecodeError(
2728 encoded.to_string(),
2729 error,
2730 ));
2731 }
2732 }
2733 };
2734
2735 dlg.finished(true);
2736 return Ok(response);
2737 }
2738 }
2739 }
2740 }
2741
2742 /// Required. Name of the requested resource, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
2743 ///
2744 /// Sets the *name* path property to the given value.
2745 ///
2746 /// Even though the property as already been set when instantiating this call,
2747 /// we provide this method for API completeness.
2748 pub fn name(mut self, new_value: &str) -> UserEnvironmentGetCall<'a, C> {
2749 self._name = new_value.to_string();
2750 self
2751 }
2752 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2753 /// while executing the actual API request.
2754 ///
2755 /// ````text
2756 /// It should be used to handle progress information, and to implement a certain level of resilience.
2757 /// ````
2758 ///
2759 /// Sets the *delegate* property to the given value.
2760 pub fn delegate(
2761 mut self,
2762 new_value: &'a mut dyn common::Delegate,
2763 ) -> UserEnvironmentGetCall<'a, C> {
2764 self._delegate = Some(new_value);
2765 self
2766 }
2767
2768 /// Set any additional parameter of the query string used in the request.
2769 /// It should be used to set parameters which are not yet available through their own
2770 /// setters.
2771 ///
2772 /// Please note that this method must not be used to set any of the known parameters
2773 /// which have their own setter method. If done anyway, the request will fail.
2774 ///
2775 /// # Additional Parameters
2776 ///
2777 /// * *$.xgafv* (query-string) - V1 error format.
2778 /// * *access_token* (query-string) - OAuth access token.
2779 /// * *alt* (query-string) - Data format for response.
2780 /// * *callback* (query-string) - JSONP
2781 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2782 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
2783 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2784 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2785 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
2786 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2787 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2788 pub fn param<T>(mut self, name: T, value: T) -> UserEnvironmentGetCall<'a, C>
2789 where
2790 T: AsRef<str>,
2791 {
2792 self._additional_params
2793 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2794 self
2795 }
2796
2797 /// Identifies the authorization scope for the method you are building.
2798 ///
2799 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2800 /// [`Scope::CloudPlatform`].
2801 ///
2802 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2803 /// tokens for more than one scope.
2804 ///
2805 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2806 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2807 /// sufficient, a read-write scope will do as well.
2808 pub fn add_scope<St>(mut self, scope: St) -> UserEnvironmentGetCall<'a, C>
2809 where
2810 St: AsRef<str>,
2811 {
2812 self._scopes.insert(String::from(scope.as_ref()));
2813 self
2814 }
2815 /// Identifies the authorization scope(s) for the method you are building.
2816 ///
2817 /// See [`Self::add_scope()`] for details.
2818 pub fn add_scopes<I, St>(mut self, scopes: I) -> UserEnvironmentGetCall<'a, C>
2819 where
2820 I: IntoIterator<Item = St>,
2821 St: AsRef<str>,
2822 {
2823 self._scopes
2824 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2825 self
2826 }
2827
2828 /// Removes all scopes, and no default scope will be used either.
2829 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2830 /// for details).
2831 pub fn clear_scopes(mut self) -> UserEnvironmentGetCall<'a, C> {
2832 self._scopes.clear();
2833 self
2834 }
2835}
2836
2837/// Removes a public SSH key from an environment. Clients will no longer be able to connect to the environment using the corresponding private key. If a key with the same content is not present, this will error with NOT_FOUND.
2838///
2839/// A builder for the *environments.removePublicKey* method supported by a *user* resource.
2840/// It is not used directly, but through a [`UserMethods`] instance.
2841///
2842/// # Example
2843///
2844/// Instantiate a resource method builder
2845///
2846/// ```test_harness,no_run
2847/// # extern crate hyper;
2848/// # extern crate hyper_rustls;
2849/// # extern crate google_cloudshell1 as cloudshell1;
2850/// use cloudshell1::api::RemovePublicKeyRequest;
2851/// # async fn dox() {
2852/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2853///
2854/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2855/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
2856/// # secret,
2857/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2858/// # ).build().await.unwrap();
2859///
2860/// # let client = hyper_util::client::legacy::Client::builder(
2861/// # hyper_util::rt::TokioExecutor::new()
2862/// # )
2863/// # .build(
2864/// # hyper_rustls::HttpsConnectorBuilder::new()
2865/// # .with_native_roots()
2866/// # .unwrap()
2867/// # .https_or_http()
2868/// # .enable_http1()
2869/// # .build()
2870/// # );
2871/// # let mut hub = CloudShell::new(client, auth);
2872/// // As the method needs a request, you would usually fill it with the desired information
2873/// // into the respective structure. Some of the parts shown here might not be applicable !
2874/// // Values shown here are possibly random and not representative !
2875/// let mut req = RemovePublicKeyRequest::default();
2876///
2877/// // You can configure optional parameters by calling the respective setters at will, and
2878/// // execute the final call using `doit()`.
2879/// // Values shown here are possibly random and not representative !
2880/// let result = hub.users().environments_remove_public_key(req, "environment")
2881/// .doit().await;
2882/// # }
2883/// ```
2884pub struct UserEnvironmentRemovePublicKeyCall<'a, C>
2885where
2886 C: 'a,
2887{
2888 hub: &'a CloudShell<C>,
2889 _request: RemovePublicKeyRequest,
2890 _environment: String,
2891 _delegate: Option<&'a mut dyn common::Delegate>,
2892 _additional_params: HashMap<String, String>,
2893 _scopes: BTreeSet<String>,
2894}
2895
2896impl<'a, C> common::CallBuilder for UserEnvironmentRemovePublicKeyCall<'a, C> {}
2897
2898impl<'a, C> UserEnvironmentRemovePublicKeyCall<'a, C>
2899where
2900 C: common::Connector,
2901{
2902 /// Perform the operation you have build so far.
2903 pub async fn doit(mut self) -> common::Result<(common::Response, Operation)> {
2904 use std::borrow::Cow;
2905 use std::io::{Read, Seek};
2906
2907 use common::{url::Params, ToParts};
2908 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2909
2910 let mut dd = common::DefaultDelegate;
2911 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2912 dlg.begin(common::MethodInfo {
2913 id: "cloudshell.users.environments.removePublicKey",
2914 http_method: hyper::Method::POST,
2915 });
2916
2917 for &field in ["alt", "environment"].iter() {
2918 if self._additional_params.contains_key(field) {
2919 dlg.finished(false);
2920 return Err(common::Error::FieldClash(field));
2921 }
2922 }
2923
2924 let mut params = Params::with_capacity(4 + self._additional_params.len());
2925 params.push("environment", self._environment);
2926
2927 params.extend(self._additional_params.iter());
2928
2929 params.push("alt", "json");
2930 let mut url = self.hub._base_url.clone() + "v1/{+environment}:removePublicKey";
2931 if self._scopes.is_empty() {
2932 self._scopes
2933 .insert(Scope::CloudPlatform.as_ref().to_string());
2934 }
2935
2936 #[allow(clippy::single_element_loop)]
2937 for &(find_this, param_name) in [("{+environment}", "environment")].iter() {
2938 url = params.uri_replacement(url, param_name, find_this, true);
2939 }
2940 {
2941 let to_remove = ["environment"];
2942 params.remove_params(&to_remove);
2943 }
2944
2945 let url = params.parse_with_url(&url);
2946
2947 let mut json_mime_type = mime::APPLICATION_JSON;
2948 let mut request_value_reader = {
2949 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
2950 common::remove_json_null_values(&mut value);
2951 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
2952 serde_json::to_writer(&mut dst, &value).unwrap();
2953 dst
2954 };
2955 let request_size = request_value_reader
2956 .seek(std::io::SeekFrom::End(0))
2957 .unwrap();
2958 request_value_reader
2959 .seek(std::io::SeekFrom::Start(0))
2960 .unwrap();
2961
2962 loop {
2963 let token = match self
2964 .hub
2965 .auth
2966 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2967 .await
2968 {
2969 Ok(token) => token,
2970 Err(e) => match dlg.token(e) {
2971 Ok(token) => token,
2972 Err(e) => {
2973 dlg.finished(false);
2974 return Err(common::Error::MissingToken(e));
2975 }
2976 },
2977 };
2978 request_value_reader
2979 .seek(std::io::SeekFrom::Start(0))
2980 .unwrap();
2981 let mut req_result = {
2982 let client = &self.hub.client;
2983 dlg.pre_request();
2984 let mut req_builder = hyper::Request::builder()
2985 .method(hyper::Method::POST)
2986 .uri(url.as_str())
2987 .header(USER_AGENT, self.hub._user_agent.clone());
2988
2989 if let Some(token) = token.as_ref() {
2990 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2991 }
2992
2993 let request = req_builder
2994 .header(CONTENT_TYPE, json_mime_type.to_string())
2995 .header(CONTENT_LENGTH, request_size as u64)
2996 .body(common::to_body(
2997 request_value_reader.get_ref().clone().into(),
2998 ));
2999
3000 client.request(request.unwrap()).await
3001 };
3002
3003 match req_result {
3004 Err(err) => {
3005 if let common::Retry::After(d) = dlg.http_error(&err) {
3006 sleep(d).await;
3007 continue;
3008 }
3009 dlg.finished(false);
3010 return Err(common::Error::HttpError(err));
3011 }
3012 Ok(res) => {
3013 let (mut parts, body) = res.into_parts();
3014 let mut body = common::Body::new(body);
3015 if !parts.status.is_success() {
3016 let bytes = common::to_bytes(body).await.unwrap_or_default();
3017 let error = serde_json::from_str(&common::to_string(&bytes));
3018 let response = common::to_response(parts, bytes.into());
3019
3020 if let common::Retry::After(d) =
3021 dlg.http_failure(&response, error.as_ref().ok())
3022 {
3023 sleep(d).await;
3024 continue;
3025 }
3026
3027 dlg.finished(false);
3028
3029 return Err(match error {
3030 Ok(value) => common::Error::BadRequest(value),
3031 _ => common::Error::Failure(response),
3032 });
3033 }
3034 let response = {
3035 let bytes = common::to_bytes(body).await.unwrap_or_default();
3036 let encoded = common::to_string(&bytes);
3037 match serde_json::from_str(&encoded) {
3038 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3039 Err(error) => {
3040 dlg.response_json_decode_error(&encoded, &error);
3041 return Err(common::Error::JsonDecodeError(
3042 encoded.to_string(),
3043 error,
3044 ));
3045 }
3046 }
3047 };
3048
3049 dlg.finished(true);
3050 return Ok(response);
3051 }
3052 }
3053 }
3054 }
3055
3056 ///
3057 /// Sets the *request* property to the given value.
3058 ///
3059 /// Even though the property as already been set when instantiating this call,
3060 /// we provide this method for API completeness.
3061 pub fn request(
3062 mut self,
3063 new_value: RemovePublicKeyRequest,
3064 ) -> UserEnvironmentRemovePublicKeyCall<'a, C> {
3065 self._request = new_value;
3066 self
3067 }
3068 /// Environment this key should be removed from, e.g. `users/me/environments/default`.
3069 ///
3070 /// Sets the *environment* path property to the given value.
3071 ///
3072 /// Even though the property as already been set when instantiating this call,
3073 /// we provide this method for API completeness.
3074 pub fn environment(mut self, new_value: &str) -> UserEnvironmentRemovePublicKeyCall<'a, C> {
3075 self._environment = new_value.to_string();
3076 self
3077 }
3078 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3079 /// while executing the actual API request.
3080 ///
3081 /// ````text
3082 /// It should be used to handle progress information, and to implement a certain level of resilience.
3083 /// ````
3084 ///
3085 /// Sets the *delegate* property to the given value.
3086 pub fn delegate(
3087 mut self,
3088 new_value: &'a mut dyn common::Delegate,
3089 ) -> UserEnvironmentRemovePublicKeyCall<'a, C> {
3090 self._delegate = Some(new_value);
3091 self
3092 }
3093
3094 /// Set any additional parameter of the query string used in the request.
3095 /// It should be used to set parameters which are not yet available through their own
3096 /// setters.
3097 ///
3098 /// Please note that this method must not be used to set any of the known parameters
3099 /// which have their own setter method. If done anyway, the request will fail.
3100 ///
3101 /// # Additional Parameters
3102 ///
3103 /// * *$.xgafv* (query-string) - V1 error format.
3104 /// * *access_token* (query-string) - OAuth access token.
3105 /// * *alt* (query-string) - Data format for response.
3106 /// * *callback* (query-string) - JSONP
3107 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3108 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
3109 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3110 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3111 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
3112 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
3113 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
3114 pub fn param<T>(mut self, name: T, value: T) -> UserEnvironmentRemovePublicKeyCall<'a, C>
3115 where
3116 T: AsRef<str>,
3117 {
3118 self._additional_params
3119 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3120 self
3121 }
3122
3123 /// Identifies the authorization scope for the method you are building.
3124 ///
3125 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3126 /// [`Scope::CloudPlatform`].
3127 ///
3128 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3129 /// tokens for more than one scope.
3130 ///
3131 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3132 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3133 /// sufficient, a read-write scope will do as well.
3134 pub fn add_scope<St>(mut self, scope: St) -> UserEnvironmentRemovePublicKeyCall<'a, C>
3135 where
3136 St: AsRef<str>,
3137 {
3138 self._scopes.insert(String::from(scope.as_ref()));
3139 self
3140 }
3141 /// Identifies the authorization scope(s) for the method you are building.
3142 ///
3143 /// See [`Self::add_scope()`] for details.
3144 pub fn add_scopes<I, St>(mut self, scopes: I) -> UserEnvironmentRemovePublicKeyCall<'a, C>
3145 where
3146 I: IntoIterator<Item = St>,
3147 St: AsRef<str>,
3148 {
3149 self._scopes
3150 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3151 self
3152 }
3153
3154 /// Removes all scopes, and no default scope will be used either.
3155 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3156 /// for details).
3157 pub fn clear_scopes(mut self) -> UserEnvironmentRemovePublicKeyCall<'a, C> {
3158 self._scopes.clear();
3159 self
3160 }
3161}
3162
3163/// Starts an existing environment, allowing clients to connect to it. The returned operation will contain an instance of StartEnvironmentMetadata in its metadata field. Users can wait for the environment to start by polling this operation via GetOperation. Once the environment has finished starting and is ready to accept connections, the operation will contain a StartEnvironmentResponse in its response field.
3164///
3165/// A builder for the *environments.start* method supported by a *user* resource.
3166/// It is not used directly, but through a [`UserMethods`] instance.
3167///
3168/// # Example
3169///
3170/// Instantiate a resource method builder
3171///
3172/// ```test_harness,no_run
3173/// # extern crate hyper;
3174/// # extern crate hyper_rustls;
3175/// # extern crate google_cloudshell1 as cloudshell1;
3176/// use cloudshell1::api::StartEnvironmentRequest;
3177/// # async fn dox() {
3178/// # use cloudshell1::{CloudShell, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3179///
3180/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3181/// # let auth = yup_oauth2::InstalledFlowAuthenticator::builder(
3182/// # secret,
3183/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3184/// # ).build().await.unwrap();
3185///
3186/// # let client = hyper_util::client::legacy::Client::builder(
3187/// # hyper_util::rt::TokioExecutor::new()
3188/// # )
3189/// # .build(
3190/// # hyper_rustls::HttpsConnectorBuilder::new()
3191/// # .with_native_roots()
3192/// # .unwrap()
3193/// # .https_or_http()
3194/// # .enable_http1()
3195/// # .build()
3196/// # );
3197/// # let mut hub = CloudShell::new(client, auth);
3198/// // As the method needs a request, you would usually fill it with the desired information
3199/// // into the respective structure. Some of the parts shown here might not be applicable !
3200/// // Values shown here are possibly random and not representative !
3201/// let mut req = StartEnvironmentRequest::default();
3202///
3203/// // You can configure optional parameters by calling the respective setters at will, and
3204/// // execute the final call using `doit()`.
3205/// // Values shown here are possibly random and not representative !
3206/// let result = hub.users().environments_start(req, "name")
3207/// .doit().await;
3208/// # }
3209/// ```
3210pub struct UserEnvironmentStartCall<'a, C>
3211where
3212 C: 'a,
3213{
3214 hub: &'a CloudShell<C>,
3215 _request: StartEnvironmentRequest,
3216 _name: String,
3217 _delegate: Option<&'a mut dyn common::Delegate>,
3218 _additional_params: HashMap<String, String>,
3219 _scopes: BTreeSet<String>,
3220}
3221
3222impl<'a, C> common::CallBuilder for UserEnvironmentStartCall<'a, C> {}
3223
3224impl<'a, C> UserEnvironmentStartCall<'a, C>
3225where
3226 C: common::Connector,
3227{
3228 /// Perform the operation you have build so far.
3229 pub async fn doit(mut self) -> common::Result<(common::Response, Operation)> {
3230 use std::borrow::Cow;
3231 use std::io::{Read, Seek};
3232
3233 use common::{url::Params, ToParts};
3234 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3235
3236 let mut dd = common::DefaultDelegate;
3237 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3238 dlg.begin(common::MethodInfo {
3239 id: "cloudshell.users.environments.start",
3240 http_method: hyper::Method::POST,
3241 });
3242
3243 for &field in ["alt", "name"].iter() {
3244 if self._additional_params.contains_key(field) {
3245 dlg.finished(false);
3246 return Err(common::Error::FieldClash(field));
3247 }
3248 }
3249
3250 let mut params = Params::with_capacity(4 + self._additional_params.len());
3251 params.push("name", self._name);
3252
3253 params.extend(self._additional_params.iter());
3254
3255 params.push("alt", "json");
3256 let mut url = self.hub._base_url.clone() + "v1/{+name}:start";
3257 if self._scopes.is_empty() {
3258 self._scopes
3259 .insert(Scope::CloudPlatform.as_ref().to_string());
3260 }
3261
3262 #[allow(clippy::single_element_loop)]
3263 for &(find_this, param_name) in [("{+name}", "name")].iter() {
3264 url = params.uri_replacement(url, param_name, find_this, true);
3265 }
3266 {
3267 let to_remove = ["name"];
3268 params.remove_params(&to_remove);
3269 }
3270
3271 let url = params.parse_with_url(&url);
3272
3273 let mut json_mime_type = mime::APPLICATION_JSON;
3274 let mut request_value_reader = {
3275 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
3276 common::remove_json_null_values(&mut value);
3277 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
3278 serde_json::to_writer(&mut dst, &value).unwrap();
3279 dst
3280 };
3281 let request_size = request_value_reader
3282 .seek(std::io::SeekFrom::End(0))
3283 .unwrap();
3284 request_value_reader
3285 .seek(std::io::SeekFrom::Start(0))
3286 .unwrap();
3287
3288 loop {
3289 let token = match self
3290 .hub
3291 .auth
3292 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3293 .await
3294 {
3295 Ok(token) => token,
3296 Err(e) => match dlg.token(e) {
3297 Ok(token) => token,
3298 Err(e) => {
3299 dlg.finished(false);
3300 return Err(common::Error::MissingToken(e));
3301 }
3302 },
3303 };
3304 request_value_reader
3305 .seek(std::io::SeekFrom::Start(0))
3306 .unwrap();
3307 let mut req_result = {
3308 let client = &self.hub.client;
3309 dlg.pre_request();
3310 let mut req_builder = hyper::Request::builder()
3311 .method(hyper::Method::POST)
3312 .uri(url.as_str())
3313 .header(USER_AGENT, self.hub._user_agent.clone());
3314
3315 if let Some(token) = token.as_ref() {
3316 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3317 }
3318
3319 let request = req_builder
3320 .header(CONTENT_TYPE, json_mime_type.to_string())
3321 .header(CONTENT_LENGTH, request_size as u64)
3322 .body(common::to_body(
3323 request_value_reader.get_ref().clone().into(),
3324 ));
3325
3326 client.request(request.unwrap()).await
3327 };
3328
3329 match req_result {
3330 Err(err) => {
3331 if let common::Retry::After(d) = dlg.http_error(&err) {
3332 sleep(d).await;
3333 continue;
3334 }
3335 dlg.finished(false);
3336 return Err(common::Error::HttpError(err));
3337 }
3338 Ok(res) => {
3339 let (mut parts, body) = res.into_parts();
3340 let mut body = common::Body::new(body);
3341 if !parts.status.is_success() {
3342 let bytes = common::to_bytes(body).await.unwrap_or_default();
3343 let error = serde_json::from_str(&common::to_string(&bytes));
3344 let response = common::to_response(parts, bytes.into());
3345
3346 if let common::Retry::After(d) =
3347 dlg.http_failure(&response, error.as_ref().ok())
3348 {
3349 sleep(d).await;
3350 continue;
3351 }
3352
3353 dlg.finished(false);
3354
3355 return Err(match error {
3356 Ok(value) => common::Error::BadRequest(value),
3357 _ => common::Error::Failure(response),
3358 });
3359 }
3360 let response = {
3361 let bytes = common::to_bytes(body).await.unwrap_or_default();
3362 let encoded = common::to_string(&bytes);
3363 match serde_json::from_str(&encoded) {
3364 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3365 Err(error) => {
3366 dlg.response_json_decode_error(&encoded, &error);
3367 return Err(common::Error::JsonDecodeError(
3368 encoded.to_string(),
3369 error,
3370 ));
3371 }
3372 }
3373 };
3374
3375 dlg.finished(true);
3376 return Ok(response);
3377 }
3378 }
3379 }
3380 }
3381
3382 ///
3383 /// Sets the *request* property to the given value.
3384 ///
3385 /// Even though the property as already been set when instantiating this call,
3386 /// we provide this method for API completeness.
3387 pub fn request(
3388 mut self,
3389 new_value: StartEnvironmentRequest,
3390 ) -> UserEnvironmentStartCall<'a, C> {
3391 self._request = new_value;
3392 self
3393 }
3394 /// Name of the resource that should be started, for example `users/me/environments/default` or `users/someone@example.com/environments/default`.
3395 ///
3396 /// Sets the *name* path property to the given value.
3397 ///
3398 /// Even though the property as already been set when instantiating this call,
3399 /// we provide this method for API completeness.
3400 pub fn name(mut self, new_value: &str) -> UserEnvironmentStartCall<'a, C> {
3401 self._name = new_value.to_string();
3402 self
3403 }
3404 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3405 /// while executing the actual API request.
3406 ///
3407 /// ````text
3408 /// It should be used to handle progress information, and to implement a certain level of resilience.
3409 /// ````
3410 ///
3411 /// Sets the *delegate* property to the given value.
3412 pub fn delegate(
3413 mut self,
3414 new_value: &'a mut dyn common::Delegate,
3415 ) -> UserEnvironmentStartCall<'a, C> {
3416 self._delegate = Some(new_value);
3417 self
3418 }
3419
3420 /// Set any additional parameter of the query string used in the request.
3421 /// It should be used to set parameters which are not yet available through their own
3422 /// setters.
3423 ///
3424 /// Please note that this method must not be used to set any of the known parameters
3425 /// which have their own setter method. If done anyway, the request will fail.
3426 ///
3427 /// # Additional Parameters
3428 ///
3429 /// * *$.xgafv* (query-string) - V1 error format.
3430 /// * *access_token* (query-string) - OAuth access token.
3431 /// * *alt* (query-string) - Data format for response.
3432 /// * *callback* (query-string) - JSONP
3433 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3434 /// * *key* (query-string) - API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
3435 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3436 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3437 /// * *quotaUser* (query-string) - Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
3438 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
3439 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
3440 pub fn param<T>(mut self, name: T, value: T) -> UserEnvironmentStartCall<'a, C>
3441 where
3442 T: AsRef<str>,
3443 {
3444 self._additional_params
3445 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3446 self
3447 }
3448
3449 /// Identifies the authorization scope for the method you are building.
3450 ///
3451 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3452 /// [`Scope::CloudPlatform`].
3453 ///
3454 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3455 /// tokens for more than one scope.
3456 ///
3457 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3458 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3459 /// sufficient, a read-write scope will do as well.
3460 pub fn add_scope<St>(mut self, scope: St) -> UserEnvironmentStartCall<'a, C>
3461 where
3462 St: AsRef<str>,
3463 {
3464 self._scopes.insert(String::from(scope.as_ref()));
3465 self
3466 }
3467 /// Identifies the authorization scope(s) for the method you are building.
3468 ///
3469 /// See [`Self::add_scope()`] for details.
3470 pub fn add_scopes<I, St>(mut self, scopes: I) -> UserEnvironmentStartCall<'a, C>
3471 where
3472 I: IntoIterator<Item = St>,
3473 St: AsRef<str>,
3474 {
3475 self._scopes
3476 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3477 self
3478 }
3479
3480 /// Removes all scopes, and no default scope will be used either.
3481 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3482 /// for details).
3483 pub fn clear_scopes(mut self) -> UserEnvironmentStartCall<'a, C> {
3484 self._scopes.clear();
3485 self
3486 }
3487}