google_servicebroker1/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 /// View and manage your data across Google Cloud Platform services
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 ServiceBroker 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_servicebroker1 as servicebroker1;
49/// use servicebroker1::api::GoogleIamV1__SetIamPolicyRequest;
50/// use servicebroker1::{Result, Error};
51/// # async fn dox() {
52/// use servicebroker1::{ServiceBroker, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
53///
54/// // Get an ApplicationSecret instance by some means. It contains the `client_id` and
55/// // `client_secret`, among other things.
56/// let secret: yup_oauth2::ApplicationSecret = Default::default();
57/// // Instantiate the authenticator. It will choose a suitable authentication flow for you,
58/// // unless you replace `None` with the desired Flow.
59/// // Provide your own `AuthenticatorDelegate` to adjust the way it operates and get feedback about
60/// // what's going on. You probably want to bring in your own `TokenStorage` to persist tokens and
61/// // retrieve them from storage.
62/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
63/// .with_native_roots()
64/// .unwrap()
65/// .https_only()
66/// .enable_http2()
67/// .build();
68///
69/// let executor = hyper_util::rt::TokioExecutor::new();
70/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
71/// secret,
72/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
73/// yup_oauth2::client::CustomHyperClientBuilder::from(
74/// hyper_util::client::legacy::Client::builder(executor).build(connector),
75/// ),
76/// ).build().await.unwrap();
77///
78/// let client = hyper_util::client::legacy::Client::builder(
79/// hyper_util::rt::TokioExecutor::new()
80/// )
81/// .build(
82/// hyper_rustls::HttpsConnectorBuilder::new()
83/// .with_native_roots()
84/// .unwrap()
85/// .https_or_http()
86/// .enable_http2()
87/// .build()
88/// );
89/// let mut hub = ServiceBroker::new(client, auth);
90/// // As the method needs a request, you would usually fill it with the desired information
91/// // into the respective structure. Some of the parts shown here might not be applicable !
92/// // Values shown here are possibly random and not representative !
93/// let mut req = GoogleIamV1__SetIamPolicyRequest::default();
94///
95/// // You can configure optional parameters by calling the respective setters at will, and
96/// // execute the final call using `doit()`.
97/// // Values shown here are possibly random and not representative !
98/// let result = hub.methods().set_iam_policy(req, "resource")
99/// .doit().await;
100///
101/// match result {
102/// Err(e) => match e {
103/// // The Error enum provides details about what exactly happened.
104/// // You can also just use its `Debug`, `Display` or `Error` traits
105/// Error::HttpError(_)
106/// |Error::Io(_)
107/// |Error::MissingAPIKey
108/// |Error::MissingToken(_)
109/// |Error::Cancelled
110/// |Error::UploadSizeLimitExceeded(_, _)
111/// |Error::Failure(_)
112/// |Error::BadRequest(_)
113/// |Error::FieldClash(_)
114/// |Error::JsonDecodeError(_, _) => println!("{}", e),
115/// },
116/// Ok(res) => println!("Success: {:?}", res),
117/// }
118/// # }
119/// ```
120#[derive(Clone)]
121pub struct ServiceBroker<C> {
122 pub client: common::Client<C>,
123 pub auth: Box<dyn common::GetToken>,
124 _user_agent: String,
125 _base_url: String,
126 _root_url: String,
127}
128
129impl<C> common::Hub for ServiceBroker<C> {}
130
131impl<'a, C> ServiceBroker<C> {
132 pub fn new<A: 'static + common::GetToken>(
133 client: common::Client<C>,
134 auth: A,
135 ) -> ServiceBroker<C> {
136 ServiceBroker {
137 client,
138 auth: Box::new(auth),
139 _user_agent: "google-api-rust-client/7.0.0".to_string(),
140 _base_url: "https://servicebroker.googleapis.com/".to_string(),
141 _root_url: "https://servicebroker.googleapis.com/".to_string(),
142 }
143 }
144
145 pub fn methods(&'a self) -> MethodMethods<'a, C> {
146 MethodMethods { hub: self }
147 }
148
149 /// Set the user-agent header field to use in all requests to the server.
150 /// It defaults to `google-api-rust-client/7.0.0`.
151 ///
152 /// Returns the previously set user-agent.
153 pub fn user_agent(&mut self, agent_name: String) -> String {
154 std::mem::replace(&mut self._user_agent, agent_name)
155 }
156
157 /// Set the base url to use in all requests to the server.
158 /// It defaults to `https://servicebroker.googleapis.com/`.
159 ///
160 /// Returns the previously set base url.
161 pub fn base_url(&mut self, new_base_url: String) -> String {
162 std::mem::replace(&mut self._base_url, new_base_url)
163 }
164
165 /// Set the root url to use in all requests to the server.
166 /// It defaults to `https://servicebroker.googleapis.com/`.
167 ///
168 /// Returns the previously set root url.
169 pub fn root_url(&mut self, new_root_url: String) -> String {
170 std::mem::replace(&mut self._root_url, new_root_url)
171 }
172}
173
174// ############
175// SCHEMAS ###
176// ##########
177/// Associates `members` with a `role`.
178///
179/// This type is not used in any activity, and only used as *part* of another schema.
180///
181#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
182#[serde_with::serde_as]
183#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
184pub struct GoogleIamV1__Binding {
185 /// The condition that is associated with this binding.
186 /// NOTE: An unsatisfied condition will not allow user access via current
187 /// binding. Different bindings, including their conditions, are examined
188 /// independently.
189 pub condition: Option<GoogleType__Expr>,
190 /// Specifies the identities requesting access for a Cloud Platform resource.
191 /// `members` can have the following values:
192 ///
193 /// * `allUsers`: A special identifier that represents anyone who is
194 /// on the internet; with or without a Google account.
195 ///
196 /// * `allAuthenticatedUsers`: A special identifier that represents anyone
197 /// who is authenticated with a Google account or a service account.
198 ///
199 /// * `user:{emailid}`: An email address that represents a specific Google
200 /// account. For example, `alice@gmail.com` .
201 ///
202 ///
203 /// * `serviceAccount:{emailid}`: An email address that represents a service
204 /// account. For example, `my-other-app@appspot.gserviceaccount.com`.
205 ///
206 /// * `group:{emailid}`: An email address that represents a Google group.
207 /// For example, `admins@example.com`.
208 ///
209 ///
210 /// * `domain:{domain}`: The G Suite domain (primary) that represents all the
211 /// users of that domain. For example, `google.com` or `example.com`.
212 ///
213 ///
214 pub members: Option<Vec<String>>,
215 /// Role that is assigned to `members`.
216 /// For example, `roles/viewer`, `roles/editor`, or `roles/owner`.
217 pub role: Option<String>,
218}
219
220impl common::Part for GoogleIamV1__Binding {}
221
222/// Defines an Identity and Access Management (IAM) policy. It is used to
223/// specify access control policies for Cloud Platform resources.
224///
225/// A `Policy` consists of a list of `bindings`. A `binding` binds a list of
226/// `members` to a `role`, where the members can be user accounts, Google groups,
227/// Google domains, and service accounts. A `role` is a named list of permissions
228/// defined by IAM.
229///
230/// **JSON Example**
231///
232/// ````text
233/// {
234/// "bindings": [
235/// {
236/// "role": "roles/owner",
237/// "members": [
238/// "user:mike@example.com",
239/// "group:admins@example.com",
240/// "domain:google.com",
241/// "serviceAccount:my-other-app@appspot.gserviceaccount.com"
242/// ]
243/// },
244/// {
245/// "role": "roles/viewer",
246/// "members": ["user:sean@example.com"]
247/// }
248/// ]
249/// }
250/// ````
251///
252/// **YAML Example**
253///
254/// ````text
255/// bindings:
256/// - members:
257/// - user:mike@example.com
258/// - group:admins@example.com
259/// - domain:google.com
260/// - serviceAccount:my-other-app@appspot.gserviceaccount.com
261/// role: roles/owner
262/// - members:
263/// - user:sean@example.com
264/// role: roles/viewer
265/// ````
266///
267/// For a description of IAM and its features, see the
268/// [IAM developer’s guide](https://cloud.google.com/iam/docs).
269///
270/// # Activities
271///
272/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
273/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
274///
275/// * [get iam policy](MethodGetIamPolicyCall) (response)
276/// * [set iam policy](MethodSetIamPolicyCall) (response)
277#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
278#[serde_with::serde_as]
279#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
280pub struct GoogleIamV1__Policy {
281 /// Associates a list of `members` to a `role`.
282 /// `bindings` with no members will result in an error.
283 pub bindings: Option<Vec<GoogleIamV1__Binding>>,
284 /// `etag` is used for optimistic concurrency control as a way to help
285 /// prevent simultaneous updates of a policy from overwriting each other.
286 /// It is strongly suggested that systems make use of the `etag` in the
287 /// read-modify-write cycle to perform policy updates in order to avoid race
288 /// conditions: An `etag` is returned in the response to `getIamPolicy`, and
289 /// systems are expected to put that etag in the request to `setIamPolicy` to
290 /// ensure that their change will be applied to the same version of the policy.
291 ///
292 /// If no `etag` is provided in the call to `setIamPolicy`, then the existing
293 /// policy is overwritten blindly.
294 #[serde_as(as = "Option<common::serde::standard_base64::Wrapper>")]
295 pub etag: Option<Vec<u8>>,
296 /// Deprecated.
297 pub version: Option<i32>,
298}
299
300impl common::ResponseResult for GoogleIamV1__Policy {}
301
302/// Request message for `SetIamPolicy` method.
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/// * [set iam policy](MethodSetIamPolicyCall) (request)
310#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
311#[serde_with::serde_as]
312#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
313pub struct GoogleIamV1__SetIamPolicyRequest {
314 /// REQUIRED: The complete policy to be applied to the `resource`. The size of
315 /// the policy is limited to a few 10s of KB. An empty policy is a
316 /// valid policy but certain Cloud Platform services (such as Projects)
317 /// might reject them.
318 pub policy: Option<GoogleIamV1__Policy>,
319}
320
321impl common::RequestValue for GoogleIamV1__SetIamPolicyRequest {}
322
323/// Request message for `TestIamPermissions` method.
324///
325/// # Activities
326///
327/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
328/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
329///
330/// * [test iam permissions](MethodTestIamPermissionCall) (request)
331#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
332#[serde_with::serde_as]
333#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
334pub struct GoogleIamV1__TestIamPermissionsRequest {
335 /// The set of permissions to check for the `resource`. Permissions with
336 /// wildcards (such as '*' or 'storage.*') are not allowed. For more
337 /// information see
338 /// [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
339 pub permissions: Option<Vec<String>>,
340}
341
342impl common::RequestValue for GoogleIamV1__TestIamPermissionsRequest {}
343
344/// Response message for `TestIamPermissions` method.
345///
346/// # Activities
347///
348/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
349/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
350///
351/// * [test iam permissions](MethodTestIamPermissionCall) (response)
352#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
353#[serde_with::serde_as]
354#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
355pub struct GoogleIamV1__TestIamPermissionsResponse {
356 /// A subset of `TestPermissionsRequest.permissions` that the caller is
357 /// allowed.
358 pub permissions: Option<Vec<String>>,
359}
360
361impl common::ResponseResult for GoogleIamV1__TestIamPermissionsResponse {}
362
363/// Represents an expression text. Example:
364///
365/// ````text
366/// title: "User account presence"
367/// description: "Determines whether the request has a user account"
368/// expression: "size(request.user) > 0"
369/// ````
370///
371/// This type is not used in any activity, and only used as *part* of another schema.
372#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
373#[serde_with::serde_as]
374#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
375pub struct GoogleType__Expr {
376 /// An optional description of the expression. This is a longer text which
377 /// describes the expression, e.g. when hovered over it in a UI.
378 pub description: Option<String>,
379 /// Textual representation of an expression in
380 /// Common Expression Language syntax.
381 ///
382 /// The application context of the containing message determines which
383 /// well-known feature set of CEL is supported.
384 pub expression: Option<String>,
385 /// An optional string indicating the location of the expression for error
386 /// reporting, e.g. a file name and a position in the file.
387 pub location: Option<String>,
388 /// An optional title for the expression, i.e. a short string describing
389 /// its purpose. This can be used e.g. in UIs which allow to enter the
390 /// expression.
391 pub title: Option<String>,
392}
393
394impl common::Part for GoogleType__Expr {}
395
396// ###################
397// MethodBuilders ###
398// #################
399
400/// A builder providing access to all free methods, which are not associated with a particular resource.
401/// It is not used directly, but through the [`ServiceBroker`] hub.
402///
403/// # Example
404///
405/// Instantiate a resource builder
406///
407/// ```test_harness,no_run
408/// extern crate hyper;
409/// extern crate hyper_rustls;
410/// extern crate google_servicebroker1 as servicebroker1;
411///
412/// # async fn dox() {
413/// use servicebroker1::{ServiceBroker, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
414///
415/// let secret: yup_oauth2::ApplicationSecret = Default::default();
416/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
417/// .with_native_roots()
418/// .unwrap()
419/// .https_only()
420/// .enable_http2()
421/// .build();
422///
423/// let executor = hyper_util::rt::TokioExecutor::new();
424/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
425/// secret,
426/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
427/// yup_oauth2::client::CustomHyperClientBuilder::from(
428/// hyper_util::client::legacy::Client::builder(executor).build(connector),
429/// ),
430/// ).build().await.unwrap();
431///
432/// let client = hyper_util::client::legacy::Client::builder(
433/// hyper_util::rt::TokioExecutor::new()
434/// )
435/// .build(
436/// hyper_rustls::HttpsConnectorBuilder::new()
437/// .with_native_roots()
438/// .unwrap()
439/// .https_or_http()
440/// .enable_http2()
441/// .build()
442/// );
443/// let mut hub = ServiceBroker::new(client, auth);
444/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
445/// // like `get_iam_policy(...)`, `set_iam_policy(...)` and `test_iam_permissions(...)`
446/// // to build up your call.
447/// let rb = hub.methods();
448/// # }
449/// ```
450pub struct MethodMethods<'a, C>
451where
452 C: 'a,
453{
454 hub: &'a ServiceBroker<C>,
455}
456
457impl<'a, C> common::MethodsBuilder for MethodMethods<'a, C> {}
458
459impl<'a, C> MethodMethods<'a, C> {
460 /// Create a builder to help you perform the following task:
461 ///
462 /// Gets the access control policy for a resource.
463 /// Returns an empty policy if the resource exists and does not have a policy
464 /// set.
465 ///
466 /// # Arguments
467 ///
468 /// * `resource` - REQUIRED: The resource for which the policy is being requested.
469 /// See the operation documentation for the appropriate value for this field.
470 pub fn get_iam_policy(&self, resource: &str) -> MethodGetIamPolicyCall<'a, C> {
471 MethodGetIamPolicyCall {
472 hub: self.hub,
473 _resource: resource.to_string(),
474 _delegate: Default::default(),
475 _additional_params: Default::default(),
476 _scopes: Default::default(),
477 }
478 }
479
480 /// Create a builder to help you perform the following task:
481 ///
482 /// Sets the access control policy on the specified resource. Replaces any
483 /// existing policy.
484 ///
485 /// # Arguments
486 ///
487 /// * `request` - No description provided.
488 /// * `resource` - REQUIRED: The resource for which the policy is being specified.
489 /// See the operation documentation for the appropriate value for this field.
490 pub fn set_iam_policy(
491 &self,
492 request: GoogleIamV1__SetIamPolicyRequest,
493 resource: &str,
494 ) -> MethodSetIamPolicyCall<'a, C> {
495 MethodSetIamPolicyCall {
496 hub: self.hub,
497 _request: request,
498 _resource: resource.to_string(),
499 _delegate: Default::default(),
500 _additional_params: Default::default(),
501 _scopes: Default::default(),
502 }
503 }
504
505 /// Create a builder to help you perform the following task:
506 ///
507 /// Returns permissions that a caller has on the specified resource.
508 /// If the resource does not exist, this will return an empty set of
509 /// permissions, not a NOT_FOUND error.
510 ///
511 /// Note: This operation is designed to be used for building permission-aware
512 /// UIs and command-line tools, not for authorization checking. This operation
513 /// may "fail open" without warning.
514 ///
515 /// # Arguments
516 ///
517 /// * `request` - No description provided.
518 /// * `resource` - REQUIRED: The resource for which the policy detail is being requested.
519 /// See the operation documentation for the appropriate value for this field.
520 pub fn test_iam_permissions(
521 &self,
522 request: GoogleIamV1__TestIamPermissionsRequest,
523 resource: &str,
524 ) -> MethodTestIamPermissionCall<'a, C> {
525 MethodTestIamPermissionCall {
526 hub: self.hub,
527 _request: request,
528 _resource: resource.to_string(),
529 _delegate: Default::default(),
530 _additional_params: Default::default(),
531 _scopes: Default::default(),
532 }
533 }
534}
535
536// ###################
537// CallBuilders ###
538// #################
539
540/// Gets the access control policy for a resource.
541/// Returns an empty policy if the resource exists and does not have a policy
542/// set.
543///
544/// A builder for the *getIamPolicy* method.
545/// It is not used directly, but through a [`MethodMethods`] instance.
546///
547/// # Example
548///
549/// Instantiate a resource method builder
550///
551/// ```test_harness,no_run
552/// # extern crate hyper;
553/// # extern crate hyper_rustls;
554/// # extern crate google_servicebroker1 as servicebroker1;
555/// # async fn dox() {
556/// # use servicebroker1::{ServiceBroker, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
557///
558/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
559/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
560/// # .with_native_roots()
561/// # .unwrap()
562/// # .https_only()
563/// # .enable_http2()
564/// # .build();
565///
566/// # let executor = hyper_util::rt::TokioExecutor::new();
567/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
568/// # secret,
569/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
570/// # yup_oauth2::client::CustomHyperClientBuilder::from(
571/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
572/// # ),
573/// # ).build().await.unwrap();
574///
575/// # let client = hyper_util::client::legacy::Client::builder(
576/// # hyper_util::rt::TokioExecutor::new()
577/// # )
578/// # .build(
579/// # hyper_rustls::HttpsConnectorBuilder::new()
580/// # .with_native_roots()
581/// # .unwrap()
582/// # .https_or_http()
583/// # .enable_http2()
584/// # .build()
585/// # );
586/// # let mut hub = ServiceBroker::new(client, auth);
587/// // You can configure optional parameters by calling the respective setters at will, and
588/// // execute the final call using `doit()`.
589/// // Values shown here are possibly random and not representative !
590/// let result = hub.methods().get_iam_policy("resource")
591/// .doit().await;
592/// # }
593/// ```
594pub struct MethodGetIamPolicyCall<'a, C>
595where
596 C: 'a,
597{
598 hub: &'a ServiceBroker<C>,
599 _resource: String,
600 _delegate: Option<&'a mut dyn common::Delegate>,
601 _additional_params: HashMap<String, String>,
602 _scopes: BTreeSet<String>,
603}
604
605impl<'a, C> common::CallBuilder for MethodGetIamPolicyCall<'a, C> {}
606
607impl<'a, C> MethodGetIamPolicyCall<'a, C>
608where
609 C: common::Connector,
610{
611 /// Perform the operation you have build so far.
612 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleIamV1__Policy)> {
613 use std::borrow::Cow;
614 use std::io::{Read, Seek};
615
616 use common::{url::Params, ToParts};
617 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
618
619 let mut dd = common::DefaultDelegate;
620 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
621 dlg.begin(common::MethodInfo {
622 id: "servicebroker.getIamPolicy",
623 http_method: hyper::Method::GET,
624 });
625
626 for &field in ["alt", "resource"].iter() {
627 if self._additional_params.contains_key(field) {
628 dlg.finished(false);
629 return Err(common::Error::FieldClash(field));
630 }
631 }
632
633 let mut params = Params::with_capacity(3 + self._additional_params.len());
634 params.push("resource", self._resource);
635
636 params.extend(self._additional_params.iter());
637
638 params.push("alt", "json");
639 let mut url = self.hub._base_url.clone() + "v1/{+resource}:getIamPolicy";
640 if self._scopes.is_empty() {
641 self._scopes
642 .insert(Scope::CloudPlatform.as_ref().to_string());
643 }
644
645 #[allow(clippy::single_element_loop)]
646 for &(find_this, param_name) in [("{+resource}", "resource")].iter() {
647 url = params.uri_replacement(url, param_name, find_this, true);
648 }
649 {
650 let to_remove = ["resource"];
651 params.remove_params(&to_remove);
652 }
653
654 let url = params.parse_with_url(&url);
655
656 loop {
657 let token = match self
658 .hub
659 .auth
660 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
661 .await
662 {
663 Ok(token) => token,
664 Err(e) => match dlg.token(e) {
665 Ok(token) => token,
666 Err(e) => {
667 dlg.finished(false);
668 return Err(common::Error::MissingToken(e));
669 }
670 },
671 };
672 let mut req_result = {
673 let client = &self.hub.client;
674 dlg.pre_request();
675 let mut req_builder = hyper::Request::builder()
676 .method(hyper::Method::GET)
677 .uri(url.as_str())
678 .header(USER_AGENT, self.hub._user_agent.clone());
679
680 if let Some(token) = token.as_ref() {
681 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
682 }
683
684 let request = req_builder
685 .header(CONTENT_LENGTH, 0_u64)
686 .body(common::to_body::<String>(None));
687
688 client.request(request.unwrap()).await
689 };
690
691 match req_result {
692 Err(err) => {
693 if let common::Retry::After(d) = dlg.http_error(&err) {
694 sleep(d).await;
695 continue;
696 }
697 dlg.finished(false);
698 return Err(common::Error::HttpError(err));
699 }
700 Ok(res) => {
701 let (mut parts, body) = res.into_parts();
702 let mut body = common::Body::new(body);
703 if !parts.status.is_success() {
704 let bytes = common::to_bytes(body).await.unwrap_or_default();
705 let error = serde_json::from_str(&common::to_string(&bytes));
706 let response = common::to_response(parts, bytes.into());
707
708 if let common::Retry::After(d) =
709 dlg.http_failure(&response, error.as_ref().ok())
710 {
711 sleep(d).await;
712 continue;
713 }
714
715 dlg.finished(false);
716
717 return Err(match error {
718 Ok(value) => common::Error::BadRequest(value),
719 _ => common::Error::Failure(response),
720 });
721 }
722 let response = {
723 let bytes = common::to_bytes(body).await.unwrap_or_default();
724 let encoded = common::to_string(&bytes);
725 match serde_json::from_str(&encoded) {
726 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
727 Err(error) => {
728 dlg.response_json_decode_error(&encoded, &error);
729 return Err(common::Error::JsonDecodeError(
730 encoded.to_string(),
731 error,
732 ));
733 }
734 }
735 };
736
737 dlg.finished(true);
738 return Ok(response);
739 }
740 }
741 }
742 }
743
744 /// REQUIRED: The resource for which the policy is being requested.
745 /// See the operation documentation for the appropriate value for this field.
746 ///
747 /// Sets the *resource* path property to the given value.
748 ///
749 /// Even though the property as already been set when instantiating this call,
750 /// we provide this method for API completeness.
751 pub fn resource(mut self, new_value: &str) -> MethodGetIamPolicyCall<'a, C> {
752 self._resource = new_value.to_string();
753 self
754 }
755 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
756 /// while executing the actual API request.
757 ///
758 /// ````text
759 /// It should be used to handle progress information, and to implement a certain level of resilience.
760 /// ````
761 ///
762 /// Sets the *delegate* property to the given value.
763 pub fn delegate(
764 mut self,
765 new_value: &'a mut dyn common::Delegate,
766 ) -> MethodGetIamPolicyCall<'a, C> {
767 self._delegate = Some(new_value);
768 self
769 }
770
771 /// Set any additional parameter of the query string used in the request.
772 /// It should be used to set parameters which are not yet available through their own
773 /// setters.
774 ///
775 /// Please note that this method must not be used to set any of the known parameters
776 /// which have their own setter method. If done anyway, the request will fail.
777 ///
778 /// # Additional Parameters
779 ///
780 /// * *$.xgafv* (query-string) - V1 error format.
781 /// * *access_token* (query-string) - OAuth access token.
782 /// * *alt* (query-string) - Data format for response.
783 /// * *callback* (query-string) - JSONP
784 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
785 /// * *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.
786 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
787 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
788 /// * *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.
789 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
790 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
791 pub fn param<T>(mut self, name: T, value: T) -> MethodGetIamPolicyCall<'a, C>
792 where
793 T: AsRef<str>,
794 {
795 self._additional_params
796 .insert(name.as_ref().to_string(), value.as_ref().to_string());
797 self
798 }
799
800 /// Identifies the authorization scope for the method you are building.
801 ///
802 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
803 /// [`Scope::CloudPlatform`].
804 ///
805 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
806 /// tokens for more than one scope.
807 ///
808 /// Usually there is more than one suitable scope to authorize an operation, some of which may
809 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
810 /// sufficient, a read-write scope will do as well.
811 pub fn add_scope<St>(mut self, scope: St) -> MethodGetIamPolicyCall<'a, C>
812 where
813 St: AsRef<str>,
814 {
815 self._scopes.insert(String::from(scope.as_ref()));
816 self
817 }
818 /// Identifies the authorization scope(s) for the method you are building.
819 ///
820 /// See [`Self::add_scope()`] for details.
821 pub fn add_scopes<I, St>(mut self, scopes: I) -> MethodGetIamPolicyCall<'a, C>
822 where
823 I: IntoIterator<Item = St>,
824 St: AsRef<str>,
825 {
826 self._scopes
827 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
828 self
829 }
830
831 /// Removes all scopes, and no default scope will be used either.
832 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
833 /// for details).
834 pub fn clear_scopes(mut self) -> MethodGetIamPolicyCall<'a, C> {
835 self._scopes.clear();
836 self
837 }
838}
839
840/// Sets the access control policy on the specified resource. Replaces any
841/// existing policy.
842///
843/// A builder for the *setIamPolicy* method.
844/// It is not used directly, but through a [`MethodMethods`] instance.
845///
846/// # Example
847///
848/// Instantiate a resource method builder
849///
850/// ```test_harness,no_run
851/// # extern crate hyper;
852/// # extern crate hyper_rustls;
853/// # extern crate google_servicebroker1 as servicebroker1;
854/// use servicebroker1::api::GoogleIamV1__SetIamPolicyRequest;
855/// # async fn dox() {
856/// # use servicebroker1::{ServiceBroker, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
857///
858/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
859/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
860/// # .with_native_roots()
861/// # .unwrap()
862/// # .https_only()
863/// # .enable_http2()
864/// # .build();
865///
866/// # let executor = hyper_util::rt::TokioExecutor::new();
867/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
868/// # secret,
869/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
870/// # yup_oauth2::client::CustomHyperClientBuilder::from(
871/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
872/// # ),
873/// # ).build().await.unwrap();
874///
875/// # let client = hyper_util::client::legacy::Client::builder(
876/// # hyper_util::rt::TokioExecutor::new()
877/// # )
878/// # .build(
879/// # hyper_rustls::HttpsConnectorBuilder::new()
880/// # .with_native_roots()
881/// # .unwrap()
882/// # .https_or_http()
883/// # .enable_http2()
884/// # .build()
885/// # );
886/// # let mut hub = ServiceBroker::new(client, auth);
887/// // As the method needs a request, you would usually fill it with the desired information
888/// // into the respective structure. Some of the parts shown here might not be applicable !
889/// // Values shown here are possibly random and not representative !
890/// let mut req = GoogleIamV1__SetIamPolicyRequest::default();
891///
892/// // You can configure optional parameters by calling the respective setters at will, and
893/// // execute the final call using `doit()`.
894/// // Values shown here are possibly random and not representative !
895/// let result = hub.methods().set_iam_policy(req, "resource")
896/// .doit().await;
897/// # }
898/// ```
899pub struct MethodSetIamPolicyCall<'a, C>
900where
901 C: 'a,
902{
903 hub: &'a ServiceBroker<C>,
904 _request: GoogleIamV1__SetIamPolicyRequest,
905 _resource: String,
906 _delegate: Option<&'a mut dyn common::Delegate>,
907 _additional_params: HashMap<String, String>,
908 _scopes: BTreeSet<String>,
909}
910
911impl<'a, C> common::CallBuilder for MethodSetIamPolicyCall<'a, C> {}
912
913impl<'a, C> MethodSetIamPolicyCall<'a, C>
914where
915 C: common::Connector,
916{
917 /// Perform the operation you have build so far.
918 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleIamV1__Policy)> {
919 use std::borrow::Cow;
920 use std::io::{Read, Seek};
921
922 use common::{url::Params, ToParts};
923 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
924
925 let mut dd = common::DefaultDelegate;
926 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
927 dlg.begin(common::MethodInfo {
928 id: "servicebroker.setIamPolicy",
929 http_method: hyper::Method::POST,
930 });
931
932 for &field in ["alt", "resource"].iter() {
933 if self._additional_params.contains_key(field) {
934 dlg.finished(false);
935 return Err(common::Error::FieldClash(field));
936 }
937 }
938
939 let mut params = Params::with_capacity(4 + self._additional_params.len());
940 params.push("resource", self._resource);
941
942 params.extend(self._additional_params.iter());
943
944 params.push("alt", "json");
945 let mut url = self.hub._base_url.clone() + "v1/{+resource}:setIamPolicy";
946 if self._scopes.is_empty() {
947 self._scopes
948 .insert(Scope::CloudPlatform.as_ref().to_string());
949 }
950
951 #[allow(clippy::single_element_loop)]
952 for &(find_this, param_name) in [("{+resource}", "resource")].iter() {
953 url = params.uri_replacement(url, param_name, find_this, true);
954 }
955 {
956 let to_remove = ["resource"];
957 params.remove_params(&to_remove);
958 }
959
960 let url = params.parse_with_url(&url);
961
962 let mut json_mime_type = mime::APPLICATION_JSON;
963 let mut request_value_reader = {
964 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
965 common::remove_json_null_values(&mut value);
966 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
967 serde_json::to_writer(&mut dst, &value).unwrap();
968 dst
969 };
970 let request_size = request_value_reader
971 .seek(std::io::SeekFrom::End(0))
972 .unwrap();
973 request_value_reader
974 .seek(std::io::SeekFrom::Start(0))
975 .unwrap();
976
977 loop {
978 let token = match self
979 .hub
980 .auth
981 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
982 .await
983 {
984 Ok(token) => token,
985 Err(e) => match dlg.token(e) {
986 Ok(token) => token,
987 Err(e) => {
988 dlg.finished(false);
989 return Err(common::Error::MissingToken(e));
990 }
991 },
992 };
993 request_value_reader
994 .seek(std::io::SeekFrom::Start(0))
995 .unwrap();
996 let mut req_result = {
997 let client = &self.hub.client;
998 dlg.pre_request();
999 let mut req_builder = hyper::Request::builder()
1000 .method(hyper::Method::POST)
1001 .uri(url.as_str())
1002 .header(USER_AGENT, self.hub._user_agent.clone());
1003
1004 if let Some(token) = token.as_ref() {
1005 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1006 }
1007
1008 let request = req_builder
1009 .header(CONTENT_TYPE, json_mime_type.to_string())
1010 .header(CONTENT_LENGTH, request_size as u64)
1011 .body(common::to_body(
1012 request_value_reader.get_ref().clone().into(),
1013 ));
1014
1015 client.request(request.unwrap()).await
1016 };
1017
1018 match req_result {
1019 Err(err) => {
1020 if let common::Retry::After(d) = dlg.http_error(&err) {
1021 sleep(d).await;
1022 continue;
1023 }
1024 dlg.finished(false);
1025 return Err(common::Error::HttpError(err));
1026 }
1027 Ok(res) => {
1028 let (mut parts, body) = res.into_parts();
1029 let mut body = common::Body::new(body);
1030 if !parts.status.is_success() {
1031 let bytes = common::to_bytes(body).await.unwrap_or_default();
1032 let error = serde_json::from_str(&common::to_string(&bytes));
1033 let response = common::to_response(parts, bytes.into());
1034
1035 if let common::Retry::After(d) =
1036 dlg.http_failure(&response, error.as_ref().ok())
1037 {
1038 sleep(d).await;
1039 continue;
1040 }
1041
1042 dlg.finished(false);
1043
1044 return Err(match error {
1045 Ok(value) => common::Error::BadRequest(value),
1046 _ => common::Error::Failure(response),
1047 });
1048 }
1049 let response = {
1050 let bytes = common::to_bytes(body).await.unwrap_or_default();
1051 let encoded = common::to_string(&bytes);
1052 match serde_json::from_str(&encoded) {
1053 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1054 Err(error) => {
1055 dlg.response_json_decode_error(&encoded, &error);
1056 return Err(common::Error::JsonDecodeError(
1057 encoded.to_string(),
1058 error,
1059 ));
1060 }
1061 }
1062 };
1063
1064 dlg.finished(true);
1065 return Ok(response);
1066 }
1067 }
1068 }
1069 }
1070
1071 ///
1072 /// Sets the *request* property to the given value.
1073 ///
1074 /// Even though the property as already been set when instantiating this call,
1075 /// we provide this method for API completeness.
1076 pub fn request(
1077 mut self,
1078 new_value: GoogleIamV1__SetIamPolicyRequest,
1079 ) -> MethodSetIamPolicyCall<'a, C> {
1080 self._request = new_value;
1081 self
1082 }
1083 /// REQUIRED: The resource for which the policy is being specified.
1084 /// See the operation documentation for the appropriate value for this field.
1085 ///
1086 /// Sets the *resource* path property to the given value.
1087 ///
1088 /// Even though the property as already been set when instantiating this call,
1089 /// we provide this method for API completeness.
1090 pub fn resource(mut self, new_value: &str) -> MethodSetIamPolicyCall<'a, C> {
1091 self._resource = new_value.to_string();
1092 self
1093 }
1094 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1095 /// while executing the actual API request.
1096 ///
1097 /// ````text
1098 /// It should be used to handle progress information, and to implement a certain level of resilience.
1099 /// ````
1100 ///
1101 /// Sets the *delegate* property to the given value.
1102 pub fn delegate(
1103 mut self,
1104 new_value: &'a mut dyn common::Delegate,
1105 ) -> MethodSetIamPolicyCall<'a, C> {
1106 self._delegate = Some(new_value);
1107 self
1108 }
1109
1110 /// Set any additional parameter of the query string used in the request.
1111 /// It should be used to set parameters which are not yet available through their own
1112 /// setters.
1113 ///
1114 /// Please note that this method must not be used to set any of the known parameters
1115 /// which have their own setter method. If done anyway, the request will fail.
1116 ///
1117 /// # Additional Parameters
1118 ///
1119 /// * *$.xgafv* (query-string) - V1 error format.
1120 /// * *access_token* (query-string) - OAuth access token.
1121 /// * *alt* (query-string) - Data format for response.
1122 /// * *callback* (query-string) - JSONP
1123 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1124 /// * *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.
1125 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1126 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1127 /// * *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.
1128 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1129 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1130 pub fn param<T>(mut self, name: T, value: T) -> MethodSetIamPolicyCall<'a, C>
1131 where
1132 T: AsRef<str>,
1133 {
1134 self._additional_params
1135 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1136 self
1137 }
1138
1139 /// Identifies the authorization scope for the method you are building.
1140 ///
1141 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1142 /// [`Scope::CloudPlatform`].
1143 ///
1144 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1145 /// tokens for more than one scope.
1146 ///
1147 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1148 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1149 /// sufficient, a read-write scope will do as well.
1150 pub fn add_scope<St>(mut self, scope: St) -> MethodSetIamPolicyCall<'a, C>
1151 where
1152 St: AsRef<str>,
1153 {
1154 self._scopes.insert(String::from(scope.as_ref()));
1155 self
1156 }
1157 /// Identifies the authorization scope(s) for the method you are building.
1158 ///
1159 /// See [`Self::add_scope()`] for details.
1160 pub fn add_scopes<I, St>(mut self, scopes: I) -> MethodSetIamPolicyCall<'a, C>
1161 where
1162 I: IntoIterator<Item = St>,
1163 St: AsRef<str>,
1164 {
1165 self._scopes
1166 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1167 self
1168 }
1169
1170 /// Removes all scopes, and no default scope will be used either.
1171 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1172 /// for details).
1173 pub fn clear_scopes(mut self) -> MethodSetIamPolicyCall<'a, C> {
1174 self._scopes.clear();
1175 self
1176 }
1177}
1178
1179/// Returns permissions that a caller has on the specified resource.
1180/// If the resource does not exist, this will return an empty set of
1181/// permissions, not a NOT_FOUND error.
1182///
1183/// Note: This operation is designed to be used for building permission-aware
1184/// UIs and command-line tools, not for authorization checking. This operation
1185/// may "fail open" without warning.
1186///
1187/// A builder for the *testIamPermissions* method.
1188/// It is not used directly, but through a [`MethodMethods`] instance.
1189///
1190/// # Example
1191///
1192/// Instantiate a resource method builder
1193///
1194/// ```test_harness,no_run
1195/// # extern crate hyper;
1196/// # extern crate hyper_rustls;
1197/// # extern crate google_servicebroker1 as servicebroker1;
1198/// use servicebroker1::api::GoogleIamV1__TestIamPermissionsRequest;
1199/// # async fn dox() {
1200/// # use servicebroker1::{ServiceBroker, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1201///
1202/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1203/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1204/// # .with_native_roots()
1205/// # .unwrap()
1206/// # .https_only()
1207/// # .enable_http2()
1208/// # .build();
1209///
1210/// # let executor = hyper_util::rt::TokioExecutor::new();
1211/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1212/// # secret,
1213/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1214/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1215/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1216/// # ),
1217/// # ).build().await.unwrap();
1218///
1219/// # let client = hyper_util::client::legacy::Client::builder(
1220/// # hyper_util::rt::TokioExecutor::new()
1221/// # )
1222/// # .build(
1223/// # hyper_rustls::HttpsConnectorBuilder::new()
1224/// # .with_native_roots()
1225/// # .unwrap()
1226/// # .https_or_http()
1227/// # .enable_http2()
1228/// # .build()
1229/// # );
1230/// # let mut hub = ServiceBroker::new(client, auth);
1231/// // As the method needs a request, you would usually fill it with the desired information
1232/// // into the respective structure. Some of the parts shown here might not be applicable !
1233/// // Values shown here are possibly random and not representative !
1234/// let mut req = GoogleIamV1__TestIamPermissionsRequest::default();
1235///
1236/// // You can configure optional parameters by calling the respective setters at will, and
1237/// // execute the final call using `doit()`.
1238/// // Values shown here are possibly random and not representative !
1239/// let result = hub.methods().test_iam_permissions(req, "resource")
1240/// .doit().await;
1241/// # }
1242/// ```
1243pub struct MethodTestIamPermissionCall<'a, C>
1244where
1245 C: 'a,
1246{
1247 hub: &'a ServiceBroker<C>,
1248 _request: GoogleIamV1__TestIamPermissionsRequest,
1249 _resource: String,
1250 _delegate: Option<&'a mut dyn common::Delegate>,
1251 _additional_params: HashMap<String, String>,
1252 _scopes: BTreeSet<String>,
1253}
1254
1255impl<'a, C> common::CallBuilder for MethodTestIamPermissionCall<'a, C> {}
1256
1257impl<'a, C> MethodTestIamPermissionCall<'a, C>
1258where
1259 C: common::Connector,
1260{
1261 /// Perform the operation you have build so far.
1262 pub async fn doit(
1263 mut self,
1264 ) -> common::Result<(common::Response, GoogleIamV1__TestIamPermissionsResponse)> {
1265 use std::borrow::Cow;
1266 use std::io::{Read, Seek};
1267
1268 use common::{url::Params, ToParts};
1269 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1270
1271 let mut dd = common::DefaultDelegate;
1272 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1273 dlg.begin(common::MethodInfo {
1274 id: "servicebroker.testIamPermissions",
1275 http_method: hyper::Method::POST,
1276 });
1277
1278 for &field in ["alt", "resource"].iter() {
1279 if self._additional_params.contains_key(field) {
1280 dlg.finished(false);
1281 return Err(common::Error::FieldClash(field));
1282 }
1283 }
1284
1285 let mut params = Params::with_capacity(4 + self._additional_params.len());
1286 params.push("resource", self._resource);
1287
1288 params.extend(self._additional_params.iter());
1289
1290 params.push("alt", "json");
1291 let mut url = self.hub._base_url.clone() + "v1/{+resource}:testIamPermissions";
1292 if self._scopes.is_empty() {
1293 self._scopes
1294 .insert(Scope::CloudPlatform.as_ref().to_string());
1295 }
1296
1297 #[allow(clippy::single_element_loop)]
1298 for &(find_this, param_name) in [("{+resource}", "resource")].iter() {
1299 url = params.uri_replacement(url, param_name, find_this, true);
1300 }
1301 {
1302 let to_remove = ["resource"];
1303 params.remove_params(&to_remove);
1304 }
1305
1306 let url = params.parse_with_url(&url);
1307
1308 let mut json_mime_type = mime::APPLICATION_JSON;
1309 let mut request_value_reader = {
1310 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1311 common::remove_json_null_values(&mut value);
1312 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1313 serde_json::to_writer(&mut dst, &value).unwrap();
1314 dst
1315 };
1316 let request_size = request_value_reader
1317 .seek(std::io::SeekFrom::End(0))
1318 .unwrap();
1319 request_value_reader
1320 .seek(std::io::SeekFrom::Start(0))
1321 .unwrap();
1322
1323 loop {
1324 let token = match self
1325 .hub
1326 .auth
1327 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1328 .await
1329 {
1330 Ok(token) => token,
1331 Err(e) => match dlg.token(e) {
1332 Ok(token) => token,
1333 Err(e) => {
1334 dlg.finished(false);
1335 return Err(common::Error::MissingToken(e));
1336 }
1337 },
1338 };
1339 request_value_reader
1340 .seek(std::io::SeekFrom::Start(0))
1341 .unwrap();
1342 let mut req_result = {
1343 let client = &self.hub.client;
1344 dlg.pre_request();
1345 let mut req_builder = hyper::Request::builder()
1346 .method(hyper::Method::POST)
1347 .uri(url.as_str())
1348 .header(USER_AGENT, self.hub._user_agent.clone());
1349
1350 if let Some(token) = token.as_ref() {
1351 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1352 }
1353
1354 let request = req_builder
1355 .header(CONTENT_TYPE, json_mime_type.to_string())
1356 .header(CONTENT_LENGTH, request_size as u64)
1357 .body(common::to_body(
1358 request_value_reader.get_ref().clone().into(),
1359 ));
1360
1361 client.request(request.unwrap()).await
1362 };
1363
1364 match req_result {
1365 Err(err) => {
1366 if let common::Retry::After(d) = dlg.http_error(&err) {
1367 sleep(d).await;
1368 continue;
1369 }
1370 dlg.finished(false);
1371 return Err(common::Error::HttpError(err));
1372 }
1373 Ok(res) => {
1374 let (mut parts, body) = res.into_parts();
1375 let mut body = common::Body::new(body);
1376 if !parts.status.is_success() {
1377 let bytes = common::to_bytes(body).await.unwrap_or_default();
1378 let error = serde_json::from_str(&common::to_string(&bytes));
1379 let response = common::to_response(parts, bytes.into());
1380
1381 if let common::Retry::After(d) =
1382 dlg.http_failure(&response, error.as_ref().ok())
1383 {
1384 sleep(d).await;
1385 continue;
1386 }
1387
1388 dlg.finished(false);
1389
1390 return Err(match error {
1391 Ok(value) => common::Error::BadRequest(value),
1392 _ => common::Error::Failure(response),
1393 });
1394 }
1395 let response = {
1396 let bytes = common::to_bytes(body).await.unwrap_or_default();
1397 let encoded = common::to_string(&bytes);
1398 match serde_json::from_str(&encoded) {
1399 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1400 Err(error) => {
1401 dlg.response_json_decode_error(&encoded, &error);
1402 return Err(common::Error::JsonDecodeError(
1403 encoded.to_string(),
1404 error,
1405 ));
1406 }
1407 }
1408 };
1409
1410 dlg.finished(true);
1411 return Ok(response);
1412 }
1413 }
1414 }
1415 }
1416
1417 ///
1418 /// Sets the *request* property to the given value.
1419 ///
1420 /// Even though the property as already been set when instantiating this call,
1421 /// we provide this method for API completeness.
1422 pub fn request(
1423 mut self,
1424 new_value: GoogleIamV1__TestIamPermissionsRequest,
1425 ) -> MethodTestIamPermissionCall<'a, C> {
1426 self._request = new_value;
1427 self
1428 }
1429 /// REQUIRED: The resource for which the policy detail is being requested.
1430 /// See the operation documentation for the appropriate value for this field.
1431 ///
1432 /// Sets the *resource* path property to the given value.
1433 ///
1434 /// Even though the property as already been set when instantiating this call,
1435 /// we provide this method for API completeness.
1436 pub fn resource(mut self, new_value: &str) -> MethodTestIamPermissionCall<'a, C> {
1437 self._resource = new_value.to_string();
1438 self
1439 }
1440 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1441 /// while executing the actual API request.
1442 ///
1443 /// ````text
1444 /// It should be used to handle progress information, and to implement a certain level of resilience.
1445 /// ````
1446 ///
1447 /// Sets the *delegate* property to the given value.
1448 pub fn delegate(
1449 mut self,
1450 new_value: &'a mut dyn common::Delegate,
1451 ) -> MethodTestIamPermissionCall<'a, C> {
1452 self._delegate = Some(new_value);
1453 self
1454 }
1455
1456 /// Set any additional parameter of the query string used in the request.
1457 /// It should be used to set parameters which are not yet available through their own
1458 /// setters.
1459 ///
1460 /// Please note that this method must not be used to set any of the known parameters
1461 /// which have their own setter method. If done anyway, the request will fail.
1462 ///
1463 /// # Additional Parameters
1464 ///
1465 /// * *$.xgafv* (query-string) - V1 error format.
1466 /// * *access_token* (query-string) - OAuth access token.
1467 /// * *alt* (query-string) - Data format for response.
1468 /// * *callback* (query-string) - JSONP
1469 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1470 /// * *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.
1471 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1472 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1473 /// * *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.
1474 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1475 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1476 pub fn param<T>(mut self, name: T, value: T) -> MethodTestIamPermissionCall<'a, C>
1477 where
1478 T: AsRef<str>,
1479 {
1480 self._additional_params
1481 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1482 self
1483 }
1484
1485 /// Identifies the authorization scope for the method you are building.
1486 ///
1487 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1488 /// [`Scope::CloudPlatform`].
1489 ///
1490 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1491 /// tokens for more than one scope.
1492 ///
1493 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1494 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1495 /// sufficient, a read-write scope will do as well.
1496 pub fn add_scope<St>(mut self, scope: St) -> MethodTestIamPermissionCall<'a, C>
1497 where
1498 St: AsRef<str>,
1499 {
1500 self._scopes.insert(String::from(scope.as_ref()));
1501 self
1502 }
1503 /// Identifies the authorization scope(s) for the method you are building.
1504 ///
1505 /// See [`Self::add_scope()`] for details.
1506 pub fn add_scopes<I, St>(mut self, scopes: I) -> MethodTestIamPermissionCall<'a, C>
1507 where
1508 I: IntoIterator<Item = St>,
1509 St: AsRef<str>,
1510 {
1511 self._scopes
1512 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1513 self
1514 }
1515
1516 /// Removes all scopes, and no default scope will be used either.
1517 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1518 /// for details).
1519 pub fn clear_scopes(mut self) -> MethodTestIamPermissionCall<'a, C> {
1520 self._scopes.clear();
1521 self
1522 }
1523}