google_orgpolicy2/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 OrgPolicyAPI 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_orgpolicy2 as orgpolicy2;
49/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
50/// use orgpolicy2::{Result, Error};
51/// # async fn dox() {
52/// use orgpolicy2::{OrgPolicyAPI, 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 = OrgPolicyAPI::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 = GoogleCloudOrgpolicyV2Policy::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.folders().policies_patch(req, "name")
99/// .update_mask(FieldMask::new::<&str>(&[]))
100/// .doit().await;
101///
102/// match result {
103/// Err(e) => match e {
104/// // The Error enum provides details about what exactly happened.
105/// // You can also just use its `Debug`, `Display` or `Error` traits
106/// Error::HttpError(_)
107/// |Error::Io(_)
108/// |Error::MissingAPIKey
109/// |Error::MissingToken(_)
110/// |Error::Cancelled
111/// |Error::UploadSizeLimitExceeded(_, _)
112/// |Error::Failure(_)
113/// |Error::BadRequest(_)
114/// |Error::FieldClash(_)
115/// |Error::JsonDecodeError(_, _) => println!("{}", e),
116/// },
117/// Ok(res) => println!("Success: {:?}", res),
118/// }
119/// # }
120/// ```
121#[derive(Clone)]
122pub struct OrgPolicyAPI<C> {
123 pub client: common::Client<C>,
124 pub auth: Box<dyn common::GetToken>,
125 _user_agent: String,
126 _base_url: String,
127 _root_url: String,
128}
129
130impl<C> common::Hub for OrgPolicyAPI<C> {}
131
132impl<'a, C> OrgPolicyAPI<C> {
133 pub fn new<A: 'static + common::GetToken>(
134 client: common::Client<C>,
135 auth: A,
136 ) -> OrgPolicyAPI<C> {
137 OrgPolicyAPI {
138 client,
139 auth: Box::new(auth),
140 _user_agent: "google-api-rust-client/7.0.0".to_string(),
141 _base_url: "https://orgpolicy.googleapis.com/".to_string(),
142 _root_url: "https://orgpolicy.googleapis.com/".to_string(),
143 }
144 }
145
146 pub fn folders(&'a self) -> FolderMethods<'a, C> {
147 FolderMethods { hub: self }
148 }
149 pub fn organizations(&'a self) -> OrganizationMethods<'a, C> {
150 OrganizationMethods { hub: self }
151 }
152 pub fn projects(&'a self) -> ProjectMethods<'a, C> {
153 ProjectMethods { hub: self }
154 }
155
156 /// Set the user-agent header field to use in all requests to the server.
157 /// It defaults to `google-api-rust-client/7.0.0`.
158 ///
159 /// Returns the previously set user-agent.
160 pub fn user_agent(&mut self, agent_name: String) -> String {
161 std::mem::replace(&mut self._user_agent, agent_name)
162 }
163
164 /// Set the base url to use in all requests to the server.
165 /// It defaults to `https://orgpolicy.googleapis.com/`.
166 ///
167 /// Returns the previously set base url.
168 pub fn base_url(&mut self, new_base_url: String) -> String {
169 std::mem::replace(&mut self._base_url, new_base_url)
170 }
171
172 /// Set the root url to use in all requests to the server.
173 /// It defaults to `https://orgpolicy.googleapis.com/`.
174 ///
175 /// Returns the previously set root url.
176 pub fn root_url(&mut self, new_root_url: String) -> String {
177 std::mem::replace(&mut self._root_url, new_root_url)
178 }
179}
180
181// ############
182// SCHEMAS ###
183// ##########
184/// Similar to PolicySpec but with an extra 'launch' field for launch reference. The PolicySpec here is specific for dry-run.
185///
186/// This type is not used in any activity, and only used as *part* of another schema.
187///
188#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
189#[serde_with::serde_as]
190#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
191pub struct GoogleCloudOrgpolicyV2AlternatePolicySpec {
192 /// Reference to the launch that will be used while audit logging and to control the launch. Should be set only in the alternate policy.
193 pub launch: Option<String>,
194 /// Specify constraint for configurations of Google Cloud resources.
195 pub spec: Option<GoogleCloudOrgpolicyV2PolicySpec>,
196}
197
198impl common::Part for GoogleCloudOrgpolicyV2AlternatePolicySpec {}
199
200/// A constraint describes a way to restrict resource's configuration. For example, you could enforce a constraint that controls which Google Cloud services can be activated across an organization, or whether a Compute Engine instance can have serial port connections established. Constraints can be configured by the organization policy administrator to fit the needs of the organization by setting a policy that includes constraints at different locations in the organization's resource hierarchy. Policies are inherited down the resource hierarchy from higher levels, but can also be overridden. For details about the inheritance rules, see `Policy`. Constraints have a default behavior determined by the `constraint_default` field, which is the enforcement behavior that is used in the absence of a policy being defined or inherited for the resource in question.
201///
202/// This type is not used in any activity, and only used as *part* of another schema.
203///
204#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
205#[serde_with::serde_as]
206#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
207pub struct GoogleCloudOrgpolicyV2Constraint {
208 /// Defines this constraint as being a boolean constraint.
209 #[serde(rename = "booleanConstraint")]
210 pub boolean_constraint: Option<GoogleCloudOrgpolicyV2ConstraintBooleanConstraint>,
211 /// The evaluation behavior of this constraint in the absence of a policy.
212 #[serde(rename = "constraintDefault")]
213 pub constraint_default: Option<String>,
214 /// Detailed description of what this constraint controls as well as how and where it is enforced. Mutable.
215 pub description: Option<String>,
216 /// The human readable name. Mutable.
217 #[serde(rename = "displayName")]
218 pub display_name: Option<String>,
219 /// Managed constraint and canned constraint sometimes can have equivalents. This field is used to store the equivalent constraint name.
220 #[serde(rename = "equivalentConstraint")]
221 pub equivalent_constraint: Option<String>,
222 /// Defines this constraint as being a list constraint.
223 #[serde(rename = "listConstraint")]
224 pub list_constraint: Option<GoogleCloudOrgpolicyV2ConstraintListConstraint>,
225 /// Immutable. The resource name of the constraint. Must be in one of the following forms: * `projects/{project_number}/constraints/{constraint_name}` * `folders/{folder_id}/constraints/{constraint_name}` * `organizations/{organization_id}/constraints/{constraint_name}` For example, "/projects/123/constraints/compute.disableSerialPortAccess".
226 pub name: Option<String>,
227 /// Shows if dry run is supported for this constraint or not.
228 #[serde(rename = "supportsDryRun")]
229 pub supports_dry_run: Option<bool>,
230 /// Shows if simulation is supported for this constraint or not.
231 #[serde(rename = "supportsSimulation")]
232 pub supports_simulation: Option<bool>,
233}
234
235impl common::Part for GoogleCloudOrgpolicyV2Constraint {}
236
237/// A constraint type is enforced or not enforced, which is configured in the `PolicyRule`. If `customConstraintDefinition` is defined, this constraint is a managed constraint.
238///
239/// This type is not used in any activity, and only used as *part* of another schema.
240///
241#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
242#[serde_with::serde_as]
243#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
244pub struct GoogleCloudOrgpolicyV2ConstraintBooleanConstraint {
245 /// Custom constraint definition. Defines this as a managed constraint.
246 #[serde(rename = "customConstraintDefinition")]
247 pub custom_constraint_definition:
248 Option<GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinition>,
249}
250
251impl common::Part for GoogleCloudOrgpolicyV2ConstraintBooleanConstraint {}
252
253/// Custom constraint definition. Defines this as a managed constraint.
254///
255/// This type is not used in any activity, and only used as *part* of another schema.
256///
257#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
258#[serde_with::serde_as]
259#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
260pub struct GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinition {
261 /// Allow or deny type.
262 #[serde(rename = "actionType")]
263 pub action_type: Option<String>,
264 /// Org policy condition/expression. For example: `resource.instanceName.matches("(production|test)_(.+_)?[\d]+")` or, `resource.management.auto_upgrade == true` The max length of the condition is 1000 characters.
265 pub condition: Option<String>,
266 /// All the operations being applied for this constraint.
267 #[serde(rename = "methodTypes")]
268 pub method_types: Option<Vec<String>>,
269 /// Stores the structure of `Parameters` used by the constraint condition. The key of `map` represents the name of the parameter.
270 pub parameters: Option<
271 HashMap<String, GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameter>,
272 >,
273 /// The resource instance type on which this policy applies. Format will be of the form : `/` Example: * `compute.googleapis.com/Instance`.
274 #[serde(rename = "resourceTypes")]
275 pub resource_types: Option<Vec<String>>,
276}
277
278impl common::Part for GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinition {}
279
280/// Defines a parameter structure.
281///
282/// This type is not used in any activity, and only used as *part* of another schema.
283///
284#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
285#[serde_with::serde_as]
286#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
287pub struct GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameter {
288 /// Sets the value of the parameter in an assignment if no value is given.
289 #[serde(rename = "defaultValue")]
290 pub default_value: Option<serde_json::Value>,
291 /// Determines the parameter's value structure. For example, `LIST` can be specified by defining `type: LIST`, and `item: STRING`.
292 pub item: Option<String>,
293 /// Defines subproperties primarily used by the UI to display user-friendly information.
294 pub metadata:
295 Option<GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameterMetadata>,
296 /// Type of the parameter.
297 #[serde(rename = "type")]
298 pub type_: Option<String>,
299 /// Provides a CEL expression to specify the acceptable parameter values during assignment. For example, parameterName in ("parameterValue1", "parameterValue2")
300 #[serde(rename = "validValuesExpr")]
301 pub valid_values_expr: Option<String>,
302}
303
304impl common::Part for GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameter {}
305
306/// Defines Metadata structure.
307///
308/// This type is not used in any activity, and only used as *part* of another schema.
309///
310#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
311#[serde_with::serde_as]
312#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
313pub struct GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameterMetadata {
314 /// Detailed description of what this `parameter` is and use of it. Mutable.
315 pub description: Option<String>,
316}
317
318impl common::Part for GoogleCloudOrgpolicyV2ConstraintCustomConstraintDefinitionParameterMetadata {}
319
320/// A constraint type that allows or disallows a list of string values, which are configured in the `PolicyRule`.
321///
322/// This type is not used in any activity, and only used as *part* of another schema.
323///
324#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
325#[serde_with::serde_as]
326#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
327pub struct GoogleCloudOrgpolicyV2ConstraintListConstraint {
328 /// Indicates whether values grouped into categories can be used in `Policy.allowed_values` and `Policy.denied_values`. For example, `"in:Python"` would match any value in the 'Python' group.
329 #[serde(rename = "supportsIn")]
330 pub supports_in: Option<bool>,
331 /// Indicates whether subtrees of the Resource Manager resource hierarchy can be used in `Policy.allowed_values` and `Policy.denied_values`. For example, `"under:folders/123"` would match any resource under the 'folders/123' folder.
332 #[serde(rename = "supportsUnder")]
333 pub supports_under: Option<bool>,
334}
335
336impl common::Part for GoogleCloudOrgpolicyV2ConstraintListConstraint {}
337
338/// A custom constraint defined by customers which can *only* be applied to the given resource types and organization. By creating a custom constraint, customers can apply policies of this custom constraint. *Creating a custom constraint itself does NOT apply any policy enforcement*.
339///
340/// # Activities
341///
342/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
343/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
344///
345/// * [custom constraints create organizations](OrganizationCustomConstraintCreateCall) (request|response)
346/// * [custom constraints get organizations](OrganizationCustomConstraintGetCall) (response)
347/// * [custom constraints patch organizations](OrganizationCustomConstraintPatchCall) (request|response)
348#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
349#[serde_with::serde_as]
350#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
351pub struct GoogleCloudOrgpolicyV2CustomConstraint {
352 /// Allow or deny type.
353 #[serde(rename = "actionType")]
354 pub action_type: Option<String>,
355 /// A Common Expression Language (CEL) condition which is used in the evaluation of the constraint. For example: `resource.instanceName.matches("(production|test)_(.+_)?[\d]+")` or, `resource.management.auto_upgrade == true` The max length of the condition is 1000 characters.
356 pub condition: Option<String>,
357 /// Detailed information about this custom policy constraint. The max length of the description is 2000 characters.
358 pub description: Option<String>,
359 /// One line display name for the UI. The max length of the display_name is 200 characters.
360 #[serde(rename = "displayName")]
361 pub display_name: Option<String>,
362 /// All the operations being applied for this constraint.
363 #[serde(rename = "methodTypes")]
364 pub method_types: Option<Vec<String>>,
365 /// Immutable. Name of the constraint. This is unique within the organization. Format of the name should be * `organizations/{organization_id}/customConstraints/{custom_constraint_id}` Example: `organizations/123/customConstraints/custom.createOnlyE2TypeVms` The max length is 70 characters and the minimum length is 1. Note that the prefix `organizations/{organization_id}/customConstraints/` is not counted.
366 pub name: Option<String>,
367 /// Immutable. The resource instance type on which this policy applies. Format will be of the form : `/` Example: * `compute.googleapis.com/Instance`.
368 #[serde(rename = "resourceTypes")]
369 pub resource_types: Option<Vec<String>>,
370 /// Output only. The last time this custom constraint was updated. This represents the last time that the `CreateCustomConstraint` or `UpdateCustomConstraint` methods were called.
371 #[serde(rename = "updateTime")]
372 pub update_time: Option<chrono::DateTime<chrono::offset::Utc>>,
373}
374
375impl common::RequestValue for GoogleCloudOrgpolicyV2CustomConstraint {}
376impl common::ResponseResult for GoogleCloudOrgpolicyV2CustomConstraint {}
377
378/// The response returned from the ListConstraints method.
379///
380/// # Activities
381///
382/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
383/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
384///
385/// * [constraints list folders](FolderConstraintListCall) (response)
386/// * [constraints list organizations](OrganizationConstraintListCall) (response)
387/// * [constraints list projects](ProjectConstraintListCall) (response)
388#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
389#[serde_with::serde_as]
390#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
391pub struct GoogleCloudOrgpolicyV2ListConstraintsResponse {
392 /// The collection of constraints that are available on the targeted resource.
393 pub constraints: Option<Vec<GoogleCloudOrgpolicyV2Constraint>>,
394 /// Page token used to retrieve the next page. This is currently not used.
395 #[serde(rename = "nextPageToken")]
396 pub next_page_token: Option<String>,
397}
398
399impl common::ResponseResult for GoogleCloudOrgpolicyV2ListConstraintsResponse {}
400
401/// The response returned from the ListCustomConstraints method. It will be empty if no custom or managed constraints are set on the organization resource.
402///
403/// # Activities
404///
405/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
406/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
407///
408/// * [custom constraints list organizations](OrganizationCustomConstraintListCall) (response)
409#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
410#[serde_with::serde_as]
411#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
412pub struct GoogleCloudOrgpolicyV2ListCustomConstraintsResponse {
413 /// All custom and managed constraints that exist on the organization resource. It will be empty if no custom constraints are set.
414 #[serde(rename = "customConstraints")]
415 pub custom_constraints: Option<Vec<GoogleCloudOrgpolicyV2CustomConstraint>>,
416 /// Page token used to retrieve the next page. This is currently not used, but the server may at any point start supplying a valid token.
417 #[serde(rename = "nextPageToken")]
418 pub next_page_token: Option<String>,
419}
420
421impl common::ResponseResult for GoogleCloudOrgpolicyV2ListCustomConstraintsResponse {}
422
423/// The response returned from the ListPolicies method. It will be empty if no policies are set on the resource.
424///
425/// # Activities
426///
427/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
428/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
429///
430/// * [policies list folders](FolderPolicyListCall) (response)
431/// * [policies list organizations](OrganizationPolicyListCall) (response)
432/// * [policies list projects](ProjectPolicyListCall) (response)
433#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
434#[serde_with::serde_as]
435#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
436pub struct GoogleCloudOrgpolicyV2ListPoliciesResponse {
437 /// Page token used to retrieve the next page. This is currently not used, but the server may at any point start supplying a valid token.
438 #[serde(rename = "nextPageToken")]
439 pub next_page_token: Option<String>,
440 /// All policies that exist on the resource. It will be empty if no policies are set.
441 pub policies: Option<Vec<GoogleCloudOrgpolicyV2Policy>>,
442}
443
444impl common::ResponseResult for GoogleCloudOrgpolicyV2ListPoliciesResponse {}
445
446/// Defines an organization policy which is used to specify constraints for configurations of Google Cloud resources.
447///
448/// # Activities
449///
450/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
451/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
452///
453/// * [policies create folders](FolderPolicyCreateCall) (request|response)
454/// * [policies get folders](FolderPolicyGetCall) (response)
455/// * [policies get effective policy folders](FolderPolicyGetEffectivePolicyCall) (response)
456/// * [policies patch folders](FolderPolicyPatchCall) (request|response)
457/// * [policies create organizations](OrganizationPolicyCreateCall) (request|response)
458/// * [policies get organizations](OrganizationPolicyGetCall) (response)
459/// * [policies get effective policy organizations](OrganizationPolicyGetEffectivePolicyCall) (response)
460/// * [policies patch organizations](OrganizationPolicyPatchCall) (request|response)
461/// * [policies create projects](ProjectPolicyCreateCall) (request|response)
462/// * [policies get projects](ProjectPolicyGetCall) (response)
463/// * [policies get effective policy projects](ProjectPolicyGetEffectivePolicyCall) (response)
464/// * [policies patch projects](ProjectPolicyPatchCall) (request|response)
465#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
466#[serde_with::serde_as]
467#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
468pub struct GoogleCloudOrgpolicyV2Policy {
469 /// Deprecated.
470 pub alternate: Option<GoogleCloudOrgpolicyV2AlternatePolicySpec>,
471 /// Dry-run policy. Audit-only policy, can be used to monitor how the policy would have impacted the existing and future resources if it's enforced.
472 #[serde(rename = "dryRunSpec")]
473 pub dry_run_spec: Option<GoogleCloudOrgpolicyV2PolicySpec>,
474 /// Optional. An opaque tag indicating the current state of the policy, used for concurrency control. This 'etag' is computed by the server based on the value of other fields, and may be sent on update and delete requests to ensure the client has an up-to-date value before proceeding.
475 pub etag: Option<String>,
476 /// Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
477 pub name: Option<String>,
478 /// Basic information about the organization policy.
479 pub spec: Option<GoogleCloudOrgpolicyV2PolicySpec>,
480}
481
482impl common::RequestValue for GoogleCloudOrgpolicyV2Policy {}
483impl common::ResponseResult for GoogleCloudOrgpolicyV2Policy {}
484
485/// Defines a Google Cloud policy specification which is used to specify constraints for configurations of Google Cloud resources.
486///
487/// This type is not used in any activity, and only used as *part* of another schema.
488///
489#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
490#[serde_with::serde_as]
491#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
492pub struct GoogleCloudOrgpolicyV2PolicySpec {
493 /// An opaque tag indicating the current version of the policySpec, used for concurrency control. This field is ignored if used in a `CreatePolicy` request. When the policy is returned from either a `GetPolicy` or a `ListPolicies` request, this `etag` indicates the version of the current policySpec to use when executing a read-modify-write loop. When the policy is returned from a `GetEffectivePolicy` request, the `etag` will be unset.
494 pub etag: Option<String>,
495 /// Determines the inheritance behavior for this policy. If `inherit_from_parent` is true, policy rules set higher up in the hierarchy (up to the closest root) are inherited and present in the effective policy. If it is false, then no rules are inherited, and this policy becomes the new root for evaluation. This field can be set only for policies which configure list constraints.
496 #[serde(rename = "inheritFromParent")]
497 pub inherit_from_parent: Option<bool>,
498 /// Ignores policies set above this resource and restores the `constraint_default` enforcement behavior of the specific constraint at this resource. This field can be set in policies for either list or boolean constraints. If set, `rules` must be empty and `inherit_from_parent` must be set to false.
499 pub reset: Option<bool>,
500 /// In policies for boolean constraints, the following requirements apply: - There must be one and only one policy rule where condition is unset. - Boolean policy rules with conditions must set `enforced` to the opposite of the policy rule without a condition. - During policy evaluation, policy rules with conditions that are true for a target resource take precedence.
501 pub rules: Option<Vec<GoogleCloudOrgpolicyV2PolicySpecPolicyRule>>,
502 /// Output only. The time stamp this was previously updated. This represents the last time a call to `CreatePolicy` or `UpdatePolicy` was made for that policy.
503 #[serde(rename = "updateTime")]
504 pub update_time: Option<chrono::DateTime<chrono::offset::Utc>>,
505}
506
507impl common::Part for GoogleCloudOrgpolicyV2PolicySpec {}
508
509/// A rule used to express this policy.
510///
511/// This type is not used in any activity, and only used as *part* of another schema.
512///
513#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
514#[serde_with::serde_as]
515#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
516pub struct GoogleCloudOrgpolicyV2PolicySpecPolicyRule {
517 /// Setting this to true means that all values are allowed. This field can be set only in policies for list constraints.
518 #[serde(rename = "allowAll")]
519 pub allow_all: Option<bool>,
520 /// A condition that determines whether this rule is used to evaluate the policy. When set, the google.type.Expr.expression field must contain 1 to 10 subexpressions, joined by the `||` or `&&` operators. Each subexpression must use the `resource.matchTag()`, `resource.matchTagId()`, `resource.hasTagKey()`, or `resource.hasTagKeyId()` Common Expression Language (CEL) function. The `resource.matchTag()` function takes the following arguments: * `key_name`: the namespaced name of the tag key, with the organization ID and a slash (`/`) as a prefix; for example, `123456789012/environment` * `value_name`: the short name of the tag value For example: `resource.matchTag('123456789012/environment, 'prod')` The `resource.matchTagId()` function takes the following arguments: * `key_id`: the permanent ID of the tag key; for example, `tagKeys/123456789012` * `value_id`: the permanent ID of the tag value; for example, `tagValues/567890123456` For example: `resource.matchTagId('tagKeys/123456789012', 'tagValues/567890123456')` The `resource.hasTagKey()` function takes the following argument: * `key_name`: the namespaced name of the tag key, with the organization ID and a slash (`/`) as a prefix; for example, `123456789012/environment` For example: `resource.hasTagKey('123456789012/environment')` The `resource.hasTagKeyId()` function takes the following arguments: * `key_id`: the permanent ID of the tag key; for example, `tagKeys/123456789012` For example: `resource.hasTagKeyId('tagKeys/123456789012')`
521 pub condition: Option<GoogleTypeExpr>,
522 /// Setting this to true means that all values are denied. This field can be set only in policies for list constraints.
523 #[serde(rename = "denyAll")]
524 pub deny_all: Option<bool>,
525 /// If `true`, then the policy is enforced. If `false`, then any configuration is acceptable. This field can be set in policies for boolean constraints, custom constraints and managed constraints.
526 pub enforce: Option<bool>,
527 /// Optional. Required for managed constraints if parameters are defined. Passes parameter values when policy enforcement is enabled. Ensure that parameter value types match those defined in the constraint definition. For example: ``` { "allowedLocations" : ["us-east1", "us-west1"], "allowAll" : true } ```
528 pub parameters: Option<HashMap<String, serde_json::Value>>,
529 /// List of values to be used for this policy rule. This field can be set only in policies for list constraints.
530 pub values: Option<GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues>,
531}
532
533impl common::Part for GoogleCloudOrgpolicyV2PolicySpecPolicyRule {}
534
535/// A message that holds specific allowed and denied values. This message can define specific values and subtrees of the Resource Manager resource hierarchy (`Organizations`, `Folders`, `Projects`) that are allowed or denied. This is achieved by using the `under:` and optional `is:` prefixes. The `under:` prefix is used to denote resource subtree values. The `is:` prefix is used to denote specific values, and is required only if the value contains a ":". Values prefixed with "is:" are treated the same as values with no prefix. Ancestry subtrees must be in one of the following formats: - `projects/` (for example, `projects/tokyo-rain-123`) - `folders/` (for example, `folders/1234`) - `organizations/` (for example, `organizations/1234`) The `supports_under` field of the associated `Constraint` defines whether ancestry prefixes can be used.
536///
537/// This type is not used in any activity, and only used as *part* of another schema.
538///
539#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
540#[serde_with::serde_as]
541#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
542pub struct GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues {
543 /// List of values allowed at this resource.
544 #[serde(rename = "allowedValues")]
545 pub allowed_values: Option<Vec<String>>,
546 /// List of values denied at this resource.
547 #[serde(rename = "deniedValues")]
548 pub denied_values: Option<Vec<String>>,
549}
550
551impl common::Part for GoogleCloudOrgpolicyV2PolicySpecPolicyRuleStringValues {}
552
553/// 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); }
554///
555/// # Activities
556///
557/// This type is used in activities, which are methods you may call on this type or where this type is involved in.
558/// The list links the activity name, along with information about where it is used (one of *request* and *response*).
559///
560/// * [policies delete folders](FolderPolicyDeleteCall) (response)
561/// * [custom constraints delete organizations](OrganizationCustomConstraintDeleteCall) (response)
562/// * [policies delete organizations](OrganizationPolicyDeleteCall) (response)
563/// * [policies delete projects](ProjectPolicyDeleteCall) (response)
564#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
565#[serde_with::serde_as]
566#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
567pub struct GoogleProtobufEmpty {
568 _never_set: Option<bool>,
569}
570
571impl common::ResponseResult for GoogleProtobufEmpty {}
572
573/// Represents a textual expression in the Common Expression Language (CEL) syntax. CEL is a C-like expression language. The syntax and semantics of CEL are documented at https://github.com/google/cel-spec. Example (Comparison): title: "Summary size limit" description: "Determines if a summary is less than 100 chars" expression: "document.summary.size() < 100" Example (Equality): title: "Requestor is owner" description: "Determines if requestor is the document owner" expression: "document.owner == request.auth.claims.email" Example (Logic): title: "Public documents" description: "Determine whether the document should be publicly visible" expression: "document.type != 'private' && document.type != 'internal'" Example (Data Manipulation): title: "Notification string" description: "Create a notification string with a timestamp." expression: "'New message received at ' + string(document.create_time)" The exact variables and functions that may be referenced within an expression are determined by the service that evaluates it. See the service documentation for additional information.
574///
575/// This type is not used in any activity, and only used as *part* of another schema.
576///
577#[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))]
578#[serde_with::serde_as]
579#[derive(Default, Clone, Debug, serde::Serialize, serde::Deserialize)]
580pub struct GoogleTypeExpr {
581 /// Optional. Description of the expression. This is a longer text which describes the expression, e.g. when hovered over it in a UI.
582 pub description: Option<String>,
583 /// Textual representation of an expression in Common Expression Language syntax.
584 pub expression: Option<String>,
585 /// Optional. String indicating the location of the expression for error reporting, e.g. a file name and a position in the file.
586 pub location: Option<String>,
587 /// Optional. Title for the expression, i.e. a short string describing its purpose. This can be used e.g. in UIs which allow to enter the expression.
588 pub title: Option<String>,
589}
590
591impl common::Part for GoogleTypeExpr {}
592
593// ###################
594// MethodBuilders ###
595// #################
596
597/// A builder providing access to all methods supported on *folder* resources.
598/// It is not used directly, but through the [`OrgPolicyAPI`] hub.
599///
600/// # Example
601///
602/// Instantiate a resource builder
603///
604/// ```test_harness,no_run
605/// extern crate hyper;
606/// extern crate hyper_rustls;
607/// extern crate google_orgpolicy2 as orgpolicy2;
608///
609/// # async fn dox() {
610/// use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
611///
612/// let secret: yup_oauth2::ApplicationSecret = Default::default();
613/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
614/// .with_native_roots()
615/// .unwrap()
616/// .https_only()
617/// .enable_http2()
618/// .build();
619///
620/// let executor = hyper_util::rt::TokioExecutor::new();
621/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
622/// secret,
623/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
624/// yup_oauth2::client::CustomHyperClientBuilder::from(
625/// hyper_util::client::legacy::Client::builder(executor).build(connector),
626/// ),
627/// ).build().await.unwrap();
628///
629/// let client = hyper_util::client::legacy::Client::builder(
630/// hyper_util::rt::TokioExecutor::new()
631/// )
632/// .build(
633/// hyper_rustls::HttpsConnectorBuilder::new()
634/// .with_native_roots()
635/// .unwrap()
636/// .https_or_http()
637/// .enable_http2()
638/// .build()
639/// );
640/// let mut hub = OrgPolicyAPI::new(client, auth);
641/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
642/// // like `constraints_list(...)`, `policies_create(...)`, `policies_delete(...)`, `policies_get(...)`, `policies_get_effective_policy(...)`, `policies_list(...)` and `policies_patch(...)`
643/// // to build up your call.
644/// let rb = hub.folders();
645/// # }
646/// ```
647pub struct FolderMethods<'a, C>
648where
649 C: 'a,
650{
651 hub: &'a OrgPolicyAPI<C>,
652}
653
654impl<'a, C> common::MethodsBuilder for FolderMethods<'a, C> {}
655
656impl<'a, C> FolderMethods<'a, C> {
657 /// Create a builder to help you perform the following task:
658 ///
659 /// Lists constraints that could be applied on the specified resource.
660 ///
661 /// # Arguments
662 ///
663 /// * `parent` - Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
664 pub fn constraints_list(&self, parent: &str) -> FolderConstraintListCall<'a, C> {
665 FolderConstraintListCall {
666 hub: self.hub,
667 _parent: parent.to_string(),
668 _page_token: Default::default(),
669 _page_size: Default::default(),
670 _delegate: Default::default(),
671 _additional_params: Default::default(),
672 _scopes: Default::default(),
673 }
674 }
675
676 /// Create a builder to help you perform the following task:
677 ///
678 /// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
679 ///
680 /// # Arguments
681 ///
682 /// * `request` - No description provided.
683 /// * `parent` - Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
684 pub fn policies_create(
685 &self,
686 request: GoogleCloudOrgpolicyV2Policy,
687 parent: &str,
688 ) -> FolderPolicyCreateCall<'a, C> {
689 FolderPolicyCreateCall {
690 hub: self.hub,
691 _request: request,
692 _parent: parent.to_string(),
693 _delegate: Default::default(),
694 _additional_params: Default::default(),
695 _scopes: Default::default(),
696 }
697 }
698
699 /// Create a builder to help you perform the following task:
700 ///
701 /// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
702 ///
703 /// # Arguments
704 ///
705 /// * `name` - Required. Name of the policy to delete. See the policy entry for naming rules.
706 pub fn policies_delete(&self, name: &str) -> FolderPolicyDeleteCall<'a, C> {
707 FolderPolicyDeleteCall {
708 hub: self.hub,
709 _name: name.to_string(),
710 _etag: Default::default(),
711 _delegate: Default::default(),
712 _additional_params: Default::default(),
713 _scopes: Default::default(),
714 }
715 }
716
717 /// Create a builder to help you perform the following task:
718 ///
719 /// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
720 ///
721 /// # Arguments
722 ///
723 /// * `name` - Required. Resource name of the policy. See Policy for naming requirements.
724 pub fn policies_get(&self, name: &str) -> FolderPolicyGetCall<'a, C> {
725 FolderPolicyGetCall {
726 hub: self.hub,
727 _name: name.to_string(),
728 _delegate: Default::default(),
729 _additional_params: Default::default(),
730 _scopes: Default::default(),
731 }
732 }
733
734 /// Create a builder to help you perform the following task:
735 ///
736 /// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
737 ///
738 /// # Arguments
739 ///
740 /// * `name` - Required. The effective policy to compute. See Policy for naming requirements.
741 pub fn policies_get_effective_policy(
742 &self,
743 name: &str,
744 ) -> FolderPolicyGetEffectivePolicyCall<'a, C> {
745 FolderPolicyGetEffectivePolicyCall {
746 hub: self.hub,
747 _name: name.to_string(),
748 _delegate: Default::default(),
749 _additional_params: Default::default(),
750 _scopes: Default::default(),
751 }
752 }
753
754 /// Create a builder to help you perform the following task:
755 ///
756 /// Retrieves all of the policies that exist on a particular resource.
757 ///
758 /// # Arguments
759 ///
760 /// * `parent` - Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
761 pub fn policies_list(&self, parent: &str) -> FolderPolicyListCall<'a, C> {
762 FolderPolicyListCall {
763 hub: self.hub,
764 _parent: parent.to_string(),
765 _page_token: Default::default(),
766 _page_size: Default::default(),
767 _delegate: Default::default(),
768 _additional_params: Default::default(),
769 _scopes: Default::default(),
770 }
771 }
772
773 /// Create a builder to help you perform the following task:
774 ///
775 /// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
776 ///
777 /// # Arguments
778 ///
779 /// * `request` - No description provided.
780 /// * `name` - Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
781 pub fn policies_patch(
782 &self,
783 request: GoogleCloudOrgpolicyV2Policy,
784 name: &str,
785 ) -> FolderPolicyPatchCall<'a, C> {
786 FolderPolicyPatchCall {
787 hub: self.hub,
788 _request: request,
789 _name: name.to_string(),
790 _update_mask: Default::default(),
791 _delegate: Default::default(),
792 _additional_params: Default::default(),
793 _scopes: Default::default(),
794 }
795 }
796}
797
798/// A builder providing access to all methods supported on *organization* resources.
799/// It is not used directly, but through the [`OrgPolicyAPI`] hub.
800///
801/// # Example
802///
803/// Instantiate a resource builder
804///
805/// ```test_harness,no_run
806/// extern crate hyper;
807/// extern crate hyper_rustls;
808/// extern crate google_orgpolicy2 as orgpolicy2;
809///
810/// # async fn dox() {
811/// use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
812///
813/// let secret: yup_oauth2::ApplicationSecret = Default::default();
814/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
815/// .with_native_roots()
816/// .unwrap()
817/// .https_only()
818/// .enable_http2()
819/// .build();
820///
821/// let executor = hyper_util::rt::TokioExecutor::new();
822/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
823/// secret,
824/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
825/// yup_oauth2::client::CustomHyperClientBuilder::from(
826/// hyper_util::client::legacy::Client::builder(executor).build(connector),
827/// ),
828/// ).build().await.unwrap();
829///
830/// let client = hyper_util::client::legacy::Client::builder(
831/// hyper_util::rt::TokioExecutor::new()
832/// )
833/// .build(
834/// hyper_rustls::HttpsConnectorBuilder::new()
835/// .with_native_roots()
836/// .unwrap()
837/// .https_or_http()
838/// .enable_http2()
839/// .build()
840/// );
841/// let mut hub = OrgPolicyAPI::new(client, auth);
842/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
843/// // like `constraints_list(...)`, `custom_constraints_create(...)`, `custom_constraints_delete(...)`, `custom_constraints_get(...)`, `custom_constraints_list(...)`, `custom_constraints_patch(...)`, `policies_create(...)`, `policies_delete(...)`, `policies_get(...)`, `policies_get_effective_policy(...)`, `policies_list(...)` and `policies_patch(...)`
844/// // to build up your call.
845/// let rb = hub.organizations();
846/// # }
847/// ```
848pub struct OrganizationMethods<'a, C>
849where
850 C: 'a,
851{
852 hub: &'a OrgPolicyAPI<C>,
853}
854
855impl<'a, C> common::MethodsBuilder for OrganizationMethods<'a, C> {}
856
857impl<'a, C> OrganizationMethods<'a, C> {
858 /// Create a builder to help you perform the following task:
859 ///
860 /// Lists constraints that could be applied on the specified resource.
861 ///
862 /// # Arguments
863 ///
864 /// * `parent` - Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
865 pub fn constraints_list(&self, parent: &str) -> OrganizationConstraintListCall<'a, C> {
866 OrganizationConstraintListCall {
867 hub: self.hub,
868 _parent: parent.to_string(),
869 _page_token: Default::default(),
870 _page_size: Default::default(),
871 _delegate: Default::default(),
872 _additional_params: Default::default(),
873 _scopes: Default::default(),
874 }
875 }
876
877 /// Create a builder to help you perform the following task:
878 ///
879 /// Creates a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the organization does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the constraint already exists on the given organization.
880 ///
881 /// # Arguments
882 ///
883 /// * `request` - No description provided.
884 /// * `parent` - Required. Must be in the following form: * `organizations/{organization_id}`
885 pub fn custom_constraints_create(
886 &self,
887 request: GoogleCloudOrgpolicyV2CustomConstraint,
888 parent: &str,
889 ) -> OrganizationCustomConstraintCreateCall<'a, C> {
890 OrganizationCustomConstraintCreateCall {
891 hub: self.hub,
892 _request: request,
893 _parent: parent.to_string(),
894 _delegate: Default::default(),
895 _additional_params: Default::default(),
896 _scopes: Default::default(),
897 }
898 }
899
900 /// Create a builder to help you perform the following task:
901 ///
902 /// Deletes a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist.
903 ///
904 /// # Arguments
905 ///
906 /// * `name` - Required. Name of the custom constraint to delete. See the custom constraint entry for naming rules.
907 pub fn custom_constraints_delete(
908 &self,
909 name: &str,
910 ) -> OrganizationCustomConstraintDeleteCall<'a, C> {
911 OrganizationCustomConstraintDeleteCall {
912 hub: self.hub,
913 _name: name.to_string(),
914 _delegate: Default::default(),
915 _additional_params: Default::default(),
916 _scopes: Default::default(),
917 }
918 }
919
920 /// Create a builder to help you perform the following task:
921 ///
922 /// Gets a custom or managed constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the custom or managed constraint does not exist.
923 ///
924 /// # Arguments
925 ///
926 /// * `name` - Required. Resource name of the custom or managed constraint. See the custom constraint entry for naming requirements.
927 pub fn custom_constraints_get(&self, name: &str) -> OrganizationCustomConstraintGetCall<'a, C> {
928 OrganizationCustomConstraintGetCall {
929 hub: self.hub,
930 _name: name.to_string(),
931 _delegate: Default::default(),
932 _additional_params: Default::default(),
933 _scopes: Default::default(),
934 }
935 }
936
937 /// Create a builder to help you perform the following task:
938 ///
939 /// Retrieves all of the custom constraints that exist on a particular organization resource.
940 ///
941 /// # Arguments
942 ///
943 /// * `parent` - Required. The target Google Cloud resource that parents the set of custom constraints that will be returned from this call. Must be in one of the following forms: * `organizations/{organization_id}`
944 pub fn custom_constraints_list(
945 &self,
946 parent: &str,
947 ) -> OrganizationCustomConstraintListCall<'a, C> {
948 OrganizationCustomConstraintListCall {
949 hub: self.hub,
950 _parent: parent.to_string(),
951 _page_token: Default::default(),
952 _page_size: Default::default(),
953 _delegate: Default::default(),
954 _additional_params: Default::default(),
955 _scopes: Default::default(),
956 }
957 }
958
959 /// Create a builder to help you perform the following task:
960 ///
961 /// Updates a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Note: the supplied policy will perform a full overwrite of all fields.
962 ///
963 /// # Arguments
964 ///
965 /// * `request` - No description provided.
966 /// * `name` - Immutable. Name of the constraint. This is unique within the organization. Format of the name should be * `organizations/{organization_id}/customConstraints/{custom_constraint_id}` Example: `organizations/123/customConstraints/custom.createOnlyE2TypeVms` The max length is 70 characters and the minimum length is 1. Note that the prefix `organizations/{organization_id}/customConstraints/` is not counted.
967 pub fn custom_constraints_patch(
968 &self,
969 request: GoogleCloudOrgpolicyV2CustomConstraint,
970 name: &str,
971 ) -> OrganizationCustomConstraintPatchCall<'a, C> {
972 OrganizationCustomConstraintPatchCall {
973 hub: self.hub,
974 _request: request,
975 _name: name.to_string(),
976 _delegate: Default::default(),
977 _additional_params: Default::default(),
978 _scopes: Default::default(),
979 }
980 }
981
982 /// Create a builder to help you perform the following task:
983 ///
984 /// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
985 ///
986 /// # Arguments
987 ///
988 /// * `request` - No description provided.
989 /// * `parent` - Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
990 pub fn policies_create(
991 &self,
992 request: GoogleCloudOrgpolicyV2Policy,
993 parent: &str,
994 ) -> OrganizationPolicyCreateCall<'a, C> {
995 OrganizationPolicyCreateCall {
996 hub: self.hub,
997 _request: request,
998 _parent: parent.to_string(),
999 _delegate: Default::default(),
1000 _additional_params: Default::default(),
1001 _scopes: Default::default(),
1002 }
1003 }
1004
1005 /// Create a builder to help you perform the following task:
1006 ///
1007 /// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
1008 ///
1009 /// # Arguments
1010 ///
1011 /// * `name` - Required. Name of the policy to delete. See the policy entry for naming rules.
1012 pub fn policies_delete(&self, name: &str) -> OrganizationPolicyDeleteCall<'a, C> {
1013 OrganizationPolicyDeleteCall {
1014 hub: self.hub,
1015 _name: name.to_string(),
1016 _etag: Default::default(),
1017 _delegate: Default::default(),
1018 _additional_params: Default::default(),
1019 _scopes: Default::default(),
1020 }
1021 }
1022
1023 /// Create a builder to help you perform the following task:
1024 ///
1025 /// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
1026 ///
1027 /// # Arguments
1028 ///
1029 /// * `name` - Required. Resource name of the policy. See Policy for naming requirements.
1030 pub fn policies_get(&self, name: &str) -> OrganizationPolicyGetCall<'a, C> {
1031 OrganizationPolicyGetCall {
1032 hub: self.hub,
1033 _name: name.to_string(),
1034 _delegate: Default::default(),
1035 _additional_params: Default::default(),
1036 _scopes: Default::default(),
1037 }
1038 }
1039
1040 /// Create a builder to help you perform the following task:
1041 ///
1042 /// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
1043 ///
1044 /// # Arguments
1045 ///
1046 /// * `name` - Required. The effective policy to compute. See Policy for naming requirements.
1047 pub fn policies_get_effective_policy(
1048 &self,
1049 name: &str,
1050 ) -> OrganizationPolicyGetEffectivePolicyCall<'a, C> {
1051 OrganizationPolicyGetEffectivePolicyCall {
1052 hub: self.hub,
1053 _name: name.to_string(),
1054 _delegate: Default::default(),
1055 _additional_params: Default::default(),
1056 _scopes: Default::default(),
1057 }
1058 }
1059
1060 /// Create a builder to help you perform the following task:
1061 ///
1062 /// Retrieves all of the policies that exist on a particular resource.
1063 ///
1064 /// # Arguments
1065 ///
1066 /// * `parent` - Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1067 pub fn policies_list(&self, parent: &str) -> OrganizationPolicyListCall<'a, C> {
1068 OrganizationPolicyListCall {
1069 hub: self.hub,
1070 _parent: parent.to_string(),
1071 _page_token: Default::default(),
1072 _page_size: Default::default(),
1073 _delegate: Default::default(),
1074 _additional_params: Default::default(),
1075 _scopes: Default::default(),
1076 }
1077 }
1078
1079 /// Create a builder to help you perform the following task:
1080 ///
1081 /// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
1082 ///
1083 /// # Arguments
1084 ///
1085 /// * `request` - No description provided.
1086 /// * `name` - Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
1087 pub fn policies_patch(
1088 &self,
1089 request: GoogleCloudOrgpolicyV2Policy,
1090 name: &str,
1091 ) -> OrganizationPolicyPatchCall<'a, C> {
1092 OrganizationPolicyPatchCall {
1093 hub: self.hub,
1094 _request: request,
1095 _name: name.to_string(),
1096 _update_mask: Default::default(),
1097 _delegate: Default::default(),
1098 _additional_params: Default::default(),
1099 _scopes: Default::default(),
1100 }
1101 }
1102}
1103
1104/// A builder providing access to all methods supported on *project* resources.
1105/// It is not used directly, but through the [`OrgPolicyAPI`] hub.
1106///
1107/// # Example
1108///
1109/// Instantiate a resource builder
1110///
1111/// ```test_harness,no_run
1112/// extern crate hyper;
1113/// extern crate hyper_rustls;
1114/// extern crate google_orgpolicy2 as orgpolicy2;
1115///
1116/// # async fn dox() {
1117/// use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1118///
1119/// let secret: yup_oauth2::ApplicationSecret = Default::default();
1120/// let connector = hyper_rustls::HttpsConnectorBuilder::new()
1121/// .with_native_roots()
1122/// .unwrap()
1123/// .https_only()
1124/// .enable_http2()
1125/// .build();
1126///
1127/// let executor = hyper_util::rt::TokioExecutor::new();
1128/// let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1129/// secret,
1130/// yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1131/// yup_oauth2::client::CustomHyperClientBuilder::from(
1132/// hyper_util::client::legacy::Client::builder(executor).build(connector),
1133/// ),
1134/// ).build().await.unwrap();
1135///
1136/// let client = hyper_util::client::legacy::Client::builder(
1137/// hyper_util::rt::TokioExecutor::new()
1138/// )
1139/// .build(
1140/// hyper_rustls::HttpsConnectorBuilder::new()
1141/// .with_native_roots()
1142/// .unwrap()
1143/// .https_or_http()
1144/// .enable_http2()
1145/// .build()
1146/// );
1147/// let mut hub = OrgPolicyAPI::new(client, auth);
1148/// // Usually you wouldn't bind this to a variable, but keep calling *CallBuilders*
1149/// // like `constraints_list(...)`, `policies_create(...)`, `policies_delete(...)`, `policies_get(...)`, `policies_get_effective_policy(...)`, `policies_list(...)` and `policies_patch(...)`
1150/// // to build up your call.
1151/// let rb = hub.projects();
1152/// # }
1153/// ```
1154pub struct ProjectMethods<'a, C>
1155where
1156 C: 'a,
1157{
1158 hub: &'a OrgPolicyAPI<C>,
1159}
1160
1161impl<'a, C> common::MethodsBuilder for ProjectMethods<'a, C> {}
1162
1163impl<'a, C> ProjectMethods<'a, C> {
1164 /// Create a builder to help you perform the following task:
1165 ///
1166 /// Lists constraints that could be applied on the specified resource.
1167 ///
1168 /// # Arguments
1169 ///
1170 /// * `parent` - Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1171 pub fn constraints_list(&self, parent: &str) -> ProjectConstraintListCall<'a, C> {
1172 ProjectConstraintListCall {
1173 hub: self.hub,
1174 _parent: parent.to_string(),
1175 _page_token: Default::default(),
1176 _page_size: Default::default(),
1177 _delegate: Default::default(),
1178 _additional_params: Default::default(),
1179 _scopes: Default::default(),
1180 }
1181 }
1182
1183 /// Create a builder to help you perform the following task:
1184 ///
1185 /// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
1186 ///
1187 /// # Arguments
1188 ///
1189 /// * `request` - No description provided.
1190 /// * `parent` - Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1191 pub fn policies_create(
1192 &self,
1193 request: GoogleCloudOrgpolicyV2Policy,
1194 parent: &str,
1195 ) -> ProjectPolicyCreateCall<'a, C> {
1196 ProjectPolicyCreateCall {
1197 hub: self.hub,
1198 _request: request,
1199 _parent: parent.to_string(),
1200 _delegate: Default::default(),
1201 _additional_params: Default::default(),
1202 _scopes: Default::default(),
1203 }
1204 }
1205
1206 /// Create a builder to help you perform the following task:
1207 ///
1208 /// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
1209 ///
1210 /// # Arguments
1211 ///
1212 /// * `name` - Required. Name of the policy to delete. See the policy entry for naming rules.
1213 pub fn policies_delete(&self, name: &str) -> ProjectPolicyDeleteCall<'a, C> {
1214 ProjectPolicyDeleteCall {
1215 hub: self.hub,
1216 _name: name.to_string(),
1217 _etag: Default::default(),
1218 _delegate: Default::default(),
1219 _additional_params: Default::default(),
1220 _scopes: Default::default(),
1221 }
1222 }
1223
1224 /// Create a builder to help you perform the following task:
1225 ///
1226 /// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
1227 ///
1228 /// # Arguments
1229 ///
1230 /// * `name` - Required. Resource name of the policy. See Policy for naming requirements.
1231 pub fn policies_get(&self, name: &str) -> ProjectPolicyGetCall<'a, C> {
1232 ProjectPolicyGetCall {
1233 hub: self.hub,
1234 _name: name.to_string(),
1235 _delegate: Default::default(),
1236 _additional_params: Default::default(),
1237 _scopes: Default::default(),
1238 }
1239 }
1240
1241 /// Create a builder to help you perform the following task:
1242 ///
1243 /// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
1244 ///
1245 /// # Arguments
1246 ///
1247 /// * `name` - Required. The effective policy to compute. See Policy for naming requirements.
1248 pub fn policies_get_effective_policy(
1249 &self,
1250 name: &str,
1251 ) -> ProjectPolicyGetEffectivePolicyCall<'a, C> {
1252 ProjectPolicyGetEffectivePolicyCall {
1253 hub: self.hub,
1254 _name: name.to_string(),
1255 _delegate: Default::default(),
1256 _additional_params: Default::default(),
1257 _scopes: Default::default(),
1258 }
1259 }
1260
1261 /// Create a builder to help you perform the following task:
1262 ///
1263 /// Retrieves all of the policies that exist on a particular resource.
1264 ///
1265 /// # Arguments
1266 ///
1267 /// * `parent` - Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1268 pub fn policies_list(&self, parent: &str) -> ProjectPolicyListCall<'a, C> {
1269 ProjectPolicyListCall {
1270 hub: self.hub,
1271 _parent: parent.to_string(),
1272 _page_token: Default::default(),
1273 _page_size: Default::default(),
1274 _delegate: Default::default(),
1275 _additional_params: Default::default(),
1276 _scopes: Default::default(),
1277 }
1278 }
1279
1280 /// Create a builder to help you perform the following task:
1281 ///
1282 /// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
1283 ///
1284 /// # Arguments
1285 ///
1286 /// * `request` - No description provided.
1287 /// * `name` - Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
1288 pub fn policies_patch(
1289 &self,
1290 request: GoogleCloudOrgpolicyV2Policy,
1291 name: &str,
1292 ) -> ProjectPolicyPatchCall<'a, C> {
1293 ProjectPolicyPatchCall {
1294 hub: self.hub,
1295 _request: request,
1296 _name: name.to_string(),
1297 _update_mask: Default::default(),
1298 _delegate: Default::default(),
1299 _additional_params: Default::default(),
1300 _scopes: Default::default(),
1301 }
1302 }
1303}
1304
1305// ###################
1306// CallBuilders ###
1307// #################
1308
1309/// Lists constraints that could be applied on the specified resource.
1310///
1311/// A builder for the *constraints.list* method supported by a *folder* resource.
1312/// It is not used directly, but through a [`FolderMethods`] instance.
1313///
1314/// # Example
1315///
1316/// Instantiate a resource method builder
1317///
1318/// ```test_harness,no_run
1319/// # extern crate hyper;
1320/// # extern crate hyper_rustls;
1321/// # extern crate google_orgpolicy2 as orgpolicy2;
1322/// # async fn dox() {
1323/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1324///
1325/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1326/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1327/// # .with_native_roots()
1328/// # .unwrap()
1329/// # .https_only()
1330/// # .enable_http2()
1331/// # .build();
1332///
1333/// # let executor = hyper_util::rt::TokioExecutor::new();
1334/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1335/// # secret,
1336/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1337/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1338/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1339/// # ),
1340/// # ).build().await.unwrap();
1341///
1342/// # let client = hyper_util::client::legacy::Client::builder(
1343/// # hyper_util::rt::TokioExecutor::new()
1344/// # )
1345/// # .build(
1346/// # hyper_rustls::HttpsConnectorBuilder::new()
1347/// # .with_native_roots()
1348/// # .unwrap()
1349/// # .https_or_http()
1350/// # .enable_http2()
1351/// # .build()
1352/// # );
1353/// # let mut hub = OrgPolicyAPI::new(client, auth);
1354/// // You can configure optional parameters by calling the respective setters at will, and
1355/// // execute the final call using `doit()`.
1356/// // Values shown here are possibly random and not representative !
1357/// let result = hub.folders().constraints_list("parent")
1358/// .page_token("voluptua.")
1359/// .page_size(-27)
1360/// .doit().await;
1361/// # }
1362/// ```
1363pub struct FolderConstraintListCall<'a, C>
1364where
1365 C: 'a,
1366{
1367 hub: &'a OrgPolicyAPI<C>,
1368 _parent: String,
1369 _page_token: Option<String>,
1370 _page_size: Option<i32>,
1371 _delegate: Option<&'a mut dyn common::Delegate>,
1372 _additional_params: HashMap<String, String>,
1373 _scopes: BTreeSet<String>,
1374}
1375
1376impl<'a, C> common::CallBuilder for FolderConstraintListCall<'a, C> {}
1377
1378impl<'a, C> FolderConstraintListCall<'a, C>
1379where
1380 C: common::Connector,
1381{
1382 /// Perform the operation you have build so far.
1383 pub async fn doit(
1384 mut self,
1385 ) -> common::Result<(
1386 common::Response,
1387 GoogleCloudOrgpolicyV2ListConstraintsResponse,
1388 )> {
1389 use std::borrow::Cow;
1390 use std::io::{Read, Seek};
1391
1392 use common::{url::Params, ToParts};
1393 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1394
1395 let mut dd = common::DefaultDelegate;
1396 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1397 dlg.begin(common::MethodInfo {
1398 id: "orgpolicy.folders.constraints.list",
1399 http_method: hyper::Method::GET,
1400 });
1401
1402 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
1403 if self._additional_params.contains_key(field) {
1404 dlg.finished(false);
1405 return Err(common::Error::FieldClash(field));
1406 }
1407 }
1408
1409 let mut params = Params::with_capacity(5 + self._additional_params.len());
1410 params.push("parent", self._parent);
1411 if let Some(value) = self._page_token.as_ref() {
1412 params.push("pageToken", value);
1413 }
1414 if let Some(value) = self._page_size.as_ref() {
1415 params.push("pageSize", value.to_string());
1416 }
1417
1418 params.extend(self._additional_params.iter());
1419
1420 params.push("alt", "json");
1421 let mut url = self.hub._base_url.clone() + "v2/{+parent}/constraints";
1422 if self._scopes.is_empty() {
1423 self._scopes
1424 .insert(Scope::CloudPlatform.as_ref().to_string());
1425 }
1426
1427 #[allow(clippy::single_element_loop)]
1428 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
1429 url = params.uri_replacement(url, param_name, find_this, true);
1430 }
1431 {
1432 let to_remove = ["parent"];
1433 params.remove_params(&to_remove);
1434 }
1435
1436 let url = params.parse_with_url(&url);
1437
1438 loop {
1439 let token = match self
1440 .hub
1441 .auth
1442 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1443 .await
1444 {
1445 Ok(token) => token,
1446 Err(e) => match dlg.token(e) {
1447 Ok(token) => token,
1448 Err(e) => {
1449 dlg.finished(false);
1450 return Err(common::Error::MissingToken(e));
1451 }
1452 },
1453 };
1454 let mut req_result = {
1455 let client = &self.hub.client;
1456 dlg.pre_request();
1457 let mut req_builder = hyper::Request::builder()
1458 .method(hyper::Method::GET)
1459 .uri(url.as_str())
1460 .header(USER_AGENT, self.hub._user_agent.clone());
1461
1462 if let Some(token) = token.as_ref() {
1463 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1464 }
1465
1466 let request = req_builder
1467 .header(CONTENT_LENGTH, 0_u64)
1468 .body(common::to_body::<String>(None));
1469
1470 client.request(request.unwrap()).await
1471 };
1472
1473 match req_result {
1474 Err(err) => {
1475 if let common::Retry::After(d) = dlg.http_error(&err) {
1476 sleep(d).await;
1477 continue;
1478 }
1479 dlg.finished(false);
1480 return Err(common::Error::HttpError(err));
1481 }
1482 Ok(res) => {
1483 let (mut parts, body) = res.into_parts();
1484 let mut body = common::Body::new(body);
1485 if !parts.status.is_success() {
1486 let bytes = common::to_bytes(body).await.unwrap_or_default();
1487 let error = serde_json::from_str(&common::to_string(&bytes));
1488 let response = common::to_response(parts, bytes.into());
1489
1490 if let common::Retry::After(d) =
1491 dlg.http_failure(&response, error.as_ref().ok())
1492 {
1493 sleep(d).await;
1494 continue;
1495 }
1496
1497 dlg.finished(false);
1498
1499 return Err(match error {
1500 Ok(value) => common::Error::BadRequest(value),
1501 _ => common::Error::Failure(response),
1502 });
1503 }
1504 let response = {
1505 let bytes = common::to_bytes(body).await.unwrap_or_default();
1506 let encoded = common::to_string(&bytes);
1507 match serde_json::from_str(&encoded) {
1508 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1509 Err(error) => {
1510 dlg.response_json_decode_error(&encoded, &error);
1511 return Err(common::Error::JsonDecodeError(
1512 encoded.to_string(),
1513 error,
1514 ));
1515 }
1516 }
1517 };
1518
1519 dlg.finished(true);
1520 return Ok(response);
1521 }
1522 }
1523 }
1524 }
1525
1526 /// Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1527 ///
1528 /// Sets the *parent* path property to the given value.
1529 ///
1530 /// Even though the property as already been set when instantiating this call,
1531 /// we provide this method for API completeness.
1532 pub fn parent(mut self, new_value: &str) -> FolderConstraintListCall<'a, C> {
1533 self._parent = new_value.to_string();
1534 self
1535 }
1536 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
1537 ///
1538 /// Sets the *page token* query property to the given value.
1539 pub fn page_token(mut self, new_value: &str) -> FolderConstraintListCall<'a, C> {
1540 self._page_token = Some(new_value.to_string());
1541 self
1542 }
1543 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
1544 ///
1545 /// Sets the *page size* query property to the given value.
1546 pub fn page_size(mut self, new_value: i32) -> FolderConstraintListCall<'a, C> {
1547 self._page_size = Some(new_value);
1548 self
1549 }
1550 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1551 /// while executing the actual API request.
1552 ///
1553 /// ````text
1554 /// It should be used to handle progress information, and to implement a certain level of resilience.
1555 /// ````
1556 ///
1557 /// Sets the *delegate* property to the given value.
1558 pub fn delegate(
1559 mut self,
1560 new_value: &'a mut dyn common::Delegate,
1561 ) -> FolderConstraintListCall<'a, C> {
1562 self._delegate = Some(new_value);
1563 self
1564 }
1565
1566 /// Set any additional parameter of the query string used in the request.
1567 /// It should be used to set parameters which are not yet available through their own
1568 /// setters.
1569 ///
1570 /// Please note that this method must not be used to set any of the known parameters
1571 /// which have their own setter method. If done anyway, the request will fail.
1572 ///
1573 /// # Additional Parameters
1574 ///
1575 /// * *$.xgafv* (query-string) - V1 error format.
1576 /// * *access_token* (query-string) - OAuth access token.
1577 /// * *alt* (query-string) - Data format for response.
1578 /// * *callback* (query-string) - JSONP
1579 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1580 /// * *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.
1581 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1582 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1583 /// * *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.
1584 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1585 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1586 pub fn param<T>(mut self, name: T, value: T) -> FolderConstraintListCall<'a, C>
1587 where
1588 T: AsRef<str>,
1589 {
1590 self._additional_params
1591 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1592 self
1593 }
1594
1595 /// Identifies the authorization scope for the method you are building.
1596 ///
1597 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1598 /// [`Scope::CloudPlatform`].
1599 ///
1600 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1601 /// tokens for more than one scope.
1602 ///
1603 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1604 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1605 /// sufficient, a read-write scope will do as well.
1606 pub fn add_scope<St>(mut self, scope: St) -> FolderConstraintListCall<'a, C>
1607 where
1608 St: AsRef<str>,
1609 {
1610 self._scopes.insert(String::from(scope.as_ref()));
1611 self
1612 }
1613 /// Identifies the authorization scope(s) for the method you are building.
1614 ///
1615 /// See [`Self::add_scope()`] for details.
1616 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderConstraintListCall<'a, C>
1617 where
1618 I: IntoIterator<Item = St>,
1619 St: AsRef<str>,
1620 {
1621 self._scopes
1622 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1623 self
1624 }
1625
1626 /// Removes all scopes, and no default scope will be used either.
1627 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1628 /// for details).
1629 pub fn clear_scopes(mut self) -> FolderConstraintListCall<'a, C> {
1630 self._scopes.clear();
1631 self
1632 }
1633}
1634
1635/// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
1636///
1637/// A builder for the *policies.create* method supported by a *folder* resource.
1638/// It is not used directly, but through a [`FolderMethods`] instance.
1639///
1640/// # Example
1641///
1642/// Instantiate a resource method builder
1643///
1644/// ```test_harness,no_run
1645/// # extern crate hyper;
1646/// # extern crate hyper_rustls;
1647/// # extern crate google_orgpolicy2 as orgpolicy2;
1648/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
1649/// # async fn dox() {
1650/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1651///
1652/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1653/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1654/// # .with_native_roots()
1655/// # .unwrap()
1656/// # .https_only()
1657/// # .enable_http2()
1658/// # .build();
1659///
1660/// # let executor = hyper_util::rt::TokioExecutor::new();
1661/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
1662/// # secret,
1663/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
1664/// # yup_oauth2::client::CustomHyperClientBuilder::from(
1665/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
1666/// # ),
1667/// # ).build().await.unwrap();
1668///
1669/// # let client = hyper_util::client::legacy::Client::builder(
1670/// # hyper_util::rt::TokioExecutor::new()
1671/// # )
1672/// # .build(
1673/// # hyper_rustls::HttpsConnectorBuilder::new()
1674/// # .with_native_roots()
1675/// # .unwrap()
1676/// # .https_or_http()
1677/// # .enable_http2()
1678/// # .build()
1679/// # );
1680/// # let mut hub = OrgPolicyAPI::new(client, auth);
1681/// // As the method needs a request, you would usually fill it with the desired information
1682/// // into the respective structure. Some of the parts shown here might not be applicable !
1683/// // Values shown here are possibly random and not representative !
1684/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
1685///
1686/// // You can configure optional parameters by calling the respective setters at will, and
1687/// // execute the final call using `doit()`.
1688/// // Values shown here are possibly random and not representative !
1689/// let result = hub.folders().policies_create(req, "parent")
1690/// .doit().await;
1691/// # }
1692/// ```
1693pub struct FolderPolicyCreateCall<'a, C>
1694where
1695 C: 'a,
1696{
1697 hub: &'a OrgPolicyAPI<C>,
1698 _request: GoogleCloudOrgpolicyV2Policy,
1699 _parent: String,
1700 _delegate: Option<&'a mut dyn common::Delegate>,
1701 _additional_params: HashMap<String, String>,
1702 _scopes: BTreeSet<String>,
1703}
1704
1705impl<'a, C> common::CallBuilder for FolderPolicyCreateCall<'a, C> {}
1706
1707impl<'a, C> FolderPolicyCreateCall<'a, C>
1708where
1709 C: common::Connector,
1710{
1711 /// Perform the operation you have build so far.
1712 pub async fn doit(
1713 mut self,
1714 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
1715 use std::borrow::Cow;
1716 use std::io::{Read, Seek};
1717
1718 use common::{url::Params, ToParts};
1719 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
1720
1721 let mut dd = common::DefaultDelegate;
1722 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
1723 dlg.begin(common::MethodInfo {
1724 id: "orgpolicy.folders.policies.create",
1725 http_method: hyper::Method::POST,
1726 });
1727
1728 for &field in ["alt", "parent"].iter() {
1729 if self._additional_params.contains_key(field) {
1730 dlg.finished(false);
1731 return Err(common::Error::FieldClash(field));
1732 }
1733 }
1734
1735 let mut params = Params::with_capacity(4 + self._additional_params.len());
1736 params.push("parent", self._parent);
1737
1738 params.extend(self._additional_params.iter());
1739
1740 params.push("alt", "json");
1741 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
1742 if self._scopes.is_empty() {
1743 self._scopes
1744 .insert(Scope::CloudPlatform.as_ref().to_string());
1745 }
1746
1747 #[allow(clippy::single_element_loop)]
1748 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
1749 url = params.uri_replacement(url, param_name, find_this, true);
1750 }
1751 {
1752 let to_remove = ["parent"];
1753 params.remove_params(&to_remove);
1754 }
1755
1756 let url = params.parse_with_url(&url);
1757
1758 let mut json_mime_type = mime::APPLICATION_JSON;
1759 let mut request_value_reader = {
1760 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
1761 common::remove_json_null_values(&mut value);
1762 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
1763 serde_json::to_writer(&mut dst, &value).unwrap();
1764 dst
1765 };
1766 let request_size = request_value_reader
1767 .seek(std::io::SeekFrom::End(0))
1768 .unwrap();
1769 request_value_reader
1770 .seek(std::io::SeekFrom::Start(0))
1771 .unwrap();
1772
1773 loop {
1774 let token = match self
1775 .hub
1776 .auth
1777 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
1778 .await
1779 {
1780 Ok(token) => token,
1781 Err(e) => match dlg.token(e) {
1782 Ok(token) => token,
1783 Err(e) => {
1784 dlg.finished(false);
1785 return Err(common::Error::MissingToken(e));
1786 }
1787 },
1788 };
1789 request_value_reader
1790 .seek(std::io::SeekFrom::Start(0))
1791 .unwrap();
1792 let mut req_result = {
1793 let client = &self.hub.client;
1794 dlg.pre_request();
1795 let mut req_builder = hyper::Request::builder()
1796 .method(hyper::Method::POST)
1797 .uri(url.as_str())
1798 .header(USER_AGENT, self.hub._user_agent.clone());
1799
1800 if let Some(token) = token.as_ref() {
1801 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
1802 }
1803
1804 let request = req_builder
1805 .header(CONTENT_TYPE, json_mime_type.to_string())
1806 .header(CONTENT_LENGTH, request_size as u64)
1807 .body(common::to_body(
1808 request_value_reader.get_ref().clone().into(),
1809 ));
1810
1811 client.request(request.unwrap()).await
1812 };
1813
1814 match req_result {
1815 Err(err) => {
1816 if let common::Retry::After(d) = dlg.http_error(&err) {
1817 sleep(d).await;
1818 continue;
1819 }
1820 dlg.finished(false);
1821 return Err(common::Error::HttpError(err));
1822 }
1823 Ok(res) => {
1824 let (mut parts, body) = res.into_parts();
1825 let mut body = common::Body::new(body);
1826 if !parts.status.is_success() {
1827 let bytes = common::to_bytes(body).await.unwrap_or_default();
1828 let error = serde_json::from_str(&common::to_string(&bytes));
1829 let response = common::to_response(parts, bytes.into());
1830
1831 if let common::Retry::After(d) =
1832 dlg.http_failure(&response, error.as_ref().ok())
1833 {
1834 sleep(d).await;
1835 continue;
1836 }
1837
1838 dlg.finished(false);
1839
1840 return Err(match error {
1841 Ok(value) => common::Error::BadRequest(value),
1842 _ => common::Error::Failure(response),
1843 });
1844 }
1845 let response = {
1846 let bytes = common::to_bytes(body).await.unwrap_or_default();
1847 let encoded = common::to_string(&bytes);
1848 match serde_json::from_str(&encoded) {
1849 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
1850 Err(error) => {
1851 dlg.response_json_decode_error(&encoded, &error);
1852 return Err(common::Error::JsonDecodeError(
1853 encoded.to_string(),
1854 error,
1855 ));
1856 }
1857 }
1858 };
1859
1860 dlg.finished(true);
1861 return Ok(response);
1862 }
1863 }
1864 }
1865 }
1866
1867 ///
1868 /// Sets the *request* property to the given value.
1869 ///
1870 /// Even though the property as already been set when instantiating this call,
1871 /// we provide this method for API completeness.
1872 pub fn request(
1873 mut self,
1874 new_value: GoogleCloudOrgpolicyV2Policy,
1875 ) -> FolderPolicyCreateCall<'a, C> {
1876 self._request = new_value;
1877 self
1878 }
1879 /// Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
1880 ///
1881 /// Sets the *parent* path property to the given value.
1882 ///
1883 /// Even though the property as already been set when instantiating this call,
1884 /// we provide this method for API completeness.
1885 pub fn parent(mut self, new_value: &str) -> FolderPolicyCreateCall<'a, C> {
1886 self._parent = new_value.to_string();
1887 self
1888 }
1889 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
1890 /// while executing the actual API request.
1891 ///
1892 /// ````text
1893 /// It should be used to handle progress information, and to implement a certain level of resilience.
1894 /// ````
1895 ///
1896 /// Sets the *delegate* property to the given value.
1897 pub fn delegate(
1898 mut self,
1899 new_value: &'a mut dyn common::Delegate,
1900 ) -> FolderPolicyCreateCall<'a, C> {
1901 self._delegate = Some(new_value);
1902 self
1903 }
1904
1905 /// Set any additional parameter of the query string used in the request.
1906 /// It should be used to set parameters which are not yet available through their own
1907 /// setters.
1908 ///
1909 /// Please note that this method must not be used to set any of the known parameters
1910 /// which have their own setter method. If done anyway, the request will fail.
1911 ///
1912 /// # Additional Parameters
1913 ///
1914 /// * *$.xgafv* (query-string) - V1 error format.
1915 /// * *access_token* (query-string) - OAuth access token.
1916 /// * *alt* (query-string) - Data format for response.
1917 /// * *callback* (query-string) - JSONP
1918 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
1919 /// * *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.
1920 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
1921 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
1922 /// * *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.
1923 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
1924 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
1925 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyCreateCall<'a, C>
1926 where
1927 T: AsRef<str>,
1928 {
1929 self._additional_params
1930 .insert(name.as_ref().to_string(), value.as_ref().to_string());
1931 self
1932 }
1933
1934 /// Identifies the authorization scope for the method you are building.
1935 ///
1936 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
1937 /// [`Scope::CloudPlatform`].
1938 ///
1939 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
1940 /// tokens for more than one scope.
1941 ///
1942 /// Usually there is more than one suitable scope to authorize an operation, some of which may
1943 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
1944 /// sufficient, a read-write scope will do as well.
1945 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyCreateCall<'a, C>
1946 where
1947 St: AsRef<str>,
1948 {
1949 self._scopes.insert(String::from(scope.as_ref()));
1950 self
1951 }
1952 /// Identifies the authorization scope(s) for the method you are building.
1953 ///
1954 /// See [`Self::add_scope()`] for details.
1955 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyCreateCall<'a, C>
1956 where
1957 I: IntoIterator<Item = St>,
1958 St: AsRef<str>,
1959 {
1960 self._scopes
1961 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
1962 self
1963 }
1964
1965 /// Removes all scopes, and no default scope will be used either.
1966 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
1967 /// for details).
1968 pub fn clear_scopes(mut self) -> FolderPolicyCreateCall<'a, C> {
1969 self._scopes.clear();
1970 self
1971 }
1972}
1973
1974/// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
1975///
1976/// A builder for the *policies.delete* method supported by a *folder* resource.
1977/// It is not used directly, but through a [`FolderMethods`] instance.
1978///
1979/// # Example
1980///
1981/// Instantiate a resource method builder
1982///
1983/// ```test_harness,no_run
1984/// # extern crate hyper;
1985/// # extern crate hyper_rustls;
1986/// # extern crate google_orgpolicy2 as orgpolicy2;
1987/// # async fn dox() {
1988/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
1989///
1990/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
1991/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
1992/// # .with_native_roots()
1993/// # .unwrap()
1994/// # .https_only()
1995/// # .enable_http2()
1996/// # .build();
1997///
1998/// # let executor = hyper_util::rt::TokioExecutor::new();
1999/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2000/// # secret,
2001/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2002/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2003/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2004/// # ),
2005/// # ).build().await.unwrap();
2006///
2007/// # let client = hyper_util::client::legacy::Client::builder(
2008/// # hyper_util::rt::TokioExecutor::new()
2009/// # )
2010/// # .build(
2011/// # hyper_rustls::HttpsConnectorBuilder::new()
2012/// # .with_native_roots()
2013/// # .unwrap()
2014/// # .https_or_http()
2015/// # .enable_http2()
2016/// # .build()
2017/// # );
2018/// # let mut hub = OrgPolicyAPI::new(client, auth);
2019/// // You can configure optional parameters by calling the respective setters at will, and
2020/// // execute the final call using `doit()`.
2021/// // Values shown here are possibly random and not representative !
2022/// let result = hub.folders().policies_delete("name")
2023/// .etag("amet.")
2024/// .doit().await;
2025/// # }
2026/// ```
2027pub struct FolderPolicyDeleteCall<'a, C>
2028where
2029 C: 'a,
2030{
2031 hub: &'a OrgPolicyAPI<C>,
2032 _name: String,
2033 _etag: Option<String>,
2034 _delegate: Option<&'a mut dyn common::Delegate>,
2035 _additional_params: HashMap<String, String>,
2036 _scopes: BTreeSet<String>,
2037}
2038
2039impl<'a, C> common::CallBuilder for FolderPolicyDeleteCall<'a, C> {}
2040
2041impl<'a, C> FolderPolicyDeleteCall<'a, C>
2042where
2043 C: common::Connector,
2044{
2045 /// Perform the operation you have build so far.
2046 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleProtobufEmpty)> {
2047 use std::borrow::Cow;
2048 use std::io::{Read, Seek};
2049
2050 use common::{url::Params, ToParts};
2051 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2052
2053 let mut dd = common::DefaultDelegate;
2054 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2055 dlg.begin(common::MethodInfo {
2056 id: "orgpolicy.folders.policies.delete",
2057 http_method: hyper::Method::DELETE,
2058 });
2059
2060 for &field in ["alt", "name", "etag"].iter() {
2061 if self._additional_params.contains_key(field) {
2062 dlg.finished(false);
2063 return Err(common::Error::FieldClash(field));
2064 }
2065 }
2066
2067 let mut params = Params::with_capacity(4 + self._additional_params.len());
2068 params.push("name", self._name);
2069 if let Some(value) = self._etag.as_ref() {
2070 params.push("etag", value);
2071 }
2072
2073 params.extend(self._additional_params.iter());
2074
2075 params.push("alt", "json");
2076 let mut url = self.hub._base_url.clone() + "v2/{+name}";
2077 if self._scopes.is_empty() {
2078 self._scopes
2079 .insert(Scope::CloudPlatform.as_ref().to_string());
2080 }
2081
2082 #[allow(clippy::single_element_loop)]
2083 for &(find_this, param_name) in [("{+name}", "name")].iter() {
2084 url = params.uri_replacement(url, param_name, find_this, true);
2085 }
2086 {
2087 let to_remove = ["name"];
2088 params.remove_params(&to_remove);
2089 }
2090
2091 let url = params.parse_with_url(&url);
2092
2093 loop {
2094 let token = match self
2095 .hub
2096 .auth
2097 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2098 .await
2099 {
2100 Ok(token) => token,
2101 Err(e) => match dlg.token(e) {
2102 Ok(token) => token,
2103 Err(e) => {
2104 dlg.finished(false);
2105 return Err(common::Error::MissingToken(e));
2106 }
2107 },
2108 };
2109 let mut req_result = {
2110 let client = &self.hub.client;
2111 dlg.pre_request();
2112 let mut req_builder = hyper::Request::builder()
2113 .method(hyper::Method::DELETE)
2114 .uri(url.as_str())
2115 .header(USER_AGENT, self.hub._user_agent.clone());
2116
2117 if let Some(token) = token.as_ref() {
2118 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2119 }
2120
2121 let request = req_builder
2122 .header(CONTENT_LENGTH, 0_u64)
2123 .body(common::to_body::<String>(None));
2124
2125 client.request(request.unwrap()).await
2126 };
2127
2128 match req_result {
2129 Err(err) => {
2130 if let common::Retry::After(d) = dlg.http_error(&err) {
2131 sleep(d).await;
2132 continue;
2133 }
2134 dlg.finished(false);
2135 return Err(common::Error::HttpError(err));
2136 }
2137 Ok(res) => {
2138 let (mut parts, body) = res.into_parts();
2139 let mut body = common::Body::new(body);
2140 if !parts.status.is_success() {
2141 let bytes = common::to_bytes(body).await.unwrap_or_default();
2142 let error = serde_json::from_str(&common::to_string(&bytes));
2143 let response = common::to_response(parts, bytes.into());
2144
2145 if let common::Retry::After(d) =
2146 dlg.http_failure(&response, error.as_ref().ok())
2147 {
2148 sleep(d).await;
2149 continue;
2150 }
2151
2152 dlg.finished(false);
2153
2154 return Err(match error {
2155 Ok(value) => common::Error::BadRequest(value),
2156 _ => common::Error::Failure(response),
2157 });
2158 }
2159 let response = {
2160 let bytes = common::to_bytes(body).await.unwrap_or_default();
2161 let encoded = common::to_string(&bytes);
2162 match serde_json::from_str(&encoded) {
2163 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2164 Err(error) => {
2165 dlg.response_json_decode_error(&encoded, &error);
2166 return Err(common::Error::JsonDecodeError(
2167 encoded.to_string(),
2168 error,
2169 ));
2170 }
2171 }
2172 };
2173
2174 dlg.finished(true);
2175 return Ok(response);
2176 }
2177 }
2178 }
2179 }
2180
2181 /// Required. Name of the policy to delete. See the policy entry for naming rules.
2182 ///
2183 /// Sets the *name* path property to the given value.
2184 ///
2185 /// Even though the property as already been set when instantiating this call,
2186 /// we provide this method for API completeness.
2187 pub fn name(mut self, new_value: &str) -> FolderPolicyDeleteCall<'a, C> {
2188 self._name = new_value.to_string();
2189 self
2190 }
2191 /// Optional. The current etag of policy. If an etag is provided and does not match the current etag of the policy, deletion will be blocked and an ABORTED error will be returned.
2192 ///
2193 /// Sets the *etag* query property to the given value.
2194 pub fn etag(mut self, new_value: &str) -> FolderPolicyDeleteCall<'a, C> {
2195 self._etag = Some(new_value.to_string());
2196 self
2197 }
2198 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2199 /// while executing the actual API request.
2200 ///
2201 /// ````text
2202 /// It should be used to handle progress information, and to implement a certain level of resilience.
2203 /// ````
2204 ///
2205 /// Sets the *delegate* property to the given value.
2206 pub fn delegate(
2207 mut self,
2208 new_value: &'a mut dyn common::Delegate,
2209 ) -> FolderPolicyDeleteCall<'a, C> {
2210 self._delegate = Some(new_value);
2211 self
2212 }
2213
2214 /// Set any additional parameter of the query string used in the request.
2215 /// It should be used to set parameters which are not yet available through their own
2216 /// setters.
2217 ///
2218 /// Please note that this method must not be used to set any of the known parameters
2219 /// which have their own setter method. If done anyway, the request will fail.
2220 ///
2221 /// # Additional Parameters
2222 ///
2223 /// * *$.xgafv* (query-string) - V1 error format.
2224 /// * *access_token* (query-string) - OAuth access token.
2225 /// * *alt* (query-string) - Data format for response.
2226 /// * *callback* (query-string) - JSONP
2227 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2228 /// * *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.
2229 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2230 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2231 /// * *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.
2232 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2233 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2234 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyDeleteCall<'a, C>
2235 where
2236 T: AsRef<str>,
2237 {
2238 self._additional_params
2239 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2240 self
2241 }
2242
2243 /// Identifies the authorization scope for the method you are building.
2244 ///
2245 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2246 /// [`Scope::CloudPlatform`].
2247 ///
2248 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2249 /// tokens for more than one scope.
2250 ///
2251 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2252 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2253 /// sufficient, a read-write scope will do as well.
2254 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyDeleteCall<'a, C>
2255 where
2256 St: AsRef<str>,
2257 {
2258 self._scopes.insert(String::from(scope.as_ref()));
2259 self
2260 }
2261 /// Identifies the authorization scope(s) for the method you are building.
2262 ///
2263 /// See [`Self::add_scope()`] for details.
2264 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyDeleteCall<'a, C>
2265 where
2266 I: IntoIterator<Item = St>,
2267 St: AsRef<str>,
2268 {
2269 self._scopes
2270 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2271 self
2272 }
2273
2274 /// Removes all scopes, and no default scope will be used either.
2275 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2276 /// for details).
2277 pub fn clear_scopes(mut self) -> FolderPolicyDeleteCall<'a, C> {
2278 self._scopes.clear();
2279 self
2280 }
2281}
2282
2283/// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
2284///
2285/// A builder for the *policies.get* method supported by a *folder* resource.
2286/// It is not used directly, but through a [`FolderMethods`] instance.
2287///
2288/// # Example
2289///
2290/// Instantiate a resource method builder
2291///
2292/// ```test_harness,no_run
2293/// # extern crate hyper;
2294/// # extern crate hyper_rustls;
2295/// # extern crate google_orgpolicy2 as orgpolicy2;
2296/// # async fn dox() {
2297/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2298///
2299/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2300/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2301/// # .with_native_roots()
2302/// # .unwrap()
2303/// # .https_only()
2304/// # .enable_http2()
2305/// # .build();
2306///
2307/// # let executor = hyper_util::rt::TokioExecutor::new();
2308/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2309/// # secret,
2310/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2311/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2312/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2313/// # ),
2314/// # ).build().await.unwrap();
2315///
2316/// # let client = hyper_util::client::legacy::Client::builder(
2317/// # hyper_util::rt::TokioExecutor::new()
2318/// # )
2319/// # .build(
2320/// # hyper_rustls::HttpsConnectorBuilder::new()
2321/// # .with_native_roots()
2322/// # .unwrap()
2323/// # .https_or_http()
2324/// # .enable_http2()
2325/// # .build()
2326/// # );
2327/// # let mut hub = OrgPolicyAPI::new(client, auth);
2328/// // You can configure optional parameters by calling the respective setters at will, and
2329/// // execute the final call using `doit()`.
2330/// // Values shown here are possibly random and not representative !
2331/// let result = hub.folders().policies_get("name")
2332/// .doit().await;
2333/// # }
2334/// ```
2335pub struct FolderPolicyGetCall<'a, C>
2336where
2337 C: 'a,
2338{
2339 hub: &'a OrgPolicyAPI<C>,
2340 _name: String,
2341 _delegate: Option<&'a mut dyn common::Delegate>,
2342 _additional_params: HashMap<String, String>,
2343 _scopes: BTreeSet<String>,
2344}
2345
2346impl<'a, C> common::CallBuilder for FolderPolicyGetCall<'a, C> {}
2347
2348impl<'a, C> FolderPolicyGetCall<'a, C>
2349where
2350 C: common::Connector,
2351{
2352 /// Perform the operation you have build so far.
2353 pub async fn doit(
2354 mut self,
2355 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
2356 use std::borrow::Cow;
2357 use std::io::{Read, Seek};
2358
2359 use common::{url::Params, ToParts};
2360 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2361
2362 let mut dd = common::DefaultDelegate;
2363 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2364 dlg.begin(common::MethodInfo {
2365 id: "orgpolicy.folders.policies.get",
2366 http_method: hyper::Method::GET,
2367 });
2368
2369 for &field in ["alt", "name"].iter() {
2370 if self._additional_params.contains_key(field) {
2371 dlg.finished(false);
2372 return Err(common::Error::FieldClash(field));
2373 }
2374 }
2375
2376 let mut params = Params::with_capacity(3 + self._additional_params.len());
2377 params.push("name", self._name);
2378
2379 params.extend(self._additional_params.iter());
2380
2381 params.push("alt", "json");
2382 let mut url = self.hub._base_url.clone() + "v2/{+name}";
2383 if self._scopes.is_empty() {
2384 self._scopes
2385 .insert(Scope::CloudPlatform.as_ref().to_string());
2386 }
2387
2388 #[allow(clippy::single_element_loop)]
2389 for &(find_this, param_name) in [("{+name}", "name")].iter() {
2390 url = params.uri_replacement(url, param_name, find_this, true);
2391 }
2392 {
2393 let to_remove = ["name"];
2394 params.remove_params(&to_remove);
2395 }
2396
2397 let url = params.parse_with_url(&url);
2398
2399 loop {
2400 let token = match self
2401 .hub
2402 .auth
2403 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2404 .await
2405 {
2406 Ok(token) => token,
2407 Err(e) => match dlg.token(e) {
2408 Ok(token) => token,
2409 Err(e) => {
2410 dlg.finished(false);
2411 return Err(common::Error::MissingToken(e));
2412 }
2413 },
2414 };
2415 let mut req_result = {
2416 let client = &self.hub.client;
2417 dlg.pre_request();
2418 let mut req_builder = hyper::Request::builder()
2419 .method(hyper::Method::GET)
2420 .uri(url.as_str())
2421 .header(USER_AGENT, self.hub._user_agent.clone());
2422
2423 if let Some(token) = token.as_ref() {
2424 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2425 }
2426
2427 let request = req_builder
2428 .header(CONTENT_LENGTH, 0_u64)
2429 .body(common::to_body::<String>(None));
2430
2431 client.request(request.unwrap()).await
2432 };
2433
2434 match req_result {
2435 Err(err) => {
2436 if let common::Retry::After(d) = dlg.http_error(&err) {
2437 sleep(d).await;
2438 continue;
2439 }
2440 dlg.finished(false);
2441 return Err(common::Error::HttpError(err));
2442 }
2443 Ok(res) => {
2444 let (mut parts, body) = res.into_parts();
2445 let mut body = common::Body::new(body);
2446 if !parts.status.is_success() {
2447 let bytes = common::to_bytes(body).await.unwrap_or_default();
2448 let error = serde_json::from_str(&common::to_string(&bytes));
2449 let response = common::to_response(parts, bytes.into());
2450
2451 if let common::Retry::After(d) =
2452 dlg.http_failure(&response, error.as_ref().ok())
2453 {
2454 sleep(d).await;
2455 continue;
2456 }
2457
2458 dlg.finished(false);
2459
2460 return Err(match error {
2461 Ok(value) => common::Error::BadRequest(value),
2462 _ => common::Error::Failure(response),
2463 });
2464 }
2465 let response = {
2466 let bytes = common::to_bytes(body).await.unwrap_or_default();
2467 let encoded = common::to_string(&bytes);
2468 match serde_json::from_str(&encoded) {
2469 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2470 Err(error) => {
2471 dlg.response_json_decode_error(&encoded, &error);
2472 return Err(common::Error::JsonDecodeError(
2473 encoded.to_string(),
2474 error,
2475 ));
2476 }
2477 }
2478 };
2479
2480 dlg.finished(true);
2481 return Ok(response);
2482 }
2483 }
2484 }
2485 }
2486
2487 /// Required. Resource name of the policy. See Policy for naming requirements.
2488 ///
2489 /// Sets the *name* path property to the given value.
2490 ///
2491 /// Even though the property as already been set when instantiating this call,
2492 /// we provide this method for API completeness.
2493 pub fn name(mut self, new_value: &str) -> FolderPolicyGetCall<'a, C> {
2494 self._name = new_value.to_string();
2495 self
2496 }
2497 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2498 /// while executing the actual API request.
2499 ///
2500 /// ````text
2501 /// It should be used to handle progress information, and to implement a certain level of resilience.
2502 /// ````
2503 ///
2504 /// Sets the *delegate* property to the given value.
2505 pub fn delegate(
2506 mut self,
2507 new_value: &'a mut dyn common::Delegate,
2508 ) -> FolderPolicyGetCall<'a, C> {
2509 self._delegate = Some(new_value);
2510 self
2511 }
2512
2513 /// Set any additional parameter of the query string used in the request.
2514 /// It should be used to set parameters which are not yet available through their own
2515 /// setters.
2516 ///
2517 /// Please note that this method must not be used to set any of the known parameters
2518 /// which have their own setter method. If done anyway, the request will fail.
2519 ///
2520 /// # Additional Parameters
2521 ///
2522 /// * *$.xgafv* (query-string) - V1 error format.
2523 /// * *access_token* (query-string) - OAuth access token.
2524 /// * *alt* (query-string) - Data format for response.
2525 /// * *callback* (query-string) - JSONP
2526 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2527 /// * *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.
2528 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2529 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2530 /// * *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.
2531 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2532 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2533 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyGetCall<'a, C>
2534 where
2535 T: AsRef<str>,
2536 {
2537 self._additional_params
2538 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2539 self
2540 }
2541
2542 /// Identifies the authorization scope for the method you are building.
2543 ///
2544 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2545 /// [`Scope::CloudPlatform`].
2546 ///
2547 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2548 /// tokens for more than one scope.
2549 ///
2550 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2551 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2552 /// sufficient, a read-write scope will do as well.
2553 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyGetCall<'a, C>
2554 where
2555 St: AsRef<str>,
2556 {
2557 self._scopes.insert(String::from(scope.as_ref()));
2558 self
2559 }
2560 /// Identifies the authorization scope(s) for the method you are building.
2561 ///
2562 /// See [`Self::add_scope()`] for details.
2563 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyGetCall<'a, C>
2564 where
2565 I: IntoIterator<Item = St>,
2566 St: AsRef<str>,
2567 {
2568 self._scopes
2569 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2570 self
2571 }
2572
2573 /// Removes all scopes, and no default scope will be used either.
2574 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2575 /// for details).
2576 pub fn clear_scopes(mut self) -> FolderPolicyGetCall<'a, C> {
2577 self._scopes.clear();
2578 self
2579 }
2580}
2581
2582/// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
2583///
2584/// A builder for the *policies.getEffectivePolicy* method supported by a *folder* resource.
2585/// It is not used directly, but through a [`FolderMethods`] instance.
2586///
2587/// # Example
2588///
2589/// Instantiate a resource method builder
2590///
2591/// ```test_harness,no_run
2592/// # extern crate hyper;
2593/// # extern crate hyper_rustls;
2594/// # extern crate google_orgpolicy2 as orgpolicy2;
2595/// # async fn dox() {
2596/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2597///
2598/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2599/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2600/// # .with_native_roots()
2601/// # .unwrap()
2602/// # .https_only()
2603/// # .enable_http2()
2604/// # .build();
2605///
2606/// # let executor = hyper_util::rt::TokioExecutor::new();
2607/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2608/// # secret,
2609/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2610/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2611/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2612/// # ),
2613/// # ).build().await.unwrap();
2614///
2615/// # let client = hyper_util::client::legacy::Client::builder(
2616/// # hyper_util::rt::TokioExecutor::new()
2617/// # )
2618/// # .build(
2619/// # hyper_rustls::HttpsConnectorBuilder::new()
2620/// # .with_native_roots()
2621/// # .unwrap()
2622/// # .https_or_http()
2623/// # .enable_http2()
2624/// # .build()
2625/// # );
2626/// # let mut hub = OrgPolicyAPI::new(client, auth);
2627/// // You can configure optional parameters by calling the respective setters at will, and
2628/// // execute the final call using `doit()`.
2629/// // Values shown here are possibly random and not representative !
2630/// let result = hub.folders().policies_get_effective_policy("name")
2631/// .doit().await;
2632/// # }
2633/// ```
2634pub struct FolderPolicyGetEffectivePolicyCall<'a, C>
2635where
2636 C: 'a,
2637{
2638 hub: &'a OrgPolicyAPI<C>,
2639 _name: String,
2640 _delegate: Option<&'a mut dyn common::Delegate>,
2641 _additional_params: HashMap<String, String>,
2642 _scopes: BTreeSet<String>,
2643}
2644
2645impl<'a, C> common::CallBuilder for FolderPolicyGetEffectivePolicyCall<'a, C> {}
2646
2647impl<'a, C> FolderPolicyGetEffectivePolicyCall<'a, C>
2648where
2649 C: common::Connector,
2650{
2651 /// Perform the operation you have build so far.
2652 pub async fn doit(
2653 mut self,
2654 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
2655 use std::borrow::Cow;
2656 use std::io::{Read, Seek};
2657
2658 use common::{url::Params, ToParts};
2659 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2660
2661 let mut dd = common::DefaultDelegate;
2662 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2663 dlg.begin(common::MethodInfo {
2664 id: "orgpolicy.folders.policies.getEffectivePolicy",
2665 http_method: hyper::Method::GET,
2666 });
2667
2668 for &field in ["alt", "name"].iter() {
2669 if self._additional_params.contains_key(field) {
2670 dlg.finished(false);
2671 return Err(common::Error::FieldClash(field));
2672 }
2673 }
2674
2675 let mut params = Params::with_capacity(3 + self._additional_params.len());
2676 params.push("name", self._name);
2677
2678 params.extend(self._additional_params.iter());
2679
2680 params.push("alt", "json");
2681 let mut url = self.hub._base_url.clone() + "v2/{+name}:getEffectivePolicy";
2682 if self._scopes.is_empty() {
2683 self._scopes
2684 .insert(Scope::CloudPlatform.as_ref().to_string());
2685 }
2686
2687 #[allow(clippy::single_element_loop)]
2688 for &(find_this, param_name) in [("{+name}", "name")].iter() {
2689 url = params.uri_replacement(url, param_name, find_this, true);
2690 }
2691 {
2692 let to_remove = ["name"];
2693 params.remove_params(&to_remove);
2694 }
2695
2696 let url = params.parse_with_url(&url);
2697
2698 loop {
2699 let token = match self
2700 .hub
2701 .auth
2702 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
2703 .await
2704 {
2705 Ok(token) => token,
2706 Err(e) => match dlg.token(e) {
2707 Ok(token) => token,
2708 Err(e) => {
2709 dlg.finished(false);
2710 return Err(common::Error::MissingToken(e));
2711 }
2712 },
2713 };
2714 let mut req_result = {
2715 let client = &self.hub.client;
2716 dlg.pre_request();
2717 let mut req_builder = hyper::Request::builder()
2718 .method(hyper::Method::GET)
2719 .uri(url.as_str())
2720 .header(USER_AGENT, self.hub._user_agent.clone());
2721
2722 if let Some(token) = token.as_ref() {
2723 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
2724 }
2725
2726 let request = req_builder
2727 .header(CONTENT_LENGTH, 0_u64)
2728 .body(common::to_body::<String>(None));
2729
2730 client.request(request.unwrap()).await
2731 };
2732
2733 match req_result {
2734 Err(err) => {
2735 if let common::Retry::After(d) = dlg.http_error(&err) {
2736 sleep(d).await;
2737 continue;
2738 }
2739 dlg.finished(false);
2740 return Err(common::Error::HttpError(err));
2741 }
2742 Ok(res) => {
2743 let (mut parts, body) = res.into_parts();
2744 let mut body = common::Body::new(body);
2745 if !parts.status.is_success() {
2746 let bytes = common::to_bytes(body).await.unwrap_or_default();
2747 let error = serde_json::from_str(&common::to_string(&bytes));
2748 let response = common::to_response(parts, bytes.into());
2749
2750 if let common::Retry::After(d) =
2751 dlg.http_failure(&response, error.as_ref().ok())
2752 {
2753 sleep(d).await;
2754 continue;
2755 }
2756
2757 dlg.finished(false);
2758
2759 return Err(match error {
2760 Ok(value) => common::Error::BadRequest(value),
2761 _ => common::Error::Failure(response),
2762 });
2763 }
2764 let response = {
2765 let bytes = common::to_bytes(body).await.unwrap_or_default();
2766 let encoded = common::to_string(&bytes);
2767 match serde_json::from_str(&encoded) {
2768 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
2769 Err(error) => {
2770 dlg.response_json_decode_error(&encoded, &error);
2771 return Err(common::Error::JsonDecodeError(
2772 encoded.to_string(),
2773 error,
2774 ));
2775 }
2776 }
2777 };
2778
2779 dlg.finished(true);
2780 return Ok(response);
2781 }
2782 }
2783 }
2784 }
2785
2786 /// Required. The effective policy to compute. See Policy for naming requirements.
2787 ///
2788 /// Sets the *name* path property to the given value.
2789 ///
2790 /// Even though the property as already been set when instantiating this call,
2791 /// we provide this method for API completeness.
2792 pub fn name(mut self, new_value: &str) -> FolderPolicyGetEffectivePolicyCall<'a, C> {
2793 self._name = new_value.to_string();
2794 self
2795 }
2796 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
2797 /// while executing the actual API request.
2798 ///
2799 /// ````text
2800 /// It should be used to handle progress information, and to implement a certain level of resilience.
2801 /// ````
2802 ///
2803 /// Sets the *delegate* property to the given value.
2804 pub fn delegate(
2805 mut self,
2806 new_value: &'a mut dyn common::Delegate,
2807 ) -> FolderPolicyGetEffectivePolicyCall<'a, C> {
2808 self._delegate = Some(new_value);
2809 self
2810 }
2811
2812 /// Set any additional parameter of the query string used in the request.
2813 /// It should be used to set parameters which are not yet available through their own
2814 /// setters.
2815 ///
2816 /// Please note that this method must not be used to set any of the known parameters
2817 /// which have their own setter method. If done anyway, the request will fail.
2818 ///
2819 /// # Additional Parameters
2820 ///
2821 /// * *$.xgafv* (query-string) - V1 error format.
2822 /// * *access_token* (query-string) - OAuth access token.
2823 /// * *alt* (query-string) - Data format for response.
2824 /// * *callback* (query-string) - JSONP
2825 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
2826 /// * *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.
2827 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
2828 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
2829 /// * *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.
2830 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
2831 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
2832 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyGetEffectivePolicyCall<'a, C>
2833 where
2834 T: AsRef<str>,
2835 {
2836 self._additional_params
2837 .insert(name.as_ref().to_string(), value.as_ref().to_string());
2838 self
2839 }
2840
2841 /// Identifies the authorization scope for the method you are building.
2842 ///
2843 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
2844 /// [`Scope::CloudPlatform`].
2845 ///
2846 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
2847 /// tokens for more than one scope.
2848 ///
2849 /// Usually there is more than one suitable scope to authorize an operation, some of which may
2850 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
2851 /// sufficient, a read-write scope will do as well.
2852 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyGetEffectivePolicyCall<'a, C>
2853 where
2854 St: AsRef<str>,
2855 {
2856 self._scopes.insert(String::from(scope.as_ref()));
2857 self
2858 }
2859 /// Identifies the authorization scope(s) for the method you are building.
2860 ///
2861 /// See [`Self::add_scope()`] for details.
2862 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyGetEffectivePolicyCall<'a, C>
2863 where
2864 I: IntoIterator<Item = St>,
2865 St: AsRef<str>,
2866 {
2867 self._scopes
2868 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
2869 self
2870 }
2871
2872 /// Removes all scopes, and no default scope will be used either.
2873 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
2874 /// for details).
2875 pub fn clear_scopes(mut self) -> FolderPolicyGetEffectivePolicyCall<'a, C> {
2876 self._scopes.clear();
2877 self
2878 }
2879}
2880
2881/// Retrieves all of the policies that exist on a particular resource.
2882///
2883/// A builder for the *policies.list* method supported by a *folder* resource.
2884/// It is not used directly, but through a [`FolderMethods`] instance.
2885///
2886/// # Example
2887///
2888/// Instantiate a resource method builder
2889///
2890/// ```test_harness,no_run
2891/// # extern crate hyper;
2892/// # extern crate hyper_rustls;
2893/// # extern crate google_orgpolicy2 as orgpolicy2;
2894/// # async fn dox() {
2895/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
2896///
2897/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
2898/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
2899/// # .with_native_roots()
2900/// # .unwrap()
2901/// # .https_only()
2902/// # .enable_http2()
2903/// # .build();
2904///
2905/// # let executor = hyper_util::rt::TokioExecutor::new();
2906/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
2907/// # secret,
2908/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
2909/// # yup_oauth2::client::CustomHyperClientBuilder::from(
2910/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
2911/// # ),
2912/// # ).build().await.unwrap();
2913///
2914/// # let client = hyper_util::client::legacy::Client::builder(
2915/// # hyper_util::rt::TokioExecutor::new()
2916/// # )
2917/// # .build(
2918/// # hyper_rustls::HttpsConnectorBuilder::new()
2919/// # .with_native_roots()
2920/// # .unwrap()
2921/// # .https_or_http()
2922/// # .enable_http2()
2923/// # .build()
2924/// # );
2925/// # let mut hub = OrgPolicyAPI::new(client, auth);
2926/// // You can configure optional parameters by calling the respective setters at will, and
2927/// // execute the final call using `doit()`.
2928/// // Values shown here are possibly random and not representative !
2929/// let result = hub.folders().policies_list("parent")
2930/// .page_token("ipsum")
2931/// .page_size(-62)
2932/// .doit().await;
2933/// # }
2934/// ```
2935pub struct FolderPolicyListCall<'a, C>
2936where
2937 C: 'a,
2938{
2939 hub: &'a OrgPolicyAPI<C>,
2940 _parent: String,
2941 _page_token: Option<String>,
2942 _page_size: Option<i32>,
2943 _delegate: Option<&'a mut dyn common::Delegate>,
2944 _additional_params: HashMap<String, String>,
2945 _scopes: BTreeSet<String>,
2946}
2947
2948impl<'a, C> common::CallBuilder for FolderPolicyListCall<'a, C> {}
2949
2950impl<'a, C> FolderPolicyListCall<'a, C>
2951where
2952 C: common::Connector,
2953{
2954 /// Perform the operation you have build so far.
2955 pub async fn doit(
2956 mut self,
2957 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2ListPoliciesResponse)> {
2958 use std::borrow::Cow;
2959 use std::io::{Read, Seek};
2960
2961 use common::{url::Params, ToParts};
2962 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
2963
2964 let mut dd = common::DefaultDelegate;
2965 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
2966 dlg.begin(common::MethodInfo {
2967 id: "orgpolicy.folders.policies.list",
2968 http_method: hyper::Method::GET,
2969 });
2970
2971 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
2972 if self._additional_params.contains_key(field) {
2973 dlg.finished(false);
2974 return Err(common::Error::FieldClash(field));
2975 }
2976 }
2977
2978 let mut params = Params::with_capacity(5 + self._additional_params.len());
2979 params.push("parent", self._parent);
2980 if let Some(value) = self._page_token.as_ref() {
2981 params.push("pageToken", value);
2982 }
2983 if let Some(value) = self._page_size.as_ref() {
2984 params.push("pageSize", value.to_string());
2985 }
2986
2987 params.extend(self._additional_params.iter());
2988
2989 params.push("alt", "json");
2990 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
2991 if self._scopes.is_empty() {
2992 self._scopes
2993 .insert(Scope::CloudPlatform.as_ref().to_string());
2994 }
2995
2996 #[allow(clippy::single_element_loop)]
2997 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
2998 url = params.uri_replacement(url, param_name, find_this, true);
2999 }
3000 {
3001 let to_remove = ["parent"];
3002 params.remove_params(&to_remove);
3003 }
3004
3005 let url = params.parse_with_url(&url);
3006
3007 loop {
3008 let token = match self
3009 .hub
3010 .auth
3011 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3012 .await
3013 {
3014 Ok(token) => token,
3015 Err(e) => match dlg.token(e) {
3016 Ok(token) => token,
3017 Err(e) => {
3018 dlg.finished(false);
3019 return Err(common::Error::MissingToken(e));
3020 }
3021 },
3022 };
3023 let mut req_result = {
3024 let client = &self.hub.client;
3025 dlg.pre_request();
3026 let mut req_builder = hyper::Request::builder()
3027 .method(hyper::Method::GET)
3028 .uri(url.as_str())
3029 .header(USER_AGENT, self.hub._user_agent.clone());
3030
3031 if let Some(token) = token.as_ref() {
3032 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3033 }
3034
3035 let request = req_builder
3036 .header(CONTENT_LENGTH, 0_u64)
3037 .body(common::to_body::<String>(None));
3038
3039 client.request(request.unwrap()).await
3040 };
3041
3042 match req_result {
3043 Err(err) => {
3044 if let common::Retry::After(d) = dlg.http_error(&err) {
3045 sleep(d).await;
3046 continue;
3047 }
3048 dlg.finished(false);
3049 return Err(common::Error::HttpError(err));
3050 }
3051 Ok(res) => {
3052 let (mut parts, body) = res.into_parts();
3053 let mut body = common::Body::new(body);
3054 if !parts.status.is_success() {
3055 let bytes = common::to_bytes(body).await.unwrap_or_default();
3056 let error = serde_json::from_str(&common::to_string(&bytes));
3057 let response = common::to_response(parts, bytes.into());
3058
3059 if let common::Retry::After(d) =
3060 dlg.http_failure(&response, error.as_ref().ok())
3061 {
3062 sleep(d).await;
3063 continue;
3064 }
3065
3066 dlg.finished(false);
3067
3068 return Err(match error {
3069 Ok(value) => common::Error::BadRequest(value),
3070 _ => common::Error::Failure(response),
3071 });
3072 }
3073 let response = {
3074 let bytes = common::to_bytes(body).await.unwrap_or_default();
3075 let encoded = common::to_string(&bytes);
3076 match serde_json::from_str(&encoded) {
3077 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3078 Err(error) => {
3079 dlg.response_json_decode_error(&encoded, &error);
3080 return Err(common::Error::JsonDecodeError(
3081 encoded.to_string(),
3082 error,
3083 ));
3084 }
3085 }
3086 };
3087
3088 dlg.finished(true);
3089 return Ok(response);
3090 }
3091 }
3092 }
3093 }
3094
3095 /// Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
3096 ///
3097 /// Sets the *parent* path property to the given value.
3098 ///
3099 /// Even though the property as already been set when instantiating this call,
3100 /// we provide this method for API completeness.
3101 pub fn parent(mut self, new_value: &str) -> FolderPolicyListCall<'a, C> {
3102 self._parent = new_value.to_string();
3103 self
3104 }
3105 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
3106 ///
3107 /// Sets the *page token* query property to the given value.
3108 pub fn page_token(mut self, new_value: &str) -> FolderPolicyListCall<'a, C> {
3109 self._page_token = Some(new_value.to_string());
3110 self
3111 }
3112 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
3113 ///
3114 /// Sets the *page size* query property to the given value.
3115 pub fn page_size(mut self, new_value: i32) -> FolderPolicyListCall<'a, C> {
3116 self._page_size = Some(new_value);
3117 self
3118 }
3119 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3120 /// while executing the actual API request.
3121 ///
3122 /// ````text
3123 /// It should be used to handle progress information, and to implement a certain level of resilience.
3124 /// ````
3125 ///
3126 /// Sets the *delegate* property to the given value.
3127 pub fn delegate(
3128 mut self,
3129 new_value: &'a mut dyn common::Delegate,
3130 ) -> FolderPolicyListCall<'a, C> {
3131 self._delegate = Some(new_value);
3132 self
3133 }
3134
3135 /// Set any additional parameter of the query string used in the request.
3136 /// It should be used to set parameters which are not yet available through their own
3137 /// setters.
3138 ///
3139 /// Please note that this method must not be used to set any of the known parameters
3140 /// which have their own setter method. If done anyway, the request will fail.
3141 ///
3142 /// # Additional Parameters
3143 ///
3144 /// * *$.xgafv* (query-string) - V1 error format.
3145 /// * *access_token* (query-string) - OAuth access token.
3146 /// * *alt* (query-string) - Data format for response.
3147 /// * *callback* (query-string) - JSONP
3148 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3149 /// * *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.
3150 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3151 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3152 /// * *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.
3153 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
3154 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
3155 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyListCall<'a, C>
3156 where
3157 T: AsRef<str>,
3158 {
3159 self._additional_params
3160 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3161 self
3162 }
3163
3164 /// Identifies the authorization scope for the method you are building.
3165 ///
3166 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3167 /// [`Scope::CloudPlatform`].
3168 ///
3169 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3170 /// tokens for more than one scope.
3171 ///
3172 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3173 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3174 /// sufficient, a read-write scope will do as well.
3175 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyListCall<'a, C>
3176 where
3177 St: AsRef<str>,
3178 {
3179 self._scopes.insert(String::from(scope.as_ref()));
3180 self
3181 }
3182 /// Identifies the authorization scope(s) for the method you are building.
3183 ///
3184 /// See [`Self::add_scope()`] for details.
3185 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyListCall<'a, C>
3186 where
3187 I: IntoIterator<Item = St>,
3188 St: AsRef<str>,
3189 {
3190 self._scopes
3191 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3192 self
3193 }
3194
3195 /// Removes all scopes, and no default scope will be used either.
3196 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3197 /// for details).
3198 pub fn clear_scopes(mut self) -> FolderPolicyListCall<'a, C> {
3199 self._scopes.clear();
3200 self
3201 }
3202}
3203
3204/// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
3205///
3206/// A builder for the *policies.patch* method supported by a *folder* resource.
3207/// It is not used directly, but through a [`FolderMethods`] instance.
3208///
3209/// # Example
3210///
3211/// Instantiate a resource method builder
3212///
3213/// ```test_harness,no_run
3214/// # extern crate hyper;
3215/// # extern crate hyper_rustls;
3216/// # extern crate google_orgpolicy2 as orgpolicy2;
3217/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
3218/// # async fn dox() {
3219/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3220///
3221/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3222/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3223/// # .with_native_roots()
3224/// # .unwrap()
3225/// # .https_only()
3226/// # .enable_http2()
3227/// # .build();
3228///
3229/// # let executor = hyper_util::rt::TokioExecutor::new();
3230/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3231/// # secret,
3232/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3233/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3234/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3235/// # ),
3236/// # ).build().await.unwrap();
3237///
3238/// # let client = hyper_util::client::legacy::Client::builder(
3239/// # hyper_util::rt::TokioExecutor::new()
3240/// # )
3241/// # .build(
3242/// # hyper_rustls::HttpsConnectorBuilder::new()
3243/// # .with_native_roots()
3244/// # .unwrap()
3245/// # .https_or_http()
3246/// # .enable_http2()
3247/// # .build()
3248/// # );
3249/// # let mut hub = OrgPolicyAPI::new(client, auth);
3250/// // As the method needs a request, you would usually fill it with the desired information
3251/// // into the respective structure. Some of the parts shown here might not be applicable !
3252/// // Values shown here are possibly random and not representative !
3253/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
3254///
3255/// // You can configure optional parameters by calling the respective setters at will, and
3256/// // execute the final call using `doit()`.
3257/// // Values shown here are possibly random and not representative !
3258/// let result = hub.folders().policies_patch(req, "name")
3259/// .update_mask(FieldMask::new::<&str>(&[]))
3260/// .doit().await;
3261/// # }
3262/// ```
3263pub struct FolderPolicyPatchCall<'a, C>
3264where
3265 C: 'a,
3266{
3267 hub: &'a OrgPolicyAPI<C>,
3268 _request: GoogleCloudOrgpolicyV2Policy,
3269 _name: String,
3270 _update_mask: Option<common::FieldMask>,
3271 _delegate: Option<&'a mut dyn common::Delegate>,
3272 _additional_params: HashMap<String, String>,
3273 _scopes: BTreeSet<String>,
3274}
3275
3276impl<'a, C> common::CallBuilder for FolderPolicyPatchCall<'a, C> {}
3277
3278impl<'a, C> FolderPolicyPatchCall<'a, C>
3279where
3280 C: common::Connector,
3281{
3282 /// Perform the operation you have build so far.
3283 pub async fn doit(
3284 mut self,
3285 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
3286 use std::borrow::Cow;
3287 use std::io::{Read, Seek};
3288
3289 use common::{url::Params, ToParts};
3290 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3291
3292 let mut dd = common::DefaultDelegate;
3293 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3294 dlg.begin(common::MethodInfo {
3295 id: "orgpolicy.folders.policies.patch",
3296 http_method: hyper::Method::PATCH,
3297 });
3298
3299 for &field in ["alt", "name", "updateMask"].iter() {
3300 if self._additional_params.contains_key(field) {
3301 dlg.finished(false);
3302 return Err(common::Error::FieldClash(field));
3303 }
3304 }
3305
3306 let mut params = Params::with_capacity(5 + self._additional_params.len());
3307 params.push("name", self._name);
3308 if let Some(value) = self._update_mask.as_ref() {
3309 params.push("updateMask", value.to_string());
3310 }
3311
3312 params.extend(self._additional_params.iter());
3313
3314 params.push("alt", "json");
3315 let mut url = self.hub._base_url.clone() + "v2/{+name}";
3316 if self._scopes.is_empty() {
3317 self._scopes
3318 .insert(Scope::CloudPlatform.as_ref().to_string());
3319 }
3320
3321 #[allow(clippy::single_element_loop)]
3322 for &(find_this, param_name) in [("{+name}", "name")].iter() {
3323 url = params.uri_replacement(url, param_name, find_this, true);
3324 }
3325 {
3326 let to_remove = ["name"];
3327 params.remove_params(&to_remove);
3328 }
3329
3330 let url = params.parse_with_url(&url);
3331
3332 let mut json_mime_type = mime::APPLICATION_JSON;
3333 let mut request_value_reader = {
3334 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
3335 common::remove_json_null_values(&mut value);
3336 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
3337 serde_json::to_writer(&mut dst, &value).unwrap();
3338 dst
3339 };
3340 let request_size = request_value_reader
3341 .seek(std::io::SeekFrom::End(0))
3342 .unwrap();
3343 request_value_reader
3344 .seek(std::io::SeekFrom::Start(0))
3345 .unwrap();
3346
3347 loop {
3348 let token = match self
3349 .hub
3350 .auth
3351 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3352 .await
3353 {
3354 Ok(token) => token,
3355 Err(e) => match dlg.token(e) {
3356 Ok(token) => token,
3357 Err(e) => {
3358 dlg.finished(false);
3359 return Err(common::Error::MissingToken(e));
3360 }
3361 },
3362 };
3363 request_value_reader
3364 .seek(std::io::SeekFrom::Start(0))
3365 .unwrap();
3366 let mut req_result = {
3367 let client = &self.hub.client;
3368 dlg.pre_request();
3369 let mut req_builder = hyper::Request::builder()
3370 .method(hyper::Method::PATCH)
3371 .uri(url.as_str())
3372 .header(USER_AGENT, self.hub._user_agent.clone());
3373
3374 if let Some(token) = token.as_ref() {
3375 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3376 }
3377
3378 let request = req_builder
3379 .header(CONTENT_TYPE, json_mime_type.to_string())
3380 .header(CONTENT_LENGTH, request_size as u64)
3381 .body(common::to_body(
3382 request_value_reader.get_ref().clone().into(),
3383 ));
3384
3385 client.request(request.unwrap()).await
3386 };
3387
3388 match req_result {
3389 Err(err) => {
3390 if let common::Retry::After(d) = dlg.http_error(&err) {
3391 sleep(d).await;
3392 continue;
3393 }
3394 dlg.finished(false);
3395 return Err(common::Error::HttpError(err));
3396 }
3397 Ok(res) => {
3398 let (mut parts, body) = res.into_parts();
3399 let mut body = common::Body::new(body);
3400 if !parts.status.is_success() {
3401 let bytes = common::to_bytes(body).await.unwrap_or_default();
3402 let error = serde_json::from_str(&common::to_string(&bytes));
3403 let response = common::to_response(parts, bytes.into());
3404
3405 if let common::Retry::After(d) =
3406 dlg.http_failure(&response, error.as_ref().ok())
3407 {
3408 sleep(d).await;
3409 continue;
3410 }
3411
3412 dlg.finished(false);
3413
3414 return Err(match error {
3415 Ok(value) => common::Error::BadRequest(value),
3416 _ => common::Error::Failure(response),
3417 });
3418 }
3419 let response = {
3420 let bytes = common::to_bytes(body).await.unwrap_or_default();
3421 let encoded = common::to_string(&bytes);
3422 match serde_json::from_str(&encoded) {
3423 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3424 Err(error) => {
3425 dlg.response_json_decode_error(&encoded, &error);
3426 return Err(common::Error::JsonDecodeError(
3427 encoded.to_string(),
3428 error,
3429 ));
3430 }
3431 }
3432 };
3433
3434 dlg.finished(true);
3435 return Ok(response);
3436 }
3437 }
3438 }
3439 }
3440
3441 ///
3442 /// Sets the *request* property to the given value.
3443 ///
3444 /// Even though the property as already been set when instantiating this call,
3445 /// we provide this method for API completeness.
3446 pub fn request(
3447 mut self,
3448 new_value: GoogleCloudOrgpolicyV2Policy,
3449 ) -> FolderPolicyPatchCall<'a, C> {
3450 self._request = new_value;
3451 self
3452 }
3453 /// Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
3454 ///
3455 /// Sets the *name* path property to the given value.
3456 ///
3457 /// Even though the property as already been set when instantiating this call,
3458 /// we provide this method for API completeness.
3459 pub fn name(mut self, new_value: &str) -> FolderPolicyPatchCall<'a, C> {
3460 self._name = new_value.to_string();
3461 self
3462 }
3463 /// Field mask used to specify the fields to be overwritten in the policy by the set. The fields specified in the update_mask are relative to the policy, not the full request.
3464 ///
3465 /// Sets the *update mask* query property to the given value.
3466 pub fn update_mask(mut self, new_value: common::FieldMask) -> FolderPolicyPatchCall<'a, C> {
3467 self._update_mask = Some(new_value);
3468 self
3469 }
3470 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3471 /// while executing the actual API request.
3472 ///
3473 /// ````text
3474 /// It should be used to handle progress information, and to implement a certain level of resilience.
3475 /// ````
3476 ///
3477 /// Sets the *delegate* property to the given value.
3478 pub fn delegate(
3479 mut self,
3480 new_value: &'a mut dyn common::Delegate,
3481 ) -> FolderPolicyPatchCall<'a, C> {
3482 self._delegate = Some(new_value);
3483 self
3484 }
3485
3486 /// Set any additional parameter of the query string used in the request.
3487 /// It should be used to set parameters which are not yet available through their own
3488 /// setters.
3489 ///
3490 /// Please note that this method must not be used to set any of the known parameters
3491 /// which have their own setter method. If done anyway, the request will fail.
3492 ///
3493 /// # Additional Parameters
3494 ///
3495 /// * *$.xgafv* (query-string) - V1 error format.
3496 /// * *access_token* (query-string) - OAuth access token.
3497 /// * *alt* (query-string) - Data format for response.
3498 /// * *callback* (query-string) - JSONP
3499 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3500 /// * *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.
3501 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3502 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3503 /// * *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.
3504 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
3505 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
3506 pub fn param<T>(mut self, name: T, value: T) -> FolderPolicyPatchCall<'a, C>
3507 where
3508 T: AsRef<str>,
3509 {
3510 self._additional_params
3511 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3512 self
3513 }
3514
3515 /// Identifies the authorization scope for the method you are building.
3516 ///
3517 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3518 /// [`Scope::CloudPlatform`].
3519 ///
3520 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3521 /// tokens for more than one scope.
3522 ///
3523 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3524 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3525 /// sufficient, a read-write scope will do as well.
3526 pub fn add_scope<St>(mut self, scope: St) -> FolderPolicyPatchCall<'a, C>
3527 where
3528 St: AsRef<str>,
3529 {
3530 self._scopes.insert(String::from(scope.as_ref()));
3531 self
3532 }
3533 /// Identifies the authorization scope(s) for the method you are building.
3534 ///
3535 /// See [`Self::add_scope()`] for details.
3536 pub fn add_scopes<I, St>(mut self, scopes: I) -> FolderPolicyPatchCall<'a, C>
3537 where
3538 I: IntoIterator<Item = St>,
3539 St: AsRef<str>,
3540 {
3541 self._scopes
3542 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3543 self
3544 }
3545
3546 /// Removes all scopes, and no default scope will be used either.
3547 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3548 /// for details).
3549 pub fn clear_scopes(mut self) -> FolderPolicyPatchCall<'a, C> {
3550 self._scopes.clear();
3551 self
3552 }
3553}
3554
3555/// Lists constraints that could be applied on the specified resource.
3556///
3557/// A builder for the *constraints.list* method supported by a *organization* resource.
3558/// It is not used directly, but through a [`OrganizationMethods`] instance.
3559///
3560/// # Example
3561///
3562/// Instantiate a resource method builder
3563///
3564/// ```test_harness,no_run
3565/// # extern crate hyper;
3566/// # extern crate hyper_rustls;
3567/// # extern crate google_orgpolicy2 as orgpolicy2;
3568/// # async fn dox() {
3569/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3570///
3571/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3572/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3573/// # .with_native_roots()
3574/// # .unwrap()
3575/// # .https_only()
3576/// # .enable_http2()
3577/// # .build();
3578///
3579/// # let executor = hyper_util::rt::TokioExecutor::new();
3580/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3581/// # secret,
3582/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3583/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3584/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3585/// # ),
3586/// # ).build().await.unwrap();
3587///
3588/// # let client = hyper_util::client::legacy::Client::builder(
3589/// # hyper_util::rt::TokioExecutor::new()
3590/// # )
3591/// # .build(
3592/// # hyper_rustls::HttpsConnectorBuilder::new()
3593/// # .with_native_roots()
3594/// # .unwrap()
3595/// # .https_or_http()
3596/// # .enable_http2()
3597/// # .build()
3598/// # );
3599/// # let mut hub = OrgPolicyAPI::new(client, auth);
3600/// // You can configure optional parameters by calling the respective setters at will, and
3601/// // execute the final call using `doit()`.
3602/// // Values shown here are possibly random and not representative !
3603/// let result = hub.organizations().constraints_list("parent")
3604/// .page_token("eos")
3605/// .page_size(-4)
3606/// .doit().await;
3607/// # }
3608/// ```
3609pub struct OrganizationConstraintListCall<'a, C>
3610where
3611 C: 'a,
3612{
3613 hub: &'a OrgPolicyAPI<C>,
3614 _parent: String,
3615 _page_token: Option<String>,
3616 _page_size: Option<i32>,
3617 _delegate: Option<&'a mut dyn common::Delegate>,
3618 _additional_params: HashMap<String, String>,
3619 _scopes: BTreeSet<String>,
3620}
3621
3622impl<'a, C> common::CallBuilder for OrganizationConstraintListCall<'a, C> {}
3623
3624impl<'a, C> OrganizationConstraintListCall<'a, C>
3625where
3626 C: common::Connector,
3627{
3628 /// Perform the operation you have build so far.
3629 pub async fn doit(
3630 mut self,
3631 ) -> common::Result<(
3632 common::Response,
3633 GoogleCloudOrgpolicyV2ListConstraintsResponse,
3634 )> {
3635 use std::borrow::Cow;
3636 use std::io::{Read, Seek};
3637
3638 use common::{url::Params, ToParts};
3639 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3640
3641 let mut dd = common::DefaultDelegate;
3642 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3643 dlg.begin(common::MethodInfo {
3644 id: "orgpolicy.organizations.constraints.list",
3645 http_method: hyper::Method::GET,
3646 });
3647
3648 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
3649 if self._additional_params.contains_key(field) {
3650 dlg.finished(false);
3651 return Err(common::Error::FieldClash(field));
3652 }
3653 }
3654
3655 let mut params = Params::with_capacity(5 + self._additional_params.len());
3656 params.push("parent", self._parent);
3657 if let Some(value) = self._page_token.as_ref() {
3658 params.push("pageToken", value);
3659 }
3660 if let Some(value) = self._page_size.as_ref() {
3661 params.push("pageSize", value.to_string());
3662 }
3663
3664 params.extend(self._additional_params.iter());
3665
3666 params.push("alt", "json");
3667 let mut url = self.hub._base_url.clone() + "v2/{+parent}/constraints";
3668 if self._scopes.is_empty() {
3669 self._scopes
3670 .insert(Scope::CloudPlatform.as_ref().to_string());
3671 }
3672
3673 #[allow(clippy::single_element_loop)]
3674 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
3675 url = params.uri_replacement(url, param_name, find_this, true);
3676 }
3677 {
3678 let to_remove = ["parent"];
3679 params.remove_params(&to_remove);
3680 }
3681
3682 let url = params.parse_with_url(&url);
3683
3684 loop {
3685 let token = match self
3686 .hub
3687 .auth
3688 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
3689 .await
3690 {
3691 Ok(token) => token,
3692 Err(e) => match dlg.token(e) {
3693 Ok(token) => token,
3694 Err(e) => {
3695 dlg.finished(false);
3696 return Err(common::Error::MissingToken(e));
3697 }
3698 },
3699 };
3700 let mut req_result = {
3701 let client = &self.hub.client;
3702 dlg.pre_request();
3703 let mut req_builder = hyper::Request::builder()
3704 .method(hyper::Method::GET)
3705 .uri(url.as_str())
3706 .header(USER_AGENT, self.hub._user_agent.clone());
3707
3708 if let Some(token) = token.as_ref() {
3709 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
3710 }
3711
3712 let request = req_builder
3713 .header(CONTENT_LENGTH, 0_u64)
3714 .body(common::to_body::<String>(None));
3715
3716 client.request(request.unwrap()).await
3717 };
3718
3719 match req_result {
3720 Err(err) => {
3721 if let common::Retry::After(d) = dlg.http_error(&err) {
3722 sleep(d).await;
3723 continue;
3724 }
3725 dlg.finished(false);
3726 return Err(common::Error::HttpError(err));
3727 }
3728 Ok(res) => {
3729 let (mut parts, body) = res.into_parts();
3730 let mut body = common::Body::new(body);
3731 if !parts.status.is_success() {
3732 let bytes = common::to_bytes(body).await.unwrap_or_default();
3733 let error = serde_json::from_str(&common::to_string(&bytes));
3734 let response = common::to_response(parts, bytes.into());
3735
3736 if let common::Retry::After(d) =
3737 dlg.http_failure(&response, error.as_ref().ok())
3738 {
3739 sleep(d).await;
3740 continue;
3741 }
3742
3743 dlg.finished(false);
3744
3745 return Err(match error {
3746 Ok(value) => common::Error::BadRequest(value),
3747 _ => common::Error::Failure(response),
3748 });
3749 }
3750 let response = {
3751 let bytes = common::to_bytes(body).await.unwrap_or_default();
3752 let encoded = common::to_string(&bytes);
3753 match serde_json::from_str(&encoded) {
3754 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
3755 Err(error) => {
3756 dlg.response_json_decode_error(&encoded, &error);
3757 return Err(common::Error::JsonDecodeError(
3758 encoded.to_string(),
3759 error,
3760 ));
3761 }
3762 }
3763 };
3764
3765 dlg.finished(true);
3766 return Ok(response);
3767 }
3768 }
3769 }
3770 }
3771
3772 /// Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
3773 ///
3774 /// Sets the *parent* path property to the given value.
3775 ///
3776 /// Even though the property as already been set when instantiating this call,
3777 /// we provide this method for API completeness.
3778 pub fn parent(mut self, new_value: &str) -> OrganizationConstraintListCall<'a, C> {
3779 self._parent = new_value.to_string();
3780 self
3781 }
3782 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
3783 ///
3784 /// Sets the *page token* query property to the given value.
3785 pub fn page_token(mut self, new_value: &str) -> OrganizationConstraintListCall<'a, C> {
3786 self._page_token = Some(new_value.to_string());
3787 self
3788 }
3789 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
3790 ///
3791 /// Sets the *page size* query property to the given value.
3792 pub fn page_size(mut self, new_value: i32) -> OrganizationConstraintListCall<'a, C> {
3793 self._page_size = Some(new_value);
3794 self
3795 }
3796 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
3797 /// while executing the actual API request.
3798 ///
3799 /// ````text
3800 /// It should be used to handle progress information, and to implement a certain level of resilience.
3801 /// ````
3802 ///
3803 /// Sets the *delegate* property to the given value.
3804 pub fn delegate(
3805 mut self,
3806 new_value: &'a mut dyn common::Delegate,
3807 ) -> OrganizationConstraintListCall<'a, C> {
3808 self._delegate = Some(new_value);
3809 self
3810 }
3811
3812 /// Set any additional parameter of the query string used in the request.
3813 /// It should be used to set parameters which are not yet available through their own
3814 /// setters.
3815 ///
3816 /// Please note that this method must not be used to set any of the known parameters
3817 /// which have their own setter method. If done anyway, the request will fail.
3818 ///
3819 /// # Additional Parameters
3820 ///
3821 /// * *$.xgafv* (query-string) - V1 error format.
3822 /// * *access_token* (query-string) - OAuth access token.
3823 /// * *alt* (query-string) - Data format for response.
3824 /// * *callback* (query-string) - JSONP
3825 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
3826 /// * *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.
3827 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
3828 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
3829 /// * *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.
3830 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
3831 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
3832 pub fn param<T>(mut self, name: T, value: T) -> OrganizationConstraintListCall<'a, C>
3833 where
3834 T: AsRef<str>,
3835 {
3836 self._additional_params
3837 .insert(name.as_ref().to_string(), value.as_ref().to_string());
3838 self
3839 }
3840
3841 /// Identifies the authorization scope for the method you are building.
3842 ///
3843 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
3844 /// [`Scope::CloudPlatform`].
3845 ///
3846 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
3847 /// tokens for more than one scope.
3848 ///
3849 /// Usually there is more than one suitable scope to authorize an operation, some of which may
3850 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
3851 /// sufficient, a read-write scope will do as well.
3852 pub fn add_scope<St>(mut self, scope: St) -> OrganizationConstraintListCall<'a, C>
3853 where
3854 St: AsRef<str>,
3855 {
3856 self._scopes.insert(String::from(scope.as_ref()));
3857 self
3858 }
3859 /// Identifies the authorization scope(s) for the method you are building.
3860 ///
3861 /// See [`Self::add_scope()`] for details.
3862 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationConstraintListCall<'a, C>
3863 where
3864 I: IntoIterator<Item = St>,
3865 St: AsRef<str>,
3866 {
3867 self._scopes
3868 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
3869 self
3870 }
3871
3872 /// Removes all scopes, and no default scope will be used either.
3873 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
3874 /// for details).
3875 pub fn clear_scopes(mut self) -> OrganizationConstraintListCall<'a, C> {
3876 self._scopes.clear();
3877 self
3878 }
3879}
3880
3881/// Creates a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the organization does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the constraint already exists on the given organization.
3882///
3883/// A builder for the *customConstraints.create* method supported by a *organization* resource.
3884/// It is not used directly, but through a [`OrganizationMethods`] instance.
3885///
3886/// # Example
3887///
3888/// Instantiate a resource method builder
3889///
3890/// ```test_harness,no_run
3891/// # extern crate hyper;
3892/// # extern crate hyper_rustls;
3893/// # extern crate google_orgpolicy2 as orgpolicy2;
3894/// use orgpolicy2::api::GoogleCloudOrgpolicyV2CustomConstraint;
3895/// # async fn dox() {
3896/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
3897///
3898/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
3899/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
3900/// # .with_native_roots()
3901/// # .unwrap()
3902/// # .https_only()
3903/// # .enable_http2()
3904/// # .build();
3905///
3906/// # let executor = hyper_util::rt::TokioExecutor::new();
3907/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
3908/// # secret,
3909/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
3910/// # yup_oauth2::client::CustomHyperClientBuilder::from(
3911/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
3912/// # ),
3913/// # ).build().await.unwrap();
3914///
3915/// # let client = hyper_util::client::legacy::Client::builder(
3916/// # hyper_util::rt::TokioExecutor::new()
3917/// # )
3918/// # .build(
3919/// # hyper_rustls::HttpsConnectorBuilder::new()
3920/// # .with_native_roots()
3921/// # .unwrap()
3922/// # .https_or_http()
3923/// # .enable_http2()
3924/// # .build()
3925/// # );
3926/// # let mut hub = OrgPolicyAPI::new(client, auth);
3927/// // As the method needs a request, you would usually fill it with the desired information
3928/// // into the respective structure. Some of the parts shown here might not be applicable !
3929/// // Values shown here are possibly random and not representative !
3930/// let mut req = GoogleCloudOrgpolicyV2CustomConstraint::default();
3931///
3932/// // You can configure optional parameters by calling the respective setters at will, and
3933/// // execute the final call using `doit()`.
3934/// // Values shown here are possibly random and not representative !
3935/// let result = hub.organizations().custom_constraints_create(req, "parent")
3936/// .doit().await;
3937/// # }
3938/// ```
3939pub struct OrganizationCustomConstraintCreateCall<'a, C>
3940where
3941 C: 'a,
3942{
3943 hub: &'a OrgPolicyAPI<C>,
3944 _request: GoogleCloudOrgpolicyV2CustomConstraint,
3945 _parent: String,
3946 _delegate: Option<&'a mut dyn common::Delegate>,
3947 _additional_params: HashMap<String, String>,
3948 _scopes: BTreeSet<String>,
3949}
3950
3951impl<'a, C> common::CallBuilder for OrganizationCustomConstraintCreateCall<'a, C> {}
3952
3953impl<'a, C> OrganizationCustomConstraintCreateCall<'a, C>
3954where
3955 C: common::Connector,
3956{
3957 /// Perform the operation you have build so far.
3958 pub async fn doit(
3959 mut self,
3960 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2CustomConstraint)> {
3961 use std::borrow::Cow;
3962 use std::io::{Read, Seek};
3963
3964 use common::{url::Params, ToParts};
3965 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
3966
3967 let mut dd = common::DefaultDelegate;
3968 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
3969 dlg.begin(common::MethodInfo {
3970 id: "orgpolicy.organizations.customConstraints.create",
3971 http_method: hyper::Method::POST,
3972 });
3973
3974 for &field in ["alt", "parent"].iter() {
3975 if self._additional_params.contains_key(field) {
3976 dlg.finished(false);
3977 return Err(common::Error::FieldClash(field));
3978 }
3979 }
3980
3981 let mut params = Params::with_capacity(4 + self._additional_params.len());
3982 params.push("parent", self._parent);
3983
3984 params.extend(self._additional_params.iter());
3985
3986 params.push("alt", "json");
3987 let mut url = self.hub._base_url.clone() + "v2/{+parent}/customConstraints";
3988 if self._scopes.is_empty() {
3989 self._scopes
3990 .insert(Scope::CloudPlatform.as_ref().to_string());
3991 }
3992
3993 #[allow(clippy::single_element_loop)]
3994 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
3995 url = params.uri_replacement(url, param_name, find_this, true);
3996 }
3997 {
3998 let to_remove = ["parent"];
3999 params.remove_params(&to_remove);
4000 }
4001
4002 let url = params.parse_with_url(&url);
4003
4004 let mut json_mime_type = mime::APPLICATION_JSON;
4005 let mut request_value_reader = {
4006 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
4007 common::remove_json_null_values(&mut value);
4008 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
4009 serde_json::to_writer(&mut dst, &value).unwrap();
4010 dst
4011 };
4012 let request_size = request_value_reader
4013 .seek(std::io::SeekFrom::End(0))
4014 .unwrap();
4015 request_value_reader
4016 .seek(std::io::SeekFrom::Start(0))
4017 .unwrap();
4018
4019 loop {
4020 let token = match self
4021 .hub
4022 .auth
4023 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
4024 .await
4025 {
4026 Ok(token) => token,
4027 Err(e) => match dlg.token(e) {
4028 Ok(token) => token,
4029 Err(e) => {
4030 dlg.finished(false);
4031 return Err(common::Error::MissingToken(e));
4032 }
4033 },
4034 };
4035 request_value_reader
4036 .seek(std::io::SeekFrom::Start(0))
4037 .unwrap();
4038 let mut req_result = {
4039 let client = &self.hub.client;
4040 dlg.pre_request();
4041 let mut req_builder = hyper::Request::builder()
4042 .method(hyper::Method::POST)
4043 .uri(url.as_str())
4044 .header(USER_AGENT, self.hub._user_agent.clone());
4045
4046 if let Some(token) = token.as_ref() {
4047 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
4048 }
4049
4050 let request = req_builder
4051 .header(CONTENT_TYPE, json_mime_type.to_string())
4052 .header(CONTENT_LENGTH, request_size as u64)
4053 .body(common::to_body(
4054 request_value_reader.get_ref().clone().into(),
4055 ));
4056
4057 client.request(request.unwrap()).await
4058 };
4059
4060 match req_result {
4061 Err(err) => {
4062 if let common::Retry::After(d) = dlg.http_error(&err) {
4063 sleep(d).await;
4064 continue;
4065 }
4066 dlg.finished(false);
4067 return Err(common::Error::HttpError(err));
4068 }
4069 Ok(res) => {
4070 let (mut parts, body) = res.into_parts();
4071 let mut body = common::Body::new(body);
4072 if !parts.status.is_success() {
4073 let bytes = common::to_bytes(body).await.unwrap_or_default();
4074 let error = serde_json::from_str(&common::to_string(&bytes));
4075 let response = common::to_response(parts, bytes.into());
4076
4077 if let common::Retry::After(d) =
4078 dlg.http_failure(&response, error.as_ref().ok())
4079 {
4080 sleep(d).await;
4081 continue;
4082 }
4083
4084 dlg.finished(false);
4085
4086 return Err(match error {
4087 Ok(value) => common::Error::BadRequest(value),
4088 _ => common::Error::Failure(response),
4089 });
4090 }
4091 let response = {
4092 let bytes = common::to_bytes(body).await.unwrap_or_default();
4093 let encoded = common::to_string(&bytes);
4094 match serde_json::from_str(&encoded) {
4095 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
4096 Err(error) => {
4097 dlg.response_json_decode_error(&encoded, &error);
4098 return Err(common::Error::JsonDecodeError(
4099 encoded.to_string(),
4100 error,
4101 ));
4102 }
4103 }
4104 };
4105
4106 dlg.finished(true);
4107 return Ok(response);
4108 }
4109 }
4110 }
4111 }
4112
4113 ///
4114 /// Sets the *request* property to the given value.
4115 ///
4116 /// Even though the property as already been set when instantiating this call,
4117 /// we provide this method for API completeness.
4118 pub fn request(
4119 mut self,
4120 new_value: GoogleCloudOrgpolicyV2CustomConstraint,
4121 ) -> OrganizationCustomConstraintCreateCall<'a, C> {
4122 self._request = new_value;
4123 self
4124 }
4125 /// Required. Must be in the following form: * `organizations/{organization_id}`
4126 ///
4127 /// Sets the *parent* path property to the given value.
4128 ///
4129 /// Even though the property as already been set when instantiating this call,
4130 /// we provide this method for API completeness.
4131 pub fn parent(mut self, new_value: &str) -> OrganizationCustomConstraintCreateCall<'a, C> {
4132 self._parent = new_value.to_string();
4133 self
4134 }
4135 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
4136 /// while executing the actual API request.
4137 ///
4138 /// ````text
4139 /// It should be used to handle progress information, and to implement a certain level of resilience.
4140 /// ````
4141 ///
4142 /// Sets the *delegate* property to the given value.
4143 pub fn delegate(
4144 mut self,
4145 new_value: &'a mut dyn common::Delegate,
4146 ) -> OrganizationCustomConstraintCreateCall<'a, C> {
4147 self._delegate = Some(new_value);
4148 self
4149 }
4150
4151 /// Set any additional parameter of the query string used in the request.
4152 /// It should be used to set parameters which are not yet available through their own
4153 /// setters.
4154 ///
4155 /// Please note that this method must not be used to set any of the known parameters
4156 /// which have their own setter method. If done anyway, the request will fail.
4157 ///
4158 /// # Additional Parameters
4159 ///
4160 /// * *$.xgafv* (query-string) - V1 error format.
4161 /// * *access_token* (query-string) - OAuth access token.
4162 /// * *alt* (query-string) - Data format for response.
4163 /// * *callback* (query-string) - JSONP
4164 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
4165 /// * *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.
4166 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
4167 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
4168 /// * *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.
4169 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
4170 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
4171 pub fn param<T>(mut self, name: T, value: T) -> OrganizationCustomConstraintCreateCall<'a, C>
4172 where
4173 T: AsRef<str>,
4174 {
4175 self._additional_params
4176 .insert(name.as_ref().to_string(), value.as_ref().to_string());
4177 self
4178 }
4179
4180 /// Identifies the authorization scope for the method you are building.
4181 ///
4182 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
4183 /// [`Scope::CloudPlatform`].
4184 ///
4185 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
4186 /// tokens for more than one scope.
4187 ///
4188 /// Usually there is more than one suitable scope to authorize an operation, some of which may
4189 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
4190 /// sufficient, a read-write scope will do as well.
4191 pub fn add_scope<St>(mut self, scope: St) -> OrganizationCustomConstraintCreateCall<'a, C>
4192 where
4193 St: AsRef<str>,
4194 {
4195 self._scopes.insert(String::from(scope.as_ref()));
4196 self
4197 }
4198 /// Identifies the authorization scope(s) for the method you are building.
4199 ///
4200 /// See [`Self::add_scope()`] for details.
4201 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationCustomConstraintCreateCall<'a, C>
4202 where
4203 I: IntoIterator<Item = St>,
4204 St: AsRef<str>,
4205 {
4206 self._scopes
4207 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
4208 self
4209 }
4210
4211 /// Removes all scopes, and no default scope will be used either.
4212 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
4213 /// for details).
4214 pub fn clear_scopes(mut self) -> OrganizationCustomConstraintCreateCall<'a, C> {
4215 self._scopes.clear();
4216 self
4217 }
4218}
4219
4220/// Deletes a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist.
4221///
4222/// A builder for the *customConstraints.delete* method supported by a *organization* resource.
4223/// It is not used directly, but through a [`OrganizationMethods`] instance.
4224///
4225/// # Example
4226///
4227/// Instantiate a resource method builder
4228///
4229/// ```test_harness,no_run
4230/// # extern crate hyper;
4231/// # extern crate hyper_rustls;
4232/// # extern crate google_orgpolicy2 as orgpolicy2;
4233/// # async fn dox() {
4234/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
4235///
4236/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
4237/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
4238/// # .with_native_roots()
4239/// # .unwrap()
4240/// # .https_only()
4241/// # .enable_http2()
4242/// # .build();
4243///
4244/// # let executor = hyper_util::rt::TokioExecutor::new();
4245/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
4246/// # secret,
4247/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
4248/// # yup_oauth2::client::CustomHyperClientBuilder::from(
4249/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
4250/// # ),
4251/// # ).build().await.unwrap();
4252///
4253/// # let client = hyper_util::client::legacy::Client::builder(
4254/// # hyper_util::rt::TokioExecutor::new()
4255/// # )
4256/// # .build(
4257/// # hyper_rustls::HttpsConnectorBuilder::new()
4258/// # .with_native_roots()
4259/// # .unwrap()
4260/// # .https_or_http()
4261/// # .enable_http2()
4262/// # .build()
4263/// # );
4264/// # let mut hub = OrgPolicyAPI::new(client, auth);
4265/// // You can configure optional parameters by calling the respective setters at will, and
4266/// // execute the final call using `doit()`.
4267/// // Values shown here are possibly random and not representative !
4268/// let result = hub.organizations().custom_constraints_delete("name")
4269/// .doit().await;
4270/// # }
4271/// ```
4272pub struct OrganizationCustomConstraintDeleteCall<'a, C>
4273where
4274 C: 'a,
4275{
4276 hub: &'a OrgPolicyAPI<C>,
4277 _name: String,
4278 _delegate: Option<&'a mut dyn common::Delegate>,
4279 _additional_params: HashMap<String, String>,
4280 _scopes: BTreeSet<String>,
4281}
4282
4283impl<'a, C> common::CallBuilder for OrganizationCustomConstraintDeleteCall<'a, C> {}
4284
4285impl<'a, C> OrganizationCustomConstraintDeleteCall<'a, C>
4286where
4287 C: common::Connector,
4288{
4289 /// Perform the operation you have build so far.
4290 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleProtobufEmpty)> {
4291 use std::borrow::Cow;
4292 use std::io::{Read, Seek};
4293
4294 use common::{url::Params, ToParts};
4295 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
4296
4297 let mut dd = common::DefaultDelegate;
4298 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
4299 dlg.begin(common::MethodInfo {
4300 id: "orgpolicy.organizations.customConstraints.delete",
4301 http_method: hyper::Method::DELETE,
4302 });
4303
4304 for &field in ["alt", "name"].iter() {
4305 if self._additional_params.contains_key(field) {
4306 dlg.finished(false);
4307 return Err(common::Error::FieldClash(field));
4308 }
4309 }
4310
4311 let mut params = Params::with_capacity(3 + self._additional_params.len());
4312 params.push("name", self._name);
4313
4314 params.extend(self._additional_params.iter());
4315
4316 params.push("alt", "json");
4317 let mut url = self.hub._base_url.clone() + "v2/{+name}";
4318 if self._scopes.is_empty() {
4319 self._scopes
4320 .insert(Scope::CloudPlatform.as_ref().to_string());
4321 }
4322
4323 #[allow(clippy::single_element_loop)]
4324 for &(find_this, param_name) in [("{+name}", "name")].iter() {
4325 url = params.uri_replacement(url, param_name, find_this, true);
4326 }
4327 {
4328 let to_remove = ["name"];
4329 params.remove_params(&to_remove);
4330 }
4331
4332 let url = params.parse_with_url(&url);
4333
4334 loop {
4335 let token = match self
4336 .hub
4337 .auth
4338 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
4339 .await
4340 {
4341 Ok(token) => token,
4342 Err(e) => match dlg.token(e) {
4343 Ok(token) => token,
4344 Err(e) => {
4345 dlg.finished(false);
4346 return Err(common::Error::MissingToken(e));
4347 }
4348 },
4349 };
4350 let mut req_result = {
4351 let client = &self.hub.client;
4352 dlg.pre_request();
4353 let mut req_builder = hyper::Request::builder()
4354 .method(hyper::Method::DELETE)
4355 .uri(url.as_str())
4356 .header(USER_AGENT, self.hub._user_agent.clone());
4357
4358 if let Some(token) = token.as_ref() {
4359 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
4360 }
4361
4362 let request = req_builder
4363 .header(CONTENT_LENGTH, 0_u64)
4364 .body(common::to_body::<String>(None));
4365
4366 client.request(request.unwrap()).await
4367 };
4368
4369 match req_result {
4370 Err(err) => {
4371 if let common::Retry::After(d) = dlg.http_error(&err) {
4372 sleep(d).await;
4373 continue;
4374 }
4375 dlg.finished(false);
4376 return Err(common::Error::HttpError(err));
4377 }
4378 Ok(res) => {
4379 let (mut parts, body) = res.into_parts();
4380 let mut body = common::Body::new(body);
4381 if !parts.status.is_success() {
4382 let bytes = common::to_bytes(body).await.unwrap_or_default();
4383 let error = serde_json::from_str(&common::to_string(&bytes));
4384 let response = common::to_response(parts, bytes.into());
4385
4386 if let common::Retry::After(d) =
4387 dlg.http_failure(&response, error.as_ref().ok())
4388 {
4389 sleep(d).await;
4390 continue;
4391 }
4392
4393 dlg.finished(false);
4394
4395 return Err(match error {
4396 Ok(value) => common::Error::BadRequest(value),
4397 _ => common::Error::Failure(response),
4398 });
4399 }
4400 let response = {
4401 let bytes = common::to_bytes(body).await.unwrap_or_default();
4402 let encoded = common::to_string(&bytes);
4403 match serde_json::from_str(&encoded) {
4404 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
4405 Err(error) => {
4406 dlg.response_json_decode_error(&encoded, &error);
4407 return Err(common::Error::JsonDecodeError(
4408 encoded.to_string(),
4409 error,
4410 ));
4411 }
4412 }
4413 };
4414
4415 dlg.finished(true);
4416 return Ok(response);
4417 }
4418 }
4419 }
4420 }
4421
4422 /// Required. Name of the custom constraint to delete. See the custom constraint entry for naming rules.
4423 ///
4424 /// Sets the *name* path property to the given value.
4425 ///
4426 /// Even though the property as already been set when instantiating this call,
4427 /// we provide this method for API completeness.
4428 pub fn name(mut self, new_value: &str) -> OrganizationCustomConstraintDeleteCall<'a, C> {
4429 self._name = new_value.to_string();
4430 self
4431 }
4432 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
4433 /// while executing the actual API request.
4434 ///
4435 /// ````text
4436 /// It should be used to handle progress information, and to implement a certain level of resilience.
4437 /// ````
4438 ///
4439 /// Sets the *delegate* property to the given value.
4440 pub fn delegate(
4441 mut self,
4442 new_value: &'a mut dyn common::Delegate,
4443 ) -> OrganizationCustomConstraintDeleteCall<'a, C> {
4444 self._delegate = Some(new_value);
4445 self
4446 }
4447
4448 /// Set any additional parameter of the query string used in the request.
4449 /// It should be used to set parameters which are not yet available through their own
4450 /// setters.
4451 ///
4452 /// Please note that this method must not be used to set any of the known parameters
4453 /// which have their own setter method. If done anyway, the request will fail.
4454 ///
4455 /// # Additional Parameters
4456 ///
4457 /// * *$.xgafv* (query-string) - V1 error format.
4458 /// * *access_token* (query-string) - OAuth access token.
4459 /// * *alt* (query-string) - Data format for response.
4460 /// * *callback* (query-string) - JSONP
4461 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
4462 /// * *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.
4463 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
4464 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
4465 /// * *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.
4466 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
4467 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
4468 pub fn param<T>(mut self, name: T, value: T) -> OrganizationCustomConstraintDeleteCall<'a, C>
4469 where
4470 T: AsRef<str>,
4471 {
4472 self._additional_params
4473 .insert(name.as_ref().to_string(), value.as_ref().to_string());
4474 self
4475 }
4476
4477 /// Identifies the authorization scope for the method you are building.
4478 ///
4479 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
4480 /// [`Scope::CloudPlatform`].
4481 ///
4482 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
4483 /// tokens for more than one scope.
4484 ///
4485 /// Usually there is more than one suitable scope to authorize an operation, some of which may
4486 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
4487 /// sufficient, a read-write scope will do as well.
4488 pub fn add_scope<St>(mut self, scope: St) -> OrganizationCustomConstraintDeleteCall<'a, C>
4489 where
4490 St: AsRef<str>,
4491 {
4492 self._scopes.insert(String::from(scope.as_ref()));
4493 self
4494 }
4495 /// Identifies the authorization scope(s) for the method you are building.
4496 ///
4497 /// See [`Self::add_scope()`] for details.
4498 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationCustomConstraintDeleteCall<'a, C>
4499 where
4500 I: IntoIterator<Item = St>,
4501 St: AsRef<str>,
4502 {
4503 self._scopes
4504 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
4505 self
4506 }
4507
4508 /// Removes all scopes, and no default scope will be used either.
4509 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
4510 /// for details).
4511 pub fn clear_scopes(mut self) -> OrganizationCustomConstraintDeleteCall<'a, C> {
4512 self._scopes.clear();
4513 self
4514 }
4515}
4516
4517/// Gets a custom or managed constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the custom or managed constraint does not exist.
4518///
4519/// A builder for the *customConstraints.get* method supported by a *organization* resource.
4520/// It is not used directly, but through a [`OrganizationMethods`] instance.
4521///
4522/// # Example
4523///
4524/// Instantiate a resource method builder
4525///
4526/// ```test_harness,no_run
4527/// # extern crate hyper;
4528/// # extern crate hyper_rustls;
4529/// # extern crate google_orgpolicy2 as orgpolicy2;
4530/// # async fn dox() {
4531/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
4532///
4533/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
4534/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
4535/// # .with_native_roots()
4536/// # .unwrap()
4537/// # .https_only()
4538/// # .enable_http2()
4539/// # .build();
4540///
4541/// # let executor = hyper_util::rt::TokioExecutor::new();
4542/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
4543/// # secret,
4544/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
4545/// # yup_oauth2::client::CustomHyperClientBuilder::from(
4546/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
4547/// # ),
4548/// # ).build().await.unwrap();
4549///
4550/// # let client = hyper_util::client::legacy::Client::builder(
4551/// # hyper_util::rt::TokioExecutor::new()
4552/// # )
4553/// # .build(
4554/// # hyper_rustls::HttpsConnectorBuilder::new()
4555/// # .with_native_roots()
4556/// # .unwrap()
4557/// # .https_or_http()
4558/// # .enable_http2()
4559/// # .build()
4560/// # );
4561/// # let mut hub = OrgPolicyAPI::new(client, auth);
4562/// // You can configure optional parameters by calling the respective setters at will, and
4563/// // execute the final call using `doit()`.
4564/// // Values shown here are possibly random and not representative !
4565/// let result = hub.organizations().custom_constraints_get("name")
4566/// .doit().await;
4567/// # }
4568/// ```
4569pub struct OrganizationCustomConstraintGetCall<'a, C>
4570where
4571 C: 'a,
4572{
4573 hub: &'a OrgPolicyAPI<C>,
4574 _name: String,
4575 _delegate: Option<&'a mut dyn common::Delegate>,
4576 _additional_params: HashMap<String, String>,
4577 _scopes: BTreeSet<String>,
4578}
4579
4580impl<'a, C> common::CallBuilder for OrganizationCustomConstraintGetCall<'a, C> {}
4581
4582impl<'a, C> OrganizationCustomConstraintGetCall<'a, C>
4583where
4584 C: common::Connector,
4585{
4586 /// Perform the operation you have build so far.
4587 pub async fn doit(
4588 mut self,
4589 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2CustomConstraint)> {
4590 use std::borrow::Cow;
4591 use std::io::{Read, Seek};
4592
4593 use common::{url::Params, ToParts};
4594 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
4595
4596 let mut dd = common::DefaultDelegate;
4597 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
4598 dlg.begin(common::MethodInfo {
4599 id: "orgpolicy.organizations.customConstraints.get",
4600 http_method: hyper::Method::GET,
4601 });
4602
4603 for &field in ["alt", "name"].iter() {
4604 if self._additional_params.contains_key(field) {
4605 dlg.finished(false);
4606 return Err(common::Error::FieldClash(field));
4607 }
4608 }
4609
4610 let mut params = Params::with_capacity(3 + self._additional_params.len());
4611 params.push("name", self._name);
4612
4613 params.extend(self._additional_params.iter());
4614
4615 params.push("alt", "json");
4616 let mut url = self.hub._base_url.clone() + "v2/{+name}";
4617 if self._scopes.is_empty() {
4618 self._scopes
4619 .insert(Scope::CloudPlatform.as_ref().to_string());
4620 }
4621
4622 #[allow(clippy::single_element_loop)]
4623 for &(find_this, param_name) in [("{+name}", "name")].iter() {
4624 url = params.uri_replacement(url, param_name, find_this, true);
4625 }
4626 {
4627 let to_remove = ["name"];
4628 params.remove_params(&to_remove);
4629 }
4630
4631 let url = params.parse_with_url(&url);
4632
4633 loop {
4634 let token = match self
4635 .hub
4636 .auth
4637 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
4638 .await
4639 {
4640 Ok(token) => token,
4641 Err(e) => match dlg.token(e) {
4642 Ok(token) => token,
4643 Err(e) => {
4644 dlg.finished(false);
4645 return Err(common::Error::MissingToken(e));
4646 }
4647 },
4648 };
4649 let mut req_result = {
4650 let client = &self.hub.client;
4651 dlg.pre_request();
4652 let mut req_builder = hyper::Request::builder()
4653 .method(hyper::Method::GET)
4654 .uri(url.as_str())
4655 .header(USER_AGENT, self.hub._user_agent.clone());
4656
4657 if let Some(token) = token.as_ref() {
4658 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
4659 }
4660
4661 let request = req_builder
4662 .header(CONTENT_LENGTH, 0_u64)
4663 .body(common::to_body::<String>(None));
4664
4665 client.request(request.unwrap()).await
4666 };
4667
4668 match req_result {
4669 Err(err) => {
4670 if let common::Retry::After(d) = dlg.http_error(&err) {
4671 sleep(d).await;
4672 continue;
4673 }
4674 dlg.finished(false);
4675 return Err(common::Error::HttpError(err));
4676 }
4677 Ok(res) => {
4678 let (mut parts, body) = res.into_parts();
4679 let mut body = common::Body::new(body);
4680 if !parts.status.is_success() {
4681 let bytes = common::to_bytes(body).await.unwrap_or_default();
4682 let error = serde_json::from_str(&common::to_string(&bytes));
4683 let response = common::to_response(parts, bytes.into());
4684
4685 if let common::Retry::After(d) =
4686 dlg.http_failure(&response, error.as_ref().ok())
4687 {
4688 sleep(d).await;
4689 continue;
4690 }
4691
4692 dlg.finished(false);
4693
4694 return Err(match error {
4695 Ok(value) => common::Error::BadRequest(value),
4696 _ => common::Error::Failure(response),
4697 });
4698 }
4699 let response = {
4700 let bytes = common::to_bytes(body).await.unwrap_or_default();
4701 let encoded = common::to_string(&bytes);
4702 match serde_json::from_str(&encoded) {
4703 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
4704 Err(error) => {
4705 dlg.response_json_decode_error(&encoded, &error);
4706 return Err(common::Error::JsonDecodeError(
4707 encoded.to_string(),
4708 error,
4709 ));
4710 }
4711 }
4712 };
4713
4714 dlg.finished(true);
4715 return Ok(response);
4716 }
4717 }
4718 }
4719 }
4720
4721 /// Required. Resource name of the custom or managed constraint. See the custom constraint entry for naming requirements.
4722 ///
4723 /// Sets the *name* path property to the given value.
4724 ///
4725 /// Even though the property as already been set when instantiating this call,
4726 /// we provide this method for API completeness.
4727 pub fn name(mut self, new_value: &str) -> OrganizationCustomConstraintGetCall<'a, C> {
4728 self._name = new_value.to_string();
4729 self
4730 }
4731 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
4732 /// while executing the actual API request.
4733 ///
4734 /// ````text
4735 /// It should be used to handle progress information, and to implement a certain level of resilience.
4736 /// ````
4737 ///
4738 /// Sets the *delegate* property to the given value.
4739 pub fn delegate(
4740 mut self,
4741 new_value: &'a mut dyn common::Delegate,
4742 ) -> OrganizationCustomConstraintGetCall<'a, C> {
4743 self._delegate = Some(new_value);
4744 self
4745 }
4746
4747 /// Set any additional parameter of the query string used in the request.
4748 /// It should be used to set parameters which are not yet available through their own
4749 /// setters.
4750 ///
4751 /// Please note that this method must not be used to set any of the known parameters
4752 /// which have their own setter method. If done anyway, the request will fail.
4753 ///
4754 /// # Additional Parameters
4755 ///
4756 /// * *$.xgafv* (query-string) - V1 error format.
4757 /// * *access_token* (query-string) - OAuth access token.
4758 /// * *alt* (query-string) - Data format for response.
4759 /// * *callback* (query-string) - JSONP
4760 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
4761 /// * *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.
4762 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
4763 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
4764 /// * *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.
4765 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
4766 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
4767 pub fn param<T>(mut self, name: T, value: T) -> OrganizationCustomConstraintGetCall<'a, C>
4768 where
4769 T: AsRef<str>,
4770 {
4771 self._additional_params
4772 .insert(name.as_ref().to_string(), value.as_ref().to_string());
4773 self
4774 }
4775
4776 /// Identifies the authorization scope for the method you are building.
4777 ///
4778 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
4779 /// [`Scope::CloudPlatform`].
4780 ///
4781 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
4782 /// tokens for more than one scope.
4783 ///
4784 /// Usually there is more than one suitable scope to authorize an operation, some of which may
4785 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
4786 /// sufficient, a read-write scope will do as well.
4787 pub fn add_scope<St>(mut self, scope: St) -> OrganizationCustomConstraintGetCall<'a, C>
4788 where
4789 St: AsRef<str>,
4790 {
4791 self._scopes.insert(String::from(scope.as_ref()));
4792 self
4793 }
4794 /// Identifies the authorization scope(s) for the method you are building.
4795 ///
4796 /// See [`Self::add_scope()`] for details.
4797 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationCustomConstraintGetCall<'a, C>
4798 where
4799 I: IntoIterator<Item = St>,
4800 St: AsRef<str>,
4801 {
4802 self._scopes
4803 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
4804 self
4805 }
4806
4807 /// Removes all scopes, and no default scope will be used either.
4808 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
4809 /// for details).
4810 pub fn clear_scopes(mut self) -> OrganizationCustomConstraintGetCall<'a, C> {
4811 self._scopes.clear();
4812 self
4813 }
4814}
4815
4816/// Retrieves all of the custom constraints that exist on a particular organization resource.
4817///
4818/// A builder for the *customConstraints.list* method supported by a *organization* resource.
4819/// It is not used directly, but through a [`OrganizationMethods`] instance.
4820///
4821/// # Example
4822///
4823/// Instantiate a resource method builder
4824///
4825/// ```test_harness,no_run
4826/// # extern crate hyper;
4827/// # extern crate hyper_rustls;
4828/// # extern crate google_orgpolicy2 as orgpolicy2;
4829/// # async fn dox() {
4830/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
4831///
4832/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
4833/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
4834/// # .with_native_roots()
4835/// # .unwrap()
4836/// # .https_only()
4837/// # .enable_http2()
4838/// # .build();
4839///
4840/// # let executor = hyper_util::rt::TokioExecutor::new();
4841/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
4842/// # secret,
4843/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
4844/// # yup_oauth2::client::CustomHyperClientBuilder::from(
4845/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
4846/// # ),
4847/// # ).build().await.unwrap();
4848///
4849/// # let client = hyper_util::client::legacy::Client::builder(
4850/// # hyper_util::rt::TokioExecutor::new()
4851/// # )
4852/// # .build(
4853/// # hyper_rustls::HttpsConnectorBuilder::new()
4854/// # .with_native_roots()
4855/// # .unwrap()
4856/// # .https_or_http()
4857/// # .enable_http2()
4858/// # .build()
4859/// # );
4860/// # let mut hub = OrgPolicyAPI::new(client, auth);
4861/// // You can configure optional parameters by calling the respective setters at will, and
4862/// // execute the final call using `doit()`.
4863/// // Values shown here are possibly random and not representative !
4864/// let result = hub.organizations().custom_constraints_list("parent")
4865/// .page_token("duo")
4866/// .page_size(-50)
4867/// .doit().await;
4868/// # }
4869/// ```
4870pub struct OrganizationCustomConstraintListCall<'a, C>
4871where
4872 C: 'a,
4873{
4874 hub: &'a OrgPolicyAPI<C>,
4875 _parent: String,
4876 _page_token: Option<String>,
4877 _page_size: Option<i32>,
4878 _delegate: Option<&'a mut dyn common::Delegate>,
4879 _additional_params: HashMap<String, String>,
4880 _scopes: BTreeSet<String>,
4881}
4882
4883impl<'a, C> common::CallBuilder for OrganizationCustomConstraintListCall<'a, C> {}
4884
4885impl<'a, C> OrganizationCustomConstraintListCall<'a, C>
4886where
4887 C: common::Connector,
4888{
4889 /// Perform the operation you have build so far.
4890 pub async fn doit(
4891 mut self,
4892 ) -> common::Result<(
4893 common::Response,
4894 GoogleCloudOrgpolicyV2ListCustomConstraintsResponse,
4895 )> {
4896 use std::borrow::Cow;
4897 use std::io::{Read, Seek};
4898
4899 use common::{url::Params, ToParts};
4900 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
4901
4902 let mut dd = common::DefaultDelegate;
4903 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
4904 dlg.begin(common::MethodInfo {
4905 id: "orgpolicy.organizations.customConstraints.list",
4906 http_method: hyper::Method::GET,
4907 });
4908
4909 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
4910 if self._additional_params.contains_key(field) {
4911 dlg.finished(false);
4912 return Err(common::Error::FieldClash(field));
4913 }
4914 }
4915
4916 let mut params = Params::with_capacity(5 + self._additional_params.len());
4917 params.push("parent", self._parent);
4918 if let Some(value) = self._page_token.as_ref() {
4919 params.push("pageToken", value);
4920 }
4921 if let Some(value) = self._page_size.as_ref() {
4922 params.push("pageSize", value.to_string());
4923 }
4924
4925 params.extend(self._additional_params.iter());
4926
4927 params.push("alt", "json");
4928 let mut url = self.hub._base_url.clone() + "v2/{+parent}/customConstraints";
4929 if self._scopes.is_empty() {
4930 self._scopes
4931 .insert(Scope::CloudPlatform.as_ref().to_string());
4932 }
4933
4934 #[allow(clippy::single_element_loop)]
4935 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
4936 url = params.uri_replacement(url, param_name, find_this, true);
4937 }
4938 {
4939 let to_remove = ["parent"];
4940 params.remove_params(&to_remove);
4941 }
4942
4943 let url = params.parse_with_url(&url);
4944
4945 loop {
4946 let token = match self
4947 .hub
4948 .auth
4949 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
4950 .await
4951 {
4952 Ok(token) => token,
4953 Err(e) => match dlg.token(e) {
4954 Ok(token) => token,
4955 Err(e) => {
4956 dlg.finished(false);
4957 return Err(common::Error::MissingToken(e));
4958 }
4959 },
4960 };
4961 let mut req_result = {
4962 let client = &self.hub.client;
4963 dlg.pre_request();
4964 let mut req_builder = hyper::Request::builder()
4965 .method(hyper::Method::GET)
4966 .uri(url.as_str())
4967 .header(USER_AGENT, self.hub._user_agent.clone());
4968
4969 if let Some(token) = token.as_ref() {
4970 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
4971 }
4972
4973 let request = req_builder
4974 .header(CONTENT_LENGTH, 0_u64)
4975 .body(common::to_body::<String>(None));
4976
4977 client.request(request.unwrap()).await
4978 };
4979
4980 match req_result {
4981 Err(err) => {
4982 if let common::Retry::After(d) = dlg.http_error(&err) {
4983 sleep(d).await;
4984 continue;
4985 }
4986 dlg.finished(false);
4987 return Err(common::Error::HttpError(err));
4988 }
4989 Ok(res) => {
4990 let (mut parts, body) = res.into_parts();
4991 let mut body = common::Body::new(body);
4992 if !parts.status.is_success() {
4993 let bytes = common::to_bytes(body).await.unwrap_or_default();
4994 let error = serde_json::from_str(&common::to_string(&bytes));
4995 let response = common::to_response(parts, bytes.into());
4996
4997 if let common::Retry::After(d) =
4998 dlg.http_failure(&response, error.as_ref().ok())
4999 {
5000 sleep(d).await;
5001 continue;
5002 }
5003
5004 dlg.finished(false);
5005
5006 return Err(match error {
5007 Ok(value) => common::Error::BadRequest(value),
5008 _ => common::Error::Failure(response),
5009 });
5010 }
5011 let response = {
5012 let bytes = common::to_bytes(body).await.unwrap_or_default();
5013 let encoded = common::to_string(&bytes);
5014 match serde_json::from_str(&encoded) {
5015 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
5016 Err(error) => {
5017 dlg.response_json_decode_error(&encoded, &error);
5018 return Err(common::Error::JsonDecodeError(
5019 encoded.to_string(),
5020 error,
5021 ));
5022 }
5023 }
5024 };
5025
5026 dlg.finished(true);
5027 return Ok(response);
5028 }
5029 }
5030 }
5031 }
5032
5033 /// Required. The target Google Cloud resource that parents the set of custom constraints that will be returned from this call. Must be in one of the following forms: * `organizations/{organization_id}`
5034 ///
5035 /// Sets the *parent* path property to the given value.
5036 ///
5037 /// Even though the property as already been set when instantiating this call,
5038 /// we provide this method for API completeness.
5039 pub fn parent(mut self, new_value: &str) -> OrganizationCustomConstraintListCall<'a, C> {
5040 self._parent = new_value.to_string();
5041 self
5042 }
5043 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
5044 ///
5045 /// Sets the *page token* query property to the given value.
5046 pub fn page_token(mut self, new_value: &str) -> OrganizationCustomConstraintListCall<'a, C> {
5047 self._page_token = Some(new_value.to_string());
5048 self
5049 }
5050 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
5051 ///
5052 /// Sets the *page size* query property to the given value.
5053 pub fn page_size(mut self, new_value: i32) -> OrganizationCustomConstraintListCall<'a, C> {
5054 self._page_size = Some(new_value);
5055 self
5056 }
5057 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
5058 /// while executing the actual API request.
5059 ///
5060 /// ````text
5061 /// It should be used to handle progress information, and to implement a certain level of resilience.
5062 /// ````
5063 ///
5064 /// Sets the *delegate* property to the given value.
5065 pub fn delegate(
5066 mut self,
5067 new_value: &'a mut dyn common::Delegate,
5068 ) -> OrganizationCustomConstraintListCall<'a, C> {
5069 self._delegate = Some(new_value);
5070 self
5071 }
5072
5073 /// Set any additional parameter of the query string used in the request.
5074 /// It should be used to set parameters which are not yet available through their own
5075 /// setters.
5076 ///
5077 /// Please note that this method must not be used to set any of the known parameters
5078 /// which have their own setter method. If done anyway, the request will fail.
5079 ///
5080 /// # Additional Parameters
5081 ///
5082 /// * *$.xgafv* (query-string) - V1 error format.
5083 /// * *access_token* (query-string) - OAuth access token.
5084 /// * *alt* (query-string) - Data format for response.
5085 /// * *callback* (query-string) - JSONP
5086 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
5087 /// * *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.
5088 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
5089 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
5090 /// * *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.
5091 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
5092 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
5093 pub fn param<T>(mut self, name: T, value: T) -> OrganizationCustomConstraintListCall<'a, C>
5094 where
5095 T: AsRef<str>,
5096 {
5097 self._additional_params
5098 .insert(name.as_ref().to_string(), value.as_ref().to_string());
5099 self
5100 }
5101
5102 /// Identifies the authorization scope for the method you are building.
5103 ///
5104 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
5105 /// [`Scope::CloudPlatform`].
5106 ///
5107 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
5108 /// tokens for more than one scope.
5109 ///
5110 /// Usually there is more than one suitable scope to authorize an operation, some of which may
5111 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
5112 /// sufficient, a read-write scope will do as well.
5113 pub fn add_scope<St>(mut self, scope: St) -> OrganizationCustomConstraintListCall<'a, C>
5114 where
5115 St: AsRef<str>,
5116 {
5117 self._scopes.insert(String::from(scope.as_ref()));
5118 self
5119 }
5120 /// Identifies the authorization scope(s) for the method you are building.
5121 ///
5122 /// See [`Self::add_scope()`] for details.
5123 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationCustomConstraintListCall<'a, C>
5124 where
5125 I: IntoIterator<Item = St>,
5126 St: AsRef<str>,
5127 {
5128 self._scopes
5129 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
5130 self
5131 }
5132
5133 /// Removes all scopes, and no default scope will be used either.
5134 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
5135 /// for details).
5136 pub fn clear_scopes(mut self) -> OrganizationCustomConstraintListCall<'a, C> {
5137 self._scopes.clear();
5138 self
5139 }
5140}
5141
5142/// Updates a custom constraint. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Note: the supplied policy will perform a full overwrite of all fields.
5143///
5144/// A builder for the *customConstraints.patch* method supported by a *organization* resource.
5145/// It is not used directly, but through a [`OrganizationMethods`] instance.
5146///
5147/// # Example
5148///
5149/// Instantiate a resource method builder
5150///
5151/// ```test_harness,no_run
5152/// # extern crate hyper;
5153/// # extern crate hyper_rustls;
5154/// # extern crate google_orgpolicy2 as orgpolicy2;
5155/// use orgpolicy2::api::GoogleCloudOrgpolicyV2CustomConstraint;
5156/// # async fn dox() {
5157/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
5158///
5159/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
5160/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
5161/// # .with_native_roots()
5162/// # .unwrap()
5163/// # .https_only()
5164/// # .enable_http2()
5165/// # .build();
5166///
5167/// # let executor = hyper_util::rt::TokioExecutor::new();
5168/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
5169/// # secret,
5170/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
5171/// # yup_oauth2::client::CustomHyperClientBuilder::from(
5172/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
5173/// # ),
5174/// # ).build().await.unwrap();
5175///
5176/// # let client = hyper_util::client::legacy::Client::builder(
5177/// # hyper_util::rt::TokioExecutor::new()
5178/// # )
5179/// # .build(
5180/// # hyper_rustls::HttpsConnectorBuilder::new()
5181/// # .with_native_roots()
5182/// # .unwrap()
5183/// # .https_or_http()
5184/// # .enable_http2()
5185/// # .build()
5186/// # );
5187/// # let mut hub = OrgPolicyAPI::new(client, auth);
5188/// // As the method needs a request, you would usually fill it with the desired information
5189/// // into the respective structure. Some of the parts shown here might not be applicable !
5190/// // Values shown here are possibly random and not representative !
5191/// let mut req = GoogleCloudOrgpolicyV2CustomConstraint::default();
5192///
5193/// // You can configure optional parameters by calling the respective setters at will, and
5194/// // execute the final call using `doit()`.
5195/// // Values shown here are possibly random and not representative !
5196/// let result = hub.organizations().custom_constraints_patch(req, "name")
5197/// .doit().await;
5198/// # }
5199/// ```
5200pub struct OrganizationCustomConstraintPatchCall<'a, C>
5201where
5202 C: 'a,
5203{
5204 hub: &'a OrgPolicyAPI<C>,
5205 _request: GoogleCloudOrgpolicyV2CustomConstraint,
5206 _name: String,
5207 _delegate: Option<&'a mut dyn common::Delegate>,
5208 _additional_params: HashMap<String, String>,
5209 _scopes: BTreeSet<String>,
5210}
5211
5212impl<'a, C> common::CallBuilder for OrganizationCustomConstraintPatchCall<'a, C> {}
5213
5214impl<'a, C> OrganizationCustomConstraintPatchCall<'a, C>
5215where
5216 C: common::Connector,
5217{
5218 /// Perform the operation you have build so far.
5219 pub async fn doit(
5220 mut self,
5221 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2CustomConstraint)> {
5222 use std::borrow::Cow;
5223 use std::io::{Read, Seek};
5224
5225 use common::{url::Params, ToParts};
5226 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
5227
5228 let mut dd = common::DefaultDelegate;
5229 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
5230 dlg.begin(common::MethodInfo {
5231 id: "orgpolicy.organizations.customConstraints.patch",
5232 http_method: hyper::Method::PATCH,
5233 });
5234
5235 for &field in ["alt", "name"].iter() {
5236 if self._additional_params.contains_key(field) {
5237 dlg.finished(false);
5238 return Err(common::Error::FieldClash(field));
5239 }
5240 }
5241
5242 let mut params = Params::with_capacity(4 + self._additional_params.len());
5243 params.push("name", self._name);
5244
5245 params.extend(self._additional_params.iter());
5246
5247 params.push("alt", "json");
5248 let mut url = self.hub._base_url.clone() + "v2/{+name}";
5249 if self._scopes.is_empty() {
5250 self._scopes
5251 .insert(Scope::CloudPlatform.as_ref().to_string());
5252 }
5253
5254 #[allow(clippy::single_element_loop)]
5255 for &(find_this, param_name) in [("{+name}", "name")].iter() {
5256 url = params.uri_replacement(url, param_name, find_this, true);
5257 }
5258 {
5259 let to_remove = ["name"];
5260 params.remove_params(&to_remove);
5261 }
5262
5263 let url = params.parse_with_url(&url);
5264
5265 let mut json_mime_type = mime::APPLICATION_JSON;
5266 let mut request_value_reader = {
5267 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
5268 common::remove_json_null_values(&mut value);
5269 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
5270 serde_json::to_writer(&mut dst, &value).unwrap();
5271 dst
5272 };
5273 let request_size = request_value_reader
5274 .seek(std::io::SeekFrom::End(0))
5275 .unwrap();
5276 request_value_reader
5277 .seek(std::io::SeekFrom::Start(0))
5278 .unwrap();
5279
5280 loop {
5281 let token = match self
5282 .hub
5283 .auth
5284 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
5285 .await
5286 {
5287 Ok(token) => token,
5288 Err(e) => match dlg.token(e) {
5289 Ok(token) => token,
5290 Err(e) => {
5291 dlg.finished(false);
5292 return Err(common::Error::MissingToken(e));
5293 }
5294 },
5295 };
5296 request_value_reader
5297 .seek(std::io::SeekFrom::Start(0))
5298 .unwrap();
5299 let mut req_result = {
5300 let client = &self.hub.client;
5301 dlg.pre_request();
5302 let mut req_builder = hyper::Request::builder()
5303 .method(hyper::Method::PATCH)
5304 .uri(url.as_str())
5305 .header(USER_AGENT, self.hub._user_agent.clone());
5306
5307 if let Some(token) = token.as_ref() {
5308 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
5309 }
5310
5311 let request = req_builder
5312 .header(CONTENT_TYPE, json_mime_type.to_string())
5313 .header(CONTENT_LENGTH, request_size as u64)
5314 .body(common::to_body(
5315 request_value_reader.get_ref().clone().into(),
5316 ));
5317
5318 client.request(request.unwrap()).await
5319 };
5320
5321 match req_result {
5322 Err(err) => {
5323 if let common::Retry::After(d) = dlg.http_error(&err) {
5324 sleep(d).await;
5325 continue;
5326 }
5327 dlg.finished(false);
5328 return Err(common::Error::HttpError(err));
5329 }
5330 Ok(res) => {
5331 let (mut parts, body) = res.into_parts();
5332 let mut body = common::Body::new(body);
5333 if !parts.status.is_success() {
5334 let bytes = common::to_bytes(body).await.unwrap_or_default();
5335 let error = serde_json::from_str(&common::to_string(&bytes));
5336 let response = common::to_response(parts, bytes.into());
5337
5338 if let common::Retry::After(d) =
5339 dlg.http_failure(&response, error.as_ref().ok())
5340 {
5341 sleep(d).await;
5342 continue;
5343 }
5344
5345 dlg.finished(false);
5346
5347 return Err(match error {
5348 Ok(value) => common::Error::BadRequest(value),
5349 _ => common::Error::Failure(response),
5350 });
5351 }
5352 let response = {
5353 let bytes = common::to_bytes(body).await.unwrap_or_default();
5354 let encoded = common::to_string(&bytes);
5355 match serde_json::from_str(&encoded) {
5356 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
5357 Err(error) => {
5358 dlg.response_json_decode_error(&encoded, &error);
5359 return Err(common::Error::JsonDecodeError(
5360 encoded.to_string(),
5361 error,
5362 ));
5363 }
5364 }
5365 };
5366
5367 dlg.finished(true);
5368 return Ok(response);
5369 }
5370 }
5371 }
5372 }
5373
5374 ///
5375 /// Sets the *request* property to the given value.
5376 ///
5377 /// Even though the property as already been set when instantiating this call,
5378 /// we provide this method for API completeness.
5379 pub fn request(
5380 mut self,
5381 new_value: GoogleCloudOrgpolicyV2CustomConstraint,
5382 ) -> OrganizationCustomConstraintPatchCall<'a, C> {
5383 self._request = new_value;
5384 self
5385 }
5386 /// Immutable. Name of the constraint. This is unique within the organization. Format of the name should be * `organizations/{organization_id}/customConstraints/{custom_constraint_id}` Example: `organizations/123/customConstraints/custom.createOnlyE2TypeVms` The max length is 70 characters and the minimum length is 1. Note that the prefix `organizations/{organization_id}/customConstraints/` is not counted.
5387 ///
5388 /// Sets the *name* path property to the given value.
5389 ///
5390 /// Even though the property as already been set when instantiating this call,
5391 /// we provide this method for API completeness.
5392 pub fn name(mut self, new_value: &str) -> OrganizationCustomConstraintPatchCall<'a, C> {
5393 self._name = new_value.to_string();
5394 self
5395 }
5396 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
5397 /// while executing the actual API request.
5398 ///
5399 /// ````text
5400 /// It should be used to handle progress information, and to implement a certain level of resilience.
5401 /// ````
5402 ///
5403 /// Sets the *delegate* property to the given value.
5404 pub fn delegate(
5405 mut self,
5406 new_value: &'a mut dyn common::Delegate,
5407 ) -> OrganizationCustomConstraintPatchCall<'a, C> {
5408 self._delegate = Some(new_value);
5409 self
5410 }
5411
5412 /// Set any additional parameter of the query string used in the request.
5413 /// It should be used to set parameters which are not yet available through their own
5414 /// setters.
5415 ///
5416 /// Please note that this method must not be used to set any of the known parameters
5417 /// which have their own setter method. If done anyway, the request will fail.
5418 ///
5419 /// # Additional Parameters
5420 ///
5421 /// * *$.xgafv* (query-string) - V1 error format.
5422 /// * *access_token* (query-string) - OAuth access token.
5423 /// * *alt* (query-string) - Data format for response.
5424 /// * *callback* (query-string) - JSONP
5425 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
5426 /// * *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.
5427 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
5428 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
5429 /// * *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.
5430 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
5431 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
5432 pub fn param<T>(mut self, name: T, value: T) -> OrganizationCustomConstraintPatchCall<'a, C>
5433 where
5434 T: AsRef<str>,
5435 {
5436 self._additional_params
5437 .insert(name.as_ref().to_string(), value.as_ref().to_string());
5438 self
5439 }
5440
5441 /// Identifies the authorization scope for the method you are building.
5442 ///
5443 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
5444 /// [`Scope::CloudPlatform`].
5445 ///
5446 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
5447 /// tokens for more than one scope.
5448 ///
5449 /// Usually there is more than one suitable scope to authorize an operation, some of which may
5450 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
5451 /// sufficient, a read-write scope will do as well.
5452 pub fn add_scope<St>(mut self, scope: St) -> OrganizationCustomConstraintPatchCall<'a, C>
5453 where
5454 St: AsRef<str>,
5455 {
5456 self._scopes.insert(String::from(scope.as_ref()));
5457 self
5458 }
5459 /// Identifies the authorization scope(s) for the method you are building.
5460 ///
5461 /// See [`Self::add_scope()`] for details.
5462 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationCustomConstraintPatchCall<'a, C>
5463 where
5464 I: IntoIterator<Item = St>,
5465 St: AsRef<str>,
5466 {
5467 self._scopes
5468 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
5469 self
5470 }
5471
5472 /// Removes all scopes, and no default scope will be used either.
5473 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
5474 /// for details).
5475 pub fn clear_scopes(mut self) -> OrganizationCustomConstraintPatchCall<'a, C> {
5476 self._scopes.clear();
5477 self
5478 }
5479}
5480
5481/// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
5482///
5483/// A builder for the *policies.create* method supported by a *organization* resource.
5484/// It is not used directly, but through a [`OrganizationMethods`] instance.
5485///
5486/// # Example
5487///
5488/// Instantiate a resource method builder
5489///
5490/// ```test_harness,no_run
5491/// # extern crate hyper;
5492/// # extern crate hyper_rustls;
5493/// # extern crate google_orgpolicy2 as orgpolicy2;
5494/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
5495/// # async fn dox() {
5496/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
5497///
5498/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
5499/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
5500/// # .with_native_roots()
5501/// # .unwrap()
5502/// # .https_only()
5503/// # .enable_http2()
5504/// # .build();
5505///
5506/// # let executor = hyper_util::rt::TokioExecutor::new();
5507/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
5508/// # secret,
5509/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
5510/// # yup_oauth2::client::CustomHyperClientBuilder::from(
5511/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
5512/// # ),
5513/// # ).build().await.unwrap();
5514///
5515/// # let client = hyper_util::client::legacy::Client::builder(
5516/// # hyper_util::rt::TokioExecutor::new()
5517/// # )
5518/// # .build(
5519/// # hyper_rustls::HttpsConnectorBuilder::new()
5520/// # .with_native_roots()
5521/// # .unwrap()
5522/// # .https_or_http()
5523/// # .enable_http2()
5524/// # .build()
5525/// # );
5526/// # let mut hub = OrgPolicyAPI::new(client, auth);
5527/// // As the method needs a request, you would usually fill it with the desired information
5528/// // into the respective structure. Some of the parts shown here might not be applicable !
5529/// // Values shown here are possibly random and not representative !
5530/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
5531///
5532/// // You can configure optional parameters by calling the respective setters at will, and
5533/// // execute the final call using `doit()`.
5534/// // Values shown here are possibly random and not representative !
5535/// let result = hub.organizations().policies_create(req, "parent")
5536/// .doit().await;
5537/// # }
5538/// ```
5539pub struct OrganizationPolicyCreateCall<'a, C>
5540where
5541 C: 'a,
5542{
5543 hub: &'a OrgPolicyAPI<C>,
5544 _request: GoogleCloudOrgpolicyV2Policy,
5545 _parent: String,
5546 _delegate: Option<&'a mut dyn common::Delegate>,
5547 _additional_params: HashMap<String, String>,
5548 _scopes: BTreeSet<String>,
5549}
5550
5551impl<'a, C> common::CallBuilder for OrganizationPolicyCreateCall<'a, C> {}
5552
5553impl<'a, C> OrganizationPolicyCreateCall<'a, C>
5554where
5555 C: common::Connector,
5556{
5557 /// Perform the operation you have build so far.
5558 pub async fn doit(
5559 mut self,
5560 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
5561 use std::borrow::Cow;
5562 use std::io::{Read, Seek};
5563
5564 use common::{url::Params, ToParts};
5565 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
5566
5567 let mut dd = common::DefaultDelegate;
5568 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
5569 dlg.begin(common::MethodInfo {
5570 id: "orgpolicy.organizations.policies.create",
5571 http_method: hyper::Method::POST,
5572 });
5573
5574 for &field in ["alt", "parent"].iter() {
5575 if self._additional_params.contains_key(field) {
5576 dlg.finished(false);
5577 return Err(common::Error::FieldClash(field));
5578 }
5579 }
5580
5581 let mut params = Params::with_capacity(4 + self._additional_params.len());
5582 params.push("parent", self._parent);
5583
5584 params.extend(self._additional_params.iter());
5585
5586 params.push("alt", "json");
5587 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
5588 if self._scopes.is_empty() {
5589 self._scopes
5590 .insert(Scope::CloudPlatform.as_ref().to_string());
5591 }
5592
5593 #[allow(clippy::single_element_loop)]
5594 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
5595 url = params.uri_replacement(url, param_name, find_this, true);
5596 }
5597 {
5598 let to_remove = ["parent"];
5599 params.remove_params(&to_remove);
5600 }
5601
5602 let url = params.parse_with_url(&url);
5603
5604 let mut json_mime_type = mime::APPLICATION_JSON;
5605 let mut request_value_reader = {
5606 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
5607 common::remove_json_null_values(&mut value);
5608 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
5609 serde_json::to_writer(&mut dst, &value).unwrap();
5610 dst
5611 };
5612 let request_size = request_value_reader
5613 .seek(std::io::SeekFrom::End(0))
5614 .unwrap();
5615 request_value_reader
5616 .seek(std::io::SeekFrom::Start(0))
5617 .unwrap();
5618
5619 loop {
5620 let token = match self
5621 .hub
5622 .auth
5623 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
5624 .await
5625 {
5626 Ok(token) => token,
5627 Err(e) => match dlg.token(e) {
5628 Ok(token) => token,
5629 Err(e) => {
5630 dlg.finished(false);
5631 return Err(common::Error::MissingToken(e));
5632 }
5633 },
5634 };
5635 request_value_reader
5636 .seek(std::io::SeekFrom::Start(0))
5637 .unwrap();
5638 let mut req_result = {
5639 let client = &self.hub.client;
5640 dlg.pre_request();
5641 let mut req_builder = hyper::Request::builder()
5642 .method(hyper::Method::POST)
5643 .uri(url.as_str())
5644 .header(USER_AGENT, self.hub._user_agent.clone());
5645
5646 if let Some(token) = token.as_ref() {
5647 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
5648 }
5649
5650 let request = req_builder
5651 .header(CONTENT_TYPE, json_mime_type.to_string())
5652 .header(CONTENT_LENGTH, request_size as u64)
5653 .body(common::to_body(
5654 request_value_reader.get_ref().clone().into(),
5655 ));
5656
5657 client.request(request.unwrap()).await
5658 };
5659
5660 match req_result {
5661 Err(err) => {
5662 if let common::Retry::After(d) = dlg.http_error(&err) {
5663 sleep(d).await;
5664 continue;
5665 }
5666 dlg.finished(false);
5667 return Err(common::Error::HttpError(err));
5668 }
5669 Ok(res) => {
5670 let (mut parts, body) = res.into_parts();
5671 let mut body = common::Body::new(body);
5672 if !parts.status.is_success() {
5673 let bytes = common::to_bytes(body).await.unwrap_or_default();
5674 let error = serde_json::from_str(&common::to_string(&bytes));
5675 let response = common::to_response(parts, bytes.into());
5676
5677 if let common::Retry::After(d) =
5678 dlg.http_failure(&response, error.as_ref().ok())
5679 {
5680 sleep(d).await;
5681 continue;
5682 }
5683
5684 dlg.finished(false);
5685
5686 return Err(match error {
5687 Ok(value) => common::Error::BadRequest(value),
5688 _ => common::Error::Failure(response),
5689 });
5690 }
5691 let response = {
5692 let bytes = common::to_bytes(body).await.unwrap_or_default();
5693 let encoded = common::to_string(&bytes);
5694 match serde_json::from_str(&encoded) {
5695 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
5696 Err(error) => {
5697 dlg.response_json_decode_error(&encoded, &error);
5698 return Err(common::Error::JsonDecodeError(
5699 encoded.to_string(),
5700 error,
5701 ));
5702 }
5703 }
5704 };
5705
5706 dlg.finished(true);
5707 return Ok(response);
5708 }
5709 }
5710 }
5711 }
5712
5713 ///
5714 /// Sets the *request* property to the given value.
5715 ///
5716 /// Even though the property as already been set when instantiating this call,
5717 /// we provide this method for API completeness.
5718 pub fn request(
5719 mut self,
5720 new_value: GoogleCloudOrgpolicyV2Policy,
5721 ) -> OrganizationPolicyCreateCall<'a, C> {
5722 self._request = new_value;
5723 self
5724 }
5725 /// Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
5726 ///
5727 /// Sets the *parent* path property to the given value.
5728 ///
5729 /// Even though the property as already been set when instantiating this call,
5730 /// we provide this method for API completeness.
5731 pub fn parent(mut self, new_value: &str) -> OrganizationPolicyCreateCall<'a, C> {
5732 self._parent = new_value.to_string();
5733 self
5734 }
5735 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
5736 /// while executing the actual API request.
5737 ///
5738 /// ````text
5739 /// It should be used to handle progress information, and to implement a certain level of resilience.
5740 /// ````
5741 ///
5742 /// Sets the *delegate* property to the given value.
5743 pub fn delegate(
5744 mut self,
5745 new_value: &'a mut dyn common::Delegate,
5746 ) -> OrganizationPolicyCreateCall<'a, C> {
5747 self._delegate = Some(new_value);
5748 self
5749 }
5750
5751 /// Set any additional parameter of the query string used in the request.
5752 /// It should be used to set parameters which are not yet available through their own
5753 /// setters.
5754 ///
5755 /// Please note that this method must not be used to set any of the known parameters
5756 /// which have their own setter method. If done anyway, the request will fail.
5757 ///
5758 /// # Additional Parameters
5759 ///
5760 /// * *$.xgafv* (query-string) - V1 error format.
5761 /// * *access_token* (query-string) - OAuth access token.
5762 /// * *alt* (query-string) - Data format for response.
5763 /// * *callback* (query-string) - JSONP
5764 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
5765 /// * *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.
5766 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
5767 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
5768 /// * *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.
5769 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
5770 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
5771 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyCreateCall<'a, C>
5772 where
5773 T: AsRef<str>,
5774 {
5775 self._additional_params
5776 .insert(name.as_ref().to_string(), value.as_ref().to_string());
5777 self
5778 }
5779
5780 /// Identifies the authorization scope for the method you are building.
5781 ///
5782 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
5783 /// [`Scope::CloudPlatform`].
5784 ///
5785 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
5786 /// tokens for more than one scope.
5787 ///
5788 /// Usually there is more than one suitable scope to authorize an operation, some of which may
5789 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
5790 /// sufficient, a read-write scope will do as well.
5791 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyCreateCall<'a, C>
5792 where
5793 St: AsRef<str>,
5794 {
5795 self._scopes.insert(String::from(scope.as_ref()));
5796 self
5797 }
5798 /// Identifies the authorization scope(s) for the method you are building.
5799 ///
5800 /// See [`Self::add_scope()`] for details.
5801 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyCreateCall<'a, C>
5802 where
5803 I: IntoIterator<Item = St>,
5804 St: AsRef<str>,
5805 {
5806 self._scopes
5807 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
5808 self
5809 }
5810
5811 /// Removes all scopes, and no default scope will be used either.
5812 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
5813 /// for details).
5814 pub fn clear_scopes(mut self) -> OrganizationPolicyCreateCall<'a, C> {
5815 self._scopes.clear();
5816 self
5817 }
5818}
5819
5820/// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
5821///
5822/// A builder for the *policies.delete* method supported by a *organization* resource.
5823/// It is not used directly, but through a [`OrganizationMethods`] instance.
5824///
5825/// # Example
5826///
5827/// Instantiate a resource method builder
5828///
5829/// ```test_harness,no_run
5830/// # extern crate hyper;
5831/// # extern crate hyper_rustls;
5832/// # extern crate google_orgpolicy2 as orgpolicy2;
5833/// # async fn dox() {
5834/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
5835///
5836/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
5837/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
5838/// # .with_native_roots()
5839/// # .unwrap()
5840/// # .https_only()
5841/// # .enable_http2()
5842/// # .build();
5843///
5844/// # let executor = hyper_util::rt::TokioExecutor::new();
5845/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
5846/// # secret,
5847/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
5848/// # yup_oauth2::client::CustomHyperClientBuilder::from(
5849/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
5850/// # ),
5851/// # ).build().await.unwrap();
5852///
5853/// # let client = hyper_util::client::legacy::Client::builder(
5854/// # hyper_util::rt::TokioExecutor::new()
5855/// # )
5856/// # .build(
5857/// # hyper_rustls::HttpsConnectorBuilder::new()
5858/// # .with_native_roots()
5859/// # .unwrap()
5860/// # .https_or_http()
5861/// # .enable_http2()
5862/// # .build()
5863/// # );
5864/// # let mut hub = OrgPolicyAPI::new(client, auth);
5865/// // You can configure optional parameters by calling the respective setters at will, and
5866/// // execute the final call using `doit()`.
5867/// // Values shown here are possibly random and not representative !
5868/// let result = hub.organizations().policies_delete("name")
5869/// .etag("rebum.")
5870/// .doit().await;
5871/// # }
5872/// ```
5873pub struct OrganizationPolicyDeleteCall<'a, C>
5874where
5875 C: 'a,
5876{
5877 hub: &'a OrgPolicyAPI<C>,
5878 _name: String,
5879 _etag: Option<String>,
5880 _delegate: Option<&'a mut dyn common::Delegate>,
5881 _additional_params: HashMap<String, String>,
5882 _scopes: BTreeSet<String>,
5883}
5884
5885impl<'a, C> common::CallBuilder for OrganizationPolicyDeleteCall<'a, C> {}
5886
5887impl<'a, C> OrganizationPolicyDeleteCall<'a, C>
5888where
5889 C: common::Connector,
5890{
5891 /// Perform the operation you have build so far.
5892 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleProtobufEmpty)> {
5893 use std::borrow::Cow;
5894 use std::io::{Read, Seek};
5895
5896 use common::{url::Params, ToParts};
5897 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
5898
5899 let mut dd = common::DefaultDelegate;
5900 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
5901 dlg.begin(common::MethodInfo {
5902 id: "orgpolicy.organizations.policies.delete",
5903 http_method: hyper::Method::DELETE,
5904 });
5905
5906 for &field in ["alt", "name", "etag"].iter() {
5907 if self._additional_params.contains_key(field) {
5908 dlg.finished(false);
5909 return Err(common::Error::FieldClash(field));
5910 }
5911 }
5912
5913 let mut params = Params::with_capacity(4 + self._additional_params.len());
5914 params.push("name", self._name);
5915 if let Some(value) = self._etag.as_ref() {
5916 params.push("etag", value);
5917 }
5918
5919 params.extend(self._additional_params.iter());
5920
5921 params.push("alt", "json");
5922 let mut url = self.hub._base_url.clone() + "v2/{+name}";
5923 if self._scopes.is_empty() {
5924 self._scopes
5925 .insert(Scope::CloudPlatform.as_ref().to_string());
5926 }
5927
5928 #[allow(clippy::single_element_loop)]
5929 for &(find_this, param_name) in [("{+name}", "name")].iter() {
5930 url = params.uri_replacement(url, param_name, find_this, true);
5931 }
5932 {
5933 let to_remove = ["name"];
5934 params.remove_params(&to_remove);
5935 }
5936
5937 let url = params.parse_with_url(&url);
5938
5939 loop {
5940 let token = match self
5941 .hub
5942 .auth
5943 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
5944 .await
5945 {
5946 Ok(token) => token,
5947 Err(e) => match dlg.token(e) {
5948 Ok(token) => token,
5949 Err(e) => {
5950 dlg.finished(false);
5951 return Err(common::Error::MissingToken(e));
5952 }
5953 },
5954 };
5955 let mut req_result = {
5956 let client = &self.hub.client;
5957 dlg.pre_request();
5958 let mut req_builder = hyper::Request::builder()
5959 .method(hyper::Method::DELETE)
5960 .uri(url.as_str())
5961 .header(USER_AGENT, self.hub._user_agent.clone());
5962
5963 if let Some(token) = token.as_ref() {
5964 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
5965 }
5966
5967 let request = req_builder
5968 .header(CONTENT_LENGTH, 0_u64)
5969 .body(common::to_body::<String>(None));
5970
5971 client.request(request.unwrap()).await
5972 };
5973
5974 match req_result {
5975 Err(err) => {
5976 if let common::Retry::After(d) = dlg.http_error(&err) {
5977 sleep(d).await;
5978 continue;
5979 }
5980 dlg.finished(false);
5981 return Err(common::Error::HttpError(err));
5982 }
5983 Ok(res) => {
5984 let (mut parts, body) = res.into_parts();
5985 let mut body = common::Body::new(body);
5986 if !parts.status.is_success() {
5987 let bytes = common::to_bytes(body).await.unwrap_or_default();
5988 let error = serde_json::from_str(&common::to_string(&bytes));
5989 let response = common::to_response(parts, bytes.into());
5990
5991 if let common::Retry::After(d) =
5992 dlg.http_failure(&response, error.as_ref().ok())
5993 {
5994 sleep(d).await;
5995 continue;
5996 }
5997
5998 dlg.finished(false);
5999
6000 return Err(match error {
6001 Ok(value) => common::Error::BadRequest(value),
6002 _ => common::Error::Failure(response),
6003 });
6004 }
6005 let response = {
6006 let bytes = common::to_bytes(body).await.unwrap_or_default();
6007 let encoded = common::to_string(&bytes);
6008 match serde_json::from_str(&encoded) {
6009 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
6010 Err(error) => {
6011 dlg.response_json_decode_error(&encoded, &error);
6012 return Err(common::Error::JsonDecodeError(
6013 encoded.to_string(),
6014 error,
6015 ));
6016 }
6017 }
6018 };
6019
6020 dlg.finished(true);
6021 return Ok(response);
6022 }
6023 }
6024 }
6025 }
6026
6027 /// Required. Name of the policy to delete. See the policy entry for naming rules.
6028 ///
6029 /// Sets the *name* path property to the given value.
6030 ///
6031 /// Even though the property as already been set when instantiating this call,
6032 /// we provide this method for API completeness.
6033 pub fn name(mut self, new_value: &str) -> OrganizationPolicyDeleteCall<'a, C> {
6034 self._name = new_value.to_string();
6035 self
6036 }
6037 /// Optional. The current etag of policy. If an etag is provided and does not match the current etag of the policy, deletion will be blocked and an ABORTED error will be returned.
6038 ///
6039 /// Sets the *etag* query property to the given value.
6040 pub fn etag(mut self, new_value: &str) -> OrganizationPolicyDeleteCall<'a, C> {
6041 self._etag = Some(new_value.to_string());
6042 self
6043 }
6044 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
6045 /// while executing the actual API request.
6046 ///
6047 /// ````text
6048 /// It should be used to handle progress information, and to implement a certain level of resilience.
6049 /// ````
6050 ///
6051 /// Sets the *delegate* property to the given value.
6052 pub fn delegate(
6053 mut self,
6054 new_value: &'a mut dyn common::Delegate,
6055 ) -> OrganizationPolicyDeleteCall<'a, C> {
6056 self._delegate = Some(new_value);
6057 self
6058 }
6059
6060 /// Set any additional parameter of the query string used in the request.
6061 /// It should be used to set parameters which are not yet available through their own
6062 /// setters.
6063 ///
6064 /// Please note that this method must not be used to set any of the known parameters
6065 /// which have their own setter method. If done anyway, the request will fail.
6066 ///
6067 /// # Additional Parameters
6068 ///
6069 /// * *$.xgafv* (query-string) - V1 error format.
6070 /// * *access_token* (query-string) - OAuth access token.
6071 /// * *alt* (query-string) - Data format for response.
6072 /// * *callback* (query-string) - JSONP
6073 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
6074 /// * *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.
6075 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
6076 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
6077 /// * *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.
6078 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
6079 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
6080 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyDeleteCall<'a, C>
6081 where
6082 T: AsRef<str>,
6083 {
6084 self._additional_params
6085 .insert(name.as_ref().to_string(), value.as_ref().to_string());
6086 self
6087 }
6088
6089 /// Identifies the authorization scope for the method you are building.
6090 ///
6091 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
6092 /// [`Scope::CloudPlatform`].
6093 ///
6094 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
6095 /// tokens for more than one scope.
6096 ///
6097 /// Usually there is more than one suitable scope to authorize an operation, some of which may
6098 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
6099 /// sufficient, a read-write scope will do as well.
6100 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyDeleteCall<'a, C>
6101 where
6102 St: AsRef<str>,
6103 {
6104 self._scopes.insert(String::from(scope.as_ref()));
6105 self
6106 }
6107 /// Identifies the authorization scope(s) for the method you are building.
6108 ///
6109 /// See [`Self::add_scope()`] for details.
6110 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyDeleteCall<'a, C>
6111 where
6112 I: IntoIterator<Item = St>,
6113 St: AsRef<str>,
6114 {
6115 self._scopes
6116 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
6117 self
6118 }
6119
6120 /// Removes all scopes, and no default scope will be used either.
6121 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
6122 /// for details).
6123 pub fn clear_scopes(mut self) -> OrganizationPolicyDeleteCall<'a, C> {
6124 self._scopes.clear();
6125 self
6126 }
6127}
6128
6129/// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
6130///
6131/// A builder for the *policies.get* method supported by a *organization* resource.
6132/// It is not used directly, but through a [`OrganizationMethods`] instance.
6133///
6134/// # Example
6135///
6136/// Instantiate a resource method builder
6137///
6138/// ```test_harness,no_run
6139/// # extern crate hyper;
6140/// # extern crate hyper_rustls;
6141/// # extern crate google_orgpolicy2 as orgpolicy2;
6142/// # async fn dox() {
6143/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
6144///
6145/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
6146/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
6147/// # .with_native_roots()
6148/// # .unwrap()
6149/// # .https_only()
6150/// # .enable_http2()
6151/// # .build();
6152///
6153/// # let executor = hyper_util::rt::TokioExecutor::new();
6154/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
6155/// # secret,
6156/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
6157/// # yup_oauth2::client::CustomHyperClientBuilder::from(
6158/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
6159/// # ),
6160/// # ).build().await.unwrap();
6161///
6162/// # let client = hyper_util::client::legacy::Client::builder(
6163/// # hyper_util::rt::TokioExecutor::new()
6164/// # )
6165/// # .build(
6166/// # hyper_rustls::HttpsConnectorBuilder::new()
6167/// # .with_native_roots()
6168/// # .unwrap()
6169/// # .https_or_http()
6170/// # .enable_http2()
6171/// # .build()
6172/// # );
6173/// # let mut hub = OrgPolicyAPI::new(client, auth);
6174/// // You can configure optional parameters by calling the respective setters at will, and
6175/// // execute the final call using `doit()`.
6176/// // Values shown here are possibly random and not representative !
6177/// let result = hub.organizations().policies_get("name")
6178/// .doit().await;
6179/// # }
6180/// ```
6181pub struct OrganizationPolicyGetCall<'a, C>
6182where
6183 C: 'a,
6184{
6185 hub: &'a OrgPolicyAPI<C>,
6186 _name: String,
6187 _delegate: Option<&'a mut dyn common::Delegate>,
6188 _additional_params: HashMap<String, String>,
6189 _scopes: BTreeSet<String>,
6190}
6191
6192impl<'a, C> common::CallBuilder for OrganizationPolicyGetCall<'a, C> {}
6193
6194impl<'a, C> OrganizationPolicyGetCall<'a, C>
6195where
6196 C: common::Connector,
6197{
6198 /// Perform the operation you have build so far.
6199 pub async fn doit(
6200 mut self,
6201 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
6202 use std::borrow::Cow;
6203 use std::io::{Read, Seek};
6204
6205 use common::{url::Params, ToParts};
6206 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
6207
6208 let mut dd = common::DefaultDelegate;
6209 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
6210 dlg.begin(common::MethodInfo {
6211 id: "orgpolicy.organizations.policies.get",
6212 http_method: hyper::Method::GET,
6213 });
6214
6215 for &field in ["alt", "name"].iter() {
6216 if self._additional_params.contains_key(field) {
6217 dlg.finished(false);
6218 return Err(common::Error::FieldClash(field));
6219 }
6220 }
6221
6222 let mut params = Params::with_capacity(3 + self._additional_params.len());
6223 params.push("name", self._name);
6224
6225 params.extend(self._additional_params.iter());
6226
6227 params.push("alt", "json");
6228 let mut url = self.hub._base_url.clone() + "v2/{+name}";
6229 if self._scopes.is_empty() {
6230 self._scopes
6231 .insert(Scope::CloudPlatform.as_ref().to_string());
6232 }
6233
6234 #[allow(clippy::single_element_loop)]
6235 for &(find_this, param_name) in [("{+name}", "name")].iter() {
6236 url = params.uri_replacement(url, param_name, find_this, true);
6237 }
6238 {
6239 let to_remove = ["name"];
6240 params.remove_params(&to_remove);
6241 }
6242
6243 let url = params.parse_with_url(&url);
6244
6245 loop {
6246 let token = match self
6247 .hub
6248 .auth
6249 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
6250 .await
6251 {
6252 Ok(token) => token,
6253 Err(e) => match dlg.token(e) {
6254 Ok(token) => token,
6255 Err(e) => {
6256 dlg.finished(false);
6257 return Err(common::Error::MissingToken(e));
6258 }
6259 },
6260 };
6261 let mut req_result = {
6262 let client = &self.hub.client;
6263 dlg.pre_request();
6264 let mut req_builder = hyper::Request::builder()
6265 .method(hyper::Method::GET)
6266 .uri(url.as_str())
6267 .header(USER_AGENT, self.hub._user_agent.clone());
6268
6269 if let Some(token) = token.as_ref() {
6270 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
6271 }
6272
6273 let request = req_builder
6274 .header(CONTENT_LENGTH, 0_u64)
6275 .body(common::to_body::<String>(None));
6276
6277 client.request(request.unwrap()).await
6278 };
6279
6280 match req_result {
6281 Err(err) => {
6282 if let common::Retry::After(d) = dlg.http_error(&err) {
6283 sleep(d).await;
6284 continue;
6285 }
6286 dlg.finished(false);
6287 return Err(common::Error::HttpError(err));
6288 }
6289 Ok(res) => {
6290 let (mut parts, body) = res.into_parts();
6291 let mut body = common::Body::new(body);
6292 if !parts.status.is_success() {
6293 let bytes = common::to_bytes(body).await.unwrap_or_default();
6294 let error = serde_json::from_str(&common::to_string(&bytes));
6295 let response = common::to_response(parts, bytes.into());
6296
6297 if let common::Retry::After(d) =
6298 dlg.http_failure(&response, error.as_ref().ok())
6299 {
6300 sleep(d).await;
6301 continue;
6302 }
6303
6304 dlg.finished(false);
6305
6306 return Err(match error {
6307 Ok(value) => common::Error::BadRequest(value),
6308 _ => common::Error::Failure(response),
6309 });
6310 }
6311 let response = {
6312 let bytes = common::to_bytes(body).await.unwrap_or_default();
6313 let encoded = common::to_string(&bytes);
6314 match serde_json::from_str(&encoded) {
6315 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
6316 Err(error) => {
6317 dlg.response_json_decode_error(&encoded, &error);
6318 return Err(common::Error::JsonDecodeError(
6319 encoded.to_string(),
6320 error,
6321 ));
6322 }
6323 }
6324 };
6325
6326 dlg.finished(true);
6327 return Ok(response);
6328 }
6329 }
6330 }
6331 }
6332
6333 /// Required. Resource name of the policy. See Policy for naming requirements.
6334 ///
6335 /// Sets the *name* path property to the given value.
6336 ///
6337 /// Even though the property as already been set when instantiating this call,
6338 /// we provide this method for API completeness.
6339 pub fn name(mut self, new_value: &str) -> OrganizationPolicyGetCall<'a, C> {
6340 self._name = new_value.to_string();
6341 self
6342 }
6343 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
6344 /// while executing the actual API request.
6345 ///
6346 /// ````text
6347 /// It should be used to handle progress information, and to implement a certain level of resilience.
6348 /// ````
6349 ///
6350 /// Sets the *delegate* property to the given value.
6351 pub fn delegate(
6352 mut self,
6353 new_value: &'a mut dyn common::Delegate,
6354 ) -> OrganizationPolicyGetCall<'a, C> {
6355 self._delegate = Some(new_value);
6356 self
6357 }
6358
6359 /// Set any additional parameter of the query string used in the request.
6360 /// It should be used to set parameters which are not yet available through their own
6361 /// setters.
6362 ///
6363 /// Please note that this method must not be used to set any of the known parameters
6364 /// which have their own setter method. If done anyway, the request will fail.
6365 ///
6366 /// # Additional Parameters
6367 ///
6368 /// * *$.xgafv* (query-string) - V1 error format.
6369 /// * *access_token* (query-string) - OAuth access token.
6370 /// * *alt* (query-string) - Data format for response.
6371 /// * *callback* (query-string) - JSONP
6372 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
6373 /// * *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.
6374 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
6375 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
6376 /// * *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.
6377 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
6378 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
6379 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyGetCall<'a, C>
6380 where
6381 T: AsRef<str>,
6382 {
6383 self._additional_params
6384 .insert(name.as_ref().to_string(), value.as_ref().to_string());
6385 self
6386 }
6387
6388 /// Identifies the authorization scope for the method you are building.
6389 ///
6390 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
6391 /// [`Scope::CloudPlatform`].
6392 ///
6393 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
6394 /// tokens for more than one scope.
6395 ///
6396 /// Usually there is more than one suitable scope to authorize an operation, some of which may
6397 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
6398 /// sufficient, a read-write scope will do as well.
6399 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyGetCall<'a, C>
6400 where
6401 St: AsRef<str>,
6402 {
6403 self._scopes.insert(String::from(scope.as_ref()));
6404 self
6405 }
6406 /// Identifies the authorization scope(s) for the method you are building.
6407 ///
6408 /// See [`Self::add_scope()`] for details.
6409 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyGetCall<'a, C>
6410 where
6411 I: IntoIterator<Item = St>,
6412 St: AsRef<str>,
6413 {
6414 self._scopes
6415 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
6416 self
6417 }
6418
6419 /// Removes all scopes, and no default scope will be used either.
6420 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
6421 /// for details).
6422 pub fn clear_scopes(mut self) -> OrganizationPolicyGetCall<'a, C> {
6423 self._scopes.clear();
6424 self
6425 }
6426}
6427
6428/// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
6429///
6430/// A builder for the *policies.getEffectivePolicy* method supported by a *organization* resource.
6431/// It is not used directly, but through a [`OrganizationMethods`] instance.
6432///
6433/// # Example
6434///
6435/// Instantiate a resource method builder
6436///
6437/// ```test_harness,no_run
6438/// # extern crate hyper;
6439/// # extern crate hyper_rustls;
6440/// # extern crate google_orgpolicy2 as orgpolicy2;
6441/// # async fn dox() {
6442/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
6443///
6444/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
6445/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
6446/// # .with_native_roots()
6447/// # .unwrap()
6448/// # .https_only()
6449/// # .enable_http2()
6450/// # .build();
6451///
6452/// # let executor = hyper_util::rt::TokioExecutor::new();
6453/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
6454/// # secret,
6455/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
6456/// # yup_oauth2::client::CustomHyperClientBuilder::from(
6457/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
6458/// # ),
6459/// # ).build().await.unwrap();
6460///
6461/// # let client = hyper_util::client::legacy::Client::builder(
6462/// # hyper_util::rt::TokioExecutor::new()
6463/// # )
6464/// # .build(
6465/// # hyper_rustls::HttpsConnectorBuilder::new()
6466/// # .with_native_roots()
6467/// # .unwrap()
6468/// # .https_or_http()
6469/// # .enable_http2()
6470/// # .build()
6471/// # );
6472/// # let mut hub = OrgPolicyAPI::new(client, auth);
6473/// // You can configure optional parameters by calling the respective setters at will, and
6474/// // execute the final call using `doit()`.
6475/// // Values shown here are possibly random and not representative !
6476/// let result = hub.organizations().policies_get_effective_policy("name")
6477/// .doit().await;
6478/// # }
6479/// ```
6480pub struct OrganizationPolicyGetEffectivePolicyCall<'a, C>
6481where
6482 C: 'a,
6483{
6484 hub: &'a OrgPolicyAPI<C>,
6485 _name: String,
6486 _delegate: Option<&'a mut dyn common::Delegate>,
6487 _additional_params: HashMap<String, String>,
6488 _scopes: BTreeSet<String>,
6489}
6490
6491impl<'a, C> common::CallBuilder for OrganizationPolicyGetEffectivePolicyCall<'a, C> {}
6492
6493impl<'a, C> OrganizationPolicyGetEffectivePolicyCall<'a, C>
6494where
6495 C: common::Connector,
6496{
6497 /// Perform the operation you have build so far.
6498 pub async fn doit(
6499 mut self,
6500 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
6501 use std::borrow::Cow;
6502 use std::io::{Read, Seek};
6503
6504 use common::{url::Params, ToParts};
6505 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
6506
6507 let mut dd = common::DefaultDelegate;
6508 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
6509 dlg.begin(common::MethodInfo {
6510 id: "orgpolicy.organizations.policies.getEffectivePolicy",
6511 http_method: hyper::Method::GET,
6512 });
6513
6514 for &field in ["alt", "name"].iter() {
6515 if self._additional_params.contains_key(field) {
6516 dlg.finished(false);
6517 return Err(common::Error::FieldClash(field));
6518 }
6519 }
6520
6521 let mut params = Params::with_capacity(3 + self._additional_params.len());
6522 params.push("name", self._name);
6523
6524 params.extend(self._additional_params.iter());
6525
6526 params.push("alt", "json");
6527 let mut url = self.hub._base_url.clone() + "v2/{+name}:getEffectivePolicy";
6528 if self._scopes.is_empty() {
6529 self._scopes
6530 .insert(Scope::CloudPlatform.as_ref().to_string());
6531 }
6532
6533 #[allow(clippy::single_element_loop)]
6534 for &(find_this, param_name) in [("{+name}", "name")].iter() {
6535 url = params.uri_replacement(url, param_name, find_this, true);
6536 }
6537 {
6538 let to_remove = ["name"];
6539 params.remove_params(&to_remove);
6540 }
6541
6542 let url = params.parse_with_url(&url);
6543
6544 loop {
6545 let token = match self
6546 .hub
6547 .auth
6548 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
6549 .await
6550 {
6551 Ok(token) => token,
6552 Err(e) => match dlg.token(e) {
6553 Ok(token) => token,
6554 Err(e) => {
6555 dlg.finished(false);
6556 return Err(common::Error::MissingToken(e));
6557 }
6558 },
6559 };
6560 let mut req_result = {
6561 let client = &self.hub.client;
6562 dlg.pre_request();
6563 let mut req_builder = hyper::Request::builder()
6564 .method(hyper::Method::GET)
6565 .uri(url.as_str())
6566 .header(USER_AGENT, self.hub._user_agent.clone());
6567
6568 if let Some(token) = token.as_ref() {
6569 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
6570 }
6571
6572 let request = req_builder
6573 .header(CONTENT_LENGTH, 0_u64)
6574 .body(common::to_body::<String>(None));
6575
6576 client.request(request.unwrap()).await
6577 };
6578
6579 match req_result {
6580 Err(err) => {
6581 if let common::Retry::After(d) = dlg.http_error(&err) {
6582 sleep(d).await;
6583 continue;
6584 }
6585 dlg.finished(false);
6586 return Err(common::Error::HttpError(err));
6587 }
6588 Ok(res) => {
6589 let (mut parts, body) = res.into_parts();
6590 let mut body = common::Body::new(body);
6591 if !parts.status.is_success() {
6592 let bytes = common::to_bytes(body).await.unwrap_or_default();
6593 let error = serde_json::from_str(&common::to_string(&bytes));
6594 let response = common::to_response(parts, bytes.into());
6595
6596 if let common::Retry::After(d) =
6597 dlg.http_failure(&response, error.as_ref().ok())
6598 {
6599 sleep(d).await;
6600 continue;
6601 }
6602
6603 dlg.finished(false);
6604
6605 return Err(match error {
6606 Ok(value) => common::Error::BadRequest(value),
6607 _ => common::Error::Failure(response),
6608 });
6609 }
6610 let response = {
6611 let bytes = common::to_bytes(body).await.unwrap_or_default();
6612 let encoded = common::to_string(&bytes);
6613 match serde_json::from_str(&encoded) {
6614 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
6615 Err(error) => {
6616 dlg.response_json_decode_error(&encoded, &error);
6617 return Err(common::Error::JsonDecodeError(
6618 encoded.to_string(),
6619 error,
6620 ));
6621 }
6622 }
6623 };
6624
6625 dlg.finished(true);
6626 return Ok(response);
6627 }
6628 }
6629 }
6630 }
6631
6632 /// Required. The effective policy to compute. See Policy for naming requirements.
6633 ///
6634 /// Sets the *name* path property to the given value.
6635 ///
6636 /// Even though the property as already been set when instantiating this call,
6637 /// we provide this method for API completeness.
6638 pub fn name(mut self, new_value: &str) -> OrganizationPolicyGetEffectivePolicyCall<'a, C> {
6639 self._name = new_value.to_string();
6640 self
6641 }
6642 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
6643 /// while executing the actual API request.
6644 ///
6645 /// ````text
6646 /// It should be used to handle progress information, and to implement a certain level of resilience.
6647 /// ````
6648 ///
6649 /// Sets the *delegate* property to the given value.
6650 pub fn delegate(
6651 mut self,
6652 new_value: &'a mut dyn common::Delegate,
6653 ) -> OrganizationPolicyGetEffectivePolicyCall<'a, C> {
6654 self._delegate = Some(new_value);
6655 self
6656 }
6657
6658 /// Set any additional parameter of the query string used in the request.
6659 /// It should be used to set parameters which are not yet available through their own
6660 /// setters.
6661 ///
6662 /// Please note that this method must not be used to set any of the known parameters
6663 /// which have their own setter method. If done anyway, the request will fail.
6664 ///
6665 /// # Additional Parameters
6666 ///
6667 /// * *$.xgafv* (query-string) - V1 error format.
6668 /// * *access_token* (query-string) - OAuth access token.
6669 /// * *alt* (query-string) - Data format for response.
6670 /// * *callback* (query-string) - JSONP
6671 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
6672 /// * *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.
6673 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
6674 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
6675 /// * *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.
6676 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
6677 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
6678 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyGetEffectivePolicyCall<'a, C>
6679 where
6680 T: AsRef<str>,
6681 {
6682 self._additional_params
6683 .insert(name.as_ref().to_string(), value.as_ref().to_string());
6684 self
6685 }
6686
6687 /// Identifies the authorization scope for the method you are building.
6688 ///
6689 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
6690 /// [`Scope::CloudPlatform`].
6691 ///
6692 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
6693 /// tokens for more than one scope.
6694 ///
6695 /// Usually there is more than one suitable scope to authorize an operation, some of which may
6696 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
6697 /// sufficient, a read-write scope will do as well.
6698 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyGetEffectivePolicyCall<'a, C>
6699 where
6700 St: AsRef<str>,
6701 {
6702 self._scopes.insert(String::from(scope.as_ref()));
6703 self
6704 }
6705 /// Identifies the authorization scope(s) for the method you are building.
6706 ///
6707 /// See [`Self::add_scope()`] for details.
6708 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyGetEffectivePolicyCall<'a, C>
6709 where
6710 I: IntoIterator<Item = St>,
6711 St: AsRef<str>,
6712 {
6713 self._scopes
6714 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
6715 self
6716 }
6717
6718 /// Removes all scopes, and no default scope will be used either.
6719 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
6720 /// for details).
6721 pub fn clear_scopes(mut self) -> OrganizationPolicyGetEffectivePolicyCall<'a, C> {
6722 self._scopes.clear();
6723 self
6724 }
6725}
6726
6727/// Retrieves all of the policies that exist on a particular resource.
6728///
6729/// A builder for the *policies.list* method supported by a *organization* resource.
6730/// It is not used directly, but through a [`OrganizationMethods`] instance.
6731///
6732/// # Example
6733///
6734/// Instantiate a resource method builder
6735///
6736/// ```test_harness,no_run
6737/// # extern crate hyper;
6738/// # extern crate hyper_rustls;
6739/// # extern crate google_orgpolicy2 as orgpolicy2;
6740/// # async fn dox() {
6741/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
6742///
6743/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
6744/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
6745/// # .with_native_roots()
6746/// # .unwrap()
6747/// # .https_only()
6748/// # .enable_http2()
6749/// # .build();
6750///
6751/// # let executor = hyper_util::rt::TokioExecutor::new();
6752/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
6753/// # secret,
6754/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
6755/// # yup_oauth2::client::CustomHyperClientBuilder::from(
6756/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
6757/// # ),
6758/// # ).build().await.unwrap();
6759///
6760/// # let client = hyper_util::client::legacy::Client::builder(
6761/// # hyper_util::rt::TokioExecutor::new()
6762/// # )
6763/// # .build(
6764/// # hyper_rustls::HttpsConnectorBuilder::new()
6765/// # .with_native_roots()
6766/// # .unwrap()
6767/// # .https_or_http()
6768/// # .enable_http2()
6769/// # .build()
6770/// # );
6771/// # let mut hub = OrgPolicyAPI::new(client, auth);
6772/// // You can configure optional parameters by calling the respective setters at will, and
6773/// // execute the final call using `doit()`.
6774/// // Values shown here are possibly random and not representative !
6775/// let result = hub.organizations().policies_list("parent")
6776/// .page_token("est")
6777/// .page_size(-62)
6778/// .doit().await;
6779/// # }
6780/// ```
6781pub struct OrganizationPolicyListCall<'a, C>
6782where
6783 C: 'a,
6784{
6785 hub: &'a OrgPolicyAPI<C>,
6786 _parent: String,
6787 _page_token: Option<String>,
6788 _page_size: Option<i32>,
6789 _delegate: Option<&'a mut dyn common::Delegate>,
6790 _additional_params: HashMap<String, String>,
6791 _scopes: BTreeSet<String>,
6792}
6793
6794impl<'a, C> common::CallBuilder for OrganizationPolicyListCall<'a, C> {}
6795
6796impl<'a, C> OrganizationPolicyListCall<'a, C>
6797where
6798 C: common::Connector,
6799{
6800 /// Perform the operation you have build so far.
6801 pub async fn doit(
6802 mut self,
6803 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2ListPoliciesResponse)> {
6804 use std::borrow::Cow;
6805 use std::io::{Read, Seek};
6806
6807 use common::{url::Params, ToParts};
6808 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
6809
6810 let mut dd = common::DefaultDelegate;
6811 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
6812 dlg.begin(common::MethodInfo {
6813 id: "orgpolicy.organizations.policies.list",
6814 http_method: hyper::Method::GET,
6815 });
6816
6817 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
6818 if self._additional_params.contains_key(field) {
6819 dlg.finished(false);
6820 return Err(common::Error::FieldClash(field));
6821 }
6822 }
6823
6824 let mut params = Params::with_capacity(5 + self._additional_params.len());
6825 params.push("parent", self._parent);
6826 if let Some(value) = self._page_token.as_ref() {
6827 params.push("pageToken", value);
6828 }
6829 if let Some(value) = self._page_size.as_ref() {
6830 params.push("pageSize", value.to_string());
6831 }
6832
6833 params.extend(self._additional_params.iter());
6834
6835 params.push("alt", "json");
6836 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
6837 if self._scopes.is_empty() {
6838 self._scopes
6839 .insert(Scope::CloudPlatform.as_ref().to_string());
6840 }
6841
6842 #[allow(clippy::single_element_loop)]
6843 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
6844 url = params.uri_replacement(url, param_name, find_this, true);
6845 }
6846 {
6847 let to_remove = ["parent"];
6848 params.remove_params(&to_remove);
6849 }
6850
6851 let url = params.parse_with_url(&url);
6852
6853 loop {
6854 let token = match self
6855 .hub
6856 .auth
6857 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
6858 .await
6859 {
6860 Ok(token) => token,
6861 Err(e) => match dlg.token(e) {
6862 Ok(token) => token,
6863 Err(e) => {
6864 dlg.finished(false);
6865 return Err(common::Error::MissingToken(e));
6866 }
6867 },
6868 };
6869 let mut req_result = {
6870 let client = &self.hub.client;
6871 dlg.pre_request();
6872 let mut req_builder = hyper::Request::builder()
6873 .method(hyper::Method::GET)
6874 .uri(url.as_str())
6875 .header(USER_AGENT, self.hub._user_agent.clone());
6876
6877 if let Some(token) = token.as_ref() {
6878 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
6879 }
6880
6881 let request = req_builder
6882 .header(CONTENT_LENGTH, 0_u64)
6883 .body(common::to_body::<String>(None));
6884
6885 client.request(request.unwrap()).await
6886 };
6887
6888 match req_result {
6889 Err(err) => {
6890 if let common::Retry::After(d) = dlg.http_error(&err) {
6891 sleep(d).await;
6892 continue;
6893 }
6894 dlg.finished(false);
6895 return Err(common::Error::HttpError(err));
6896 }
6897 Ok(res) => {
6898 let (mut parts, body) = res.into_parts();
6899 let mut body = common::Body::new(body);
6900 if !parts.status.is_success() {
6901 let bytes = common::to_bytes(body).await.unwrap_or_default();
6902 let error = serde_json::from_str(&common::to_string(&bytes));
6903 let response = common::to_response(parts, bytes.into());
6904
6905 if let common::Retry::After(d) =
6906 dlg.http_failure(&response, error.as_ref().ok())
6907 {
6908 sleep(d).await;
6909 continue;
6910 }
6911
6912 dlg.finished(false);
6913
6914 return Err(match error {
6915 Ok(value) => common::Error::BadRequest(value),
6916 _ => common::Error::Failure(response),
6917 });
6918 }
6919 let response = {
6920 let bytes = common::to_bytes(body).await.unwrap_or_default();
6921 let encoded = common::to_string(&bytes);
6922 match serde_json::from_str(&encoded) {
6923 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
6924 Err(error) => {
6925 dlg.response_json_decode_error(&encoded, &error);
6926 return Err(common::Error::JsonDecodeError(
6927 encoded.to_string(),
6928 error,
6929 ));
6930 }
6931 }
6932 };
6933
6934 dlg.finished(true);
6935 return Ok(response);
6936 }
6937 }
6938 }
6939 }
6940
6941 /// Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
6942 ///
6943 /// Sets the *parent* path property to the given value.
6944 ///
6945 /// Even though the property as already been set when instantiating this call,
6946 /// we provide this method for API completeness.
6947 pub fn parent(mut self, new_value: &str) -> OrganizationPolicyListCall<'a, C> {
6948 self._parent = new_value.to_string();
6949 self
6950 }
6951 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
6952 ///
6953 /// Sets the *page token* query property to the given value.
6954 pub fn page_token(mut self, new_value: &str) -> OrganizationPolicyListCall<'a, C> {
6955 self._page_token = Some(new_value.to_string());
6956 self
6957 }
6958 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
6959 ///
6960 /// Sets the *page size* query property to the given value.
6961 pub fn page_size(mut self, new_value: i32) -> OrganizationPolicyListCall<'a, C> {
6962 self._page_size = Some(new_value);
6963 self
6964 }
6965 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
6966 /// while executing the actual API request.
6967 ///
6968 /// ````text
6969 /// It should be used to handle progress information, and to implement a certain level of resilience.
6970 /// ````
6971 ///
6972 /// Sets the *delegate* property to the given value.
6973 pub fn delegate(
6974 mut self,
6975 new_value: &'a mut dyn common::Delegate,
6976 ) -> OrganizationPolicyListCall<'a, C> {
6977 self._delegate = Some(new_value);
6978 self
6979 }
6980
6981 /// Set any additional parameter of the query string used in the request.
6982 /// It should be used to set parameters which are not yet available through their own
6983 /// setters.
6984 ///
6985 /// Please note that this method must not be used to set any of the known parameters
6986 /// which have their own setter method. If done anyway, the request will fail.
6987 ///
6988 /// # Additional Parameters
6989 ///
6990 /// * *$.xgafv* (query-string) - V1 error format.
6991 /// * *access_token* (query-string) - OAuth access token.
6992 /// * *alt* (query-string) - Data format for response.
6993 /// * *callback* (query-string) - JSONP
6994 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
6995 /// * *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.
6996 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
6997 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
6998 /// * *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.
6999 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
7000 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
7001 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyListCall<'a, C>
7002 where
7003 T: AsRef<str>,
7004 {
7005 self._additional_params
7006 .insert(name.as_ref().to_string(), value.as_ref().to_string());
7007 self
7008 }
7009
7010 /// Identifies the authorization scope for the method you are building.
7011 ///
7012 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
7013 /// [`Scope::CloudPlatform`].
7014 ///
7015 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
7016 /// tokens for more than one scope.
7017 ///
7018 /// Usually there is more than one suitable scope to authorize an operation, some of which may
7019 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
7020 /// sufficient, a read-write scope will do as well.
7021 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyListCall<'a, C>
7022 where
7023 St: AsRef<str>,
7024 {
7025 self._scopes.insert(String::from(scope.as_ref()));
7026 self
7027 }
7028 /// Identifies the authorization scope(s) for the method you are building.
7029 ///
7030 /// See [`Self::add_scope()`] for details.
7031 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyListCall<'a, C>
7032 where
7033 I: IntoIterator<Item = St>,
7034 St: AsRef<str>,
7035 {
7036 self._scopes
7037 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
7038 self
7039 }
7040
7041 /// Removes all scopes, and no default scope will be used either.
7042 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
7043 /// for details).
7044 pub fn clear_scopes(mut self) -> OrganizationPolicyListCall<'a, C> {
7045 self._scopes.clear();
7046 self
7047 }
7048}
7049
7050/// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
7051///
7052/// A builder for the *policies.patch* method supported by a *organization* resource.
7053/// It is not used directly, but through a [`OrganizationMethods`] instance.
7054///
7055/// # Example
7056///
7057/// Instantiate a resource method builder
7058///
7059/// ```test_harness,no_run
7060/// # extern crate hyper;
7061/// # extern crate hyper_rustls;
7062/// # extern crate google_orgpolicy2 as orgpolicy2;
7063/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
7064/// # async fn dox() {
7065/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
7066///
7067/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
7068/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
7069/// # .with_native_roots()
7070/// # .unwrap()
7071/// # .https_only()
7072/// # .enable_http2()
7073/// # .build();
7074///
7075/// # let executor = hyper_util::rt::TokioExecutor::new();
7076/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
7077/// # secret,
7078/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
7079/// # yup_oauth2::client::CustomHyperClientBuilder::from(
7080/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
7081/// # ),
7082/// # ).build().await.unwrap();
7083///
7084/// # let client = hyper_util::client::legacy::Client::builder(
7085/// # hyper_util::rt::TokioExecutor::new()
7086/// # )
7087/// # .build(
7088/// # hyper_rustls::HttpsConnectorBuilder::new()
7089/// # .with_native_roots()
7090/// # .unwrap()
7091/// # .https_or_http()
7092/// # .enable_http2()
7093/// # .build()
7094/// # );
7095/// # let mut hub = OrgPolicyAPI::new(client, auth);
7096/// // As the method needs a request, you would usually fill it with the desired information
7097/// // into the respective structure. Some of the parts shown here might not be applicable !
7098/// // Values shown here are possibly random and not representative !
7099/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
7100///
7101/// // You can configure optional parameters by calling the respective setters at will, and
7102/// // execute the final call using `doit()`.
7103/// // Values shown here are possibly random and not representative !
7104/// let result = hub.organizations().policies_patch(req, "name")
7105/// .update_mask(FieldMask::new::<&str>(&[]))
7106/// .doit().await;
7107/// # }
7108/// ```
7109pub struct OrganizationPolicyPatchCall<'a, C>
7110where
7111 C: 'a,
7112{
7113 hub: &'a OrgPolicyAPI<C>,
7114 _request: GoogleCloudOrgpolicyV2Policy,
7115 _name: String,
7116 _update_mask: Option<common::FieldMask>,
7117 _delegate: Option<&'a mut dyn common::Delegate>,
7118 _additional_params: HashMap<String, String>,
7119 _scopes: BTreeSet<String>,
7120}
7121
7122impl<'a, C> common::CallBuilder for OrganizationPolicyPatchCall<'a, C> {}
7123
7124impl<'a, C> OrganizationPolicyPatchCall<'a, C>
7125where
7126 C: common::Connector,
7127{
7128 /// Perform the operation you have build so far.
7129 pub async fn doit(
7130 mut self,
7131 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
7132 use std::borrow::Cow;
7133 use std::io::{Read, Seek};
7134
7135 use common::{url::Params, ToParts};
7136 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
7137
7138 let mut dd = common::DefaultDelegate;
7139 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
7140 dlg.begin(common::MethodInfo {
7141 id: "orgpolicy.organizations.policies.patch",
7142 http_method: hyper::Method::PATCH,
7143 });
7144
7145 for &field in ["alt", "name", "updateMask"].iter() {
7146 if self._additional_params.contains_key(field) {
7147 dlg.finished(false);
7148 return Err(common::Error::FieldClash(field));
7149 }
7150 }
7151
7152 let mut params = Params::with_capacity(5 + self._additional_params.len());
7153 params.push("name", self._name);
7154 if let Some(value) = self._update_mask.as_ref() {
7155 params.push("updateMask", value.to_string());
7156 }
7157
7158 params.extend(self._additional_params.iter());
7159
7160 params.push("alt", "json");
7161 let mut url = self.hub._base_url.clone() + "v2/{+name}";
7162 if self._scopes.is_empty() {
7163 self._scopes
7164 .insert(Scope::CloudPlatform.as_ref().to_string());
7165 }
7166
7167 #[allow(clippy::single_element_loop)]
7168 for &(find_this, param_name) in [("{+name}", "name")].iter() {
7169 url = params.uri_replacement(url, param_name, find_this, true);
7170 }
7171 {
7172 let to_remove = ["name"];
7173 params.remove_params(&to_remove);
7174 }
7175
7176 let url = params.parse_with_url(&url);
7177
7178 let mut json_mime_type = mime::APPLICATION_JSON;
7179 let mut request_value_reader = {
7180 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
7181 common::remove_json_null_values(&mut value);
7182 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
7183 serde_json::to_writer(&mut dst, &value).unwrap();
7184 dst
7185 };
7186 let request_size = request_value_reader
7187 .seek(std::io::SeekFrom::End(0))
7188 .unwrap();
7189 request_value_reader
7190 .seek(std::io::SeekFrom::Start(0))
7191 .unwrap();
7192
7193 loop {
7194 let token = match self
7195 .hub
7196 .auth
7197 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
7198 .await
7199 {
7200 Ok(token) => token,
7201 Err(e) => match dlg.token(e) {
7202 Ok(token) => token,
7203 Err(e) => {
7204 dlg.finished(false);
7205 return Err(common::Error::MissingToken(e));
7206 }
7207 },
7208 };
7209 request_value_reader
7210 .seek(std::io::SeekFrom::Start(0))
7211 .unwrap();
7212 let mut req_result = {
7213 let client = &self.hub.client;
7214 dlg.pre_request();
7215 let mut req_builder = hyper::Request::builder()
7216 .method(hyper::Method::PATCH)
7217 .uri(url.as_str())
7218 .header(USER_AGENT, self.hub._user_agent.clone());
7219
7220 if let Some(token) = token.as_ref() {
7221 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
7222 }
7223
7224 let request = req_builder
7225 .header(CONTENT_TYPE, json_mime_type.to_string())
7226 .header(CONTENT_LENGTH, request_size as u64)
7227 .body(common::to_body(
7228 request_value_reader.get_ref().clone().into(),
7229 ));
7230
7231 client.request(request.unwrap()).await
7232 };
7233
7234 match req_result {
7235 Err(err) => {
7236 if let common::Retry::After(d) = dlg.http_error(&err) {
7237 sleep(d).await;
7238 continue;
7239 }
7240 dlg.finished(false);
7241 return Err(common::Error::HttpError(err));
7242 }
7243 Ok(res) => {
7244 let (mut parts, body) = res.into_parts();
7245 let mut body = common::Body::new(body);
7246 if !parts.status.is_success() {
7247 let bytes = common::to_bytes(body).await.unwrap_or_default();
7248 let error = serde_json::from_str(&common::to_string(&bytes));
7249 let response = common::to_response(parts, bytes.into());
7250
7251 if let common::Retry::After(d) =
7252 dlg.http_failure(&response, error.as_ref().ok())
7253 {
7254 sleep(d).await;
7255 continue;
7256 }
7257
7258 dlg.finished(false);
7259
7260 return Err(match error {
7261 Ok(value) => common::Error::BadRequest(value),
7262 _ => common::Error::Failure(response),
7263 });
7264 }
7265 let response = {
7266 let bytes = common::to_bytes(body).await.unwrap_or_default();
7267 let encoded = common::to_string(&bytes);
7268 match serde_json::from_str(&encoded) {
7269 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
7270 Err(error) => {
7271 dlg.response_json_decode_error(&encoded, &error);
7272 return Err(common::Error::JsonDecodeError(
7273 encoded.to_string(),
7274 error,
7275 ));
7276 }
7277 }
7278 };
7279
7280 dlg.finished(true);
7281 return Ok(response);
7282 }
7283 }
7284 }
7285 }
7286
7287 ///
7288 /// Sets the *request* property to the given value.
7289 ///
7290 /// Even though the property as already been set when instantiating this call,
7291 /// we provide this method for API completeness.
7292 pub fn request(
7293 mut self,
7294 new_value: GoogleCloudOrgpolicyV2Policy,
7295 ) -> OrganizationPolicyPatchCall<'a, C> {
7296 self._request = new_value;
7297 self
7298 }
7299 /// Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
7300 ///
7301 /// Sets the *name* path property to the given value.
7302 ///
7303 /// Even though the property as already been set when instantiating this call,
7304 /// we provide this method for API completeness.
7305 pub fn name(mut self, new_value: &str) -> OrganizationPolicyPatchCall<'a, C> {
7306 self._name = new_value.to_string();
7307 self
7308 }
7309 /// Field mask used to specify the fields to be overwritten in the policy by the set. The fields specified in the update_mask are relative to the policy, not the full request.
7310 ///
7311 /// Sets the *update mask* query property to the given value.
7312 pub fn update_mask(
7313 mut self,
7314 new_value: common::FieldMask,
7315 ) -> OrganizationPolicyPatchCall<'a, C> {
7316 self._update_mask = Some(new_value);
7317 self
7318 }
7319 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
7320 /// while executing the actual API request.
7321 ///
7322 /// ````text
7323 /// It should be used to handle progress information, and to implement a certain level of resilience.
7324 /// ````
7325 ///
7326 /// Sets the *delegate* property to the given value.
7327 pub fn delegate(
7328 mut self,
7329 new_value: &'a mut dyn common::Delegate,
7330 ) -> OrganizationPolicyPatchCall<'a, C> {
7331 self._delegate = Some(new_value);
7332 self
7333 }
7334
7335 /// Set any additional parameter of the query string used in the request.
7336 /// It should be used to set parameters which are not yet available through their own
7337 /// setters.
7338 ///
7339 /// Please note that this method must not be used to set any of the known parameters
7340 /// which have their own setter method. If done anyway, the request will fail.
7341 ///
7342 /// # Additional Parameters
7343 ///
7344 /// * *$.xgafv* (query-string) - V1 error format.
7345 /// * *access_token* (query-string) - OAuth access token.
7346 /// * *alt* (query-string) - Data format for response.
7347 /// * *callback* (query-string) - JSONP
7348 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
7349 /// * *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.
7350 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
7351 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
7352 /// * *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.
7353 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
7354 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
7355 pub fn param<T>(mut self, name: T, value: T) -> OrganizationPolicyPatchCall<'a, C>
7356 where
7357 T: AsRef<str>,
7358 {
7359 self._additional_params
7360 .insert(name.as_ref().to_string(), value.as_ref().to_string());
7361 self
7362 }
7363
7364 /// Identifies the authorization scope for the method you are building.
7365 ///
7366 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
7367 /// [`Scope::CloudPlatform`].
7368 ///
7369 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
7370 /// tokens for more than one scope.
7371 ///
7372 /// Usually there is more than one suitable scope to authorize an operation, some of which may
7373 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
7374 /// sufficient, a read-write scope will do as well.
7375 pub fn add_scope<St>(mut self, scope: St) -> OrganizationPolicyPatchCall<'a, C>
7376 where
7377 St: AsRef<str>,
7378 {
7379 self._scopes.insert(String::from(scope.as_ref()));
7380 self
7381 }
7382 /// Identifies the authorization scope(s) for the method you are building.
7383 ///
7384 /// See [`Self::add_scope()`] for details.
7385 pub fn add_scopes<I, St>(mut self, scopes: I) -> OrganizationPolicyPatchCall<'a, C>
7386 where
7387 I: IntoIterator<Item = St>,
7388 St: AsRef<str>,
7389 {
7390 self._scopes
7391 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
7392 self
7393 }
7394
7395 /// Removes all scopes, and no default scope will be used either.
7396 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
7397 /// for details).
7398 pub fn clear_scopes(mut self) -> OrganizationPolicyPatchCall<'a, C> {
7399 self._scopes.clear();
7400 self
7401 }
7402}
7403
7404/// Lists constraints that could be applied on the specified resource.
7405///
7406/// A builder for the *constraints.list* method supported by a *project* resource.
7407/// It is not used directly, but through a [`ProjectMethods`] instance.
7408///
7409/// # Example
7410///
7411/// Instantiate a resource method builder
7412///
7413/// ```test_harness,no_run
7414/// # extern crate hyper;
7415/// # extern crate hyper_rustls;
7416/// # extern crate google_orgpolicy2 as orgpolicy2;
7417/// # async fn dox() {
7418/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
7419///
7420/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
7421/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
7422/// # .with_native_roots()
7423/// # .unwrap()
7424/// # .https_only()
7425/// # .enable_http2()
7426/// # .build();
7427///
7428/// # let executor = hyper_util::rt::TokioExecutor::new();
7429/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
7430/// # secret,
7431/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
7432/// # yup_oauth2::client::CustomHyperClientBuilder::from(
7433/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
7434/// # ),
7435/// # ).build().await.unwrap();
7436///
7437/// # let client = hyper_util::client::legacy::Client::builder(
7438/// # hyper_util::rt::TokioExecutor::new()
7439/// # )
7440/// # .build(
7441/// # hyper_rustls::HttpsConnectorBuilder::new()
7442/// # .with_native_roots()
7443/// # .unwrap()
7444/// # .https_or_http()
7445/// # .enable_http2()
7446/// # .build()
7447/// # );
7448/// # let mut hub = OrgPolicyAPI::new(client, auth);
7449/// // You can configure optional parameters by calling the respective setters at will, and
7450/// // execute the final call using `doit()`.
7451/// // Values shown here are possibly random and not representative !
7452/// let result = hub.projects().constraints_list("parent")
7453/// .page_token("Lorem")
7454/// .page_size(-25)
7455/// .doit().await;
7456/// # }
7457/// ```
7458pub struct ProjectConstraintListCall<'a, C>
7459where
7460 C: 'a,
7461{
7462 hub: &'a OrgPolicyAPI<C>,
7463 _parent: String,
7464 _page_token: Option<String>,
7465 _page_size: Option<i32>,
7466 _delegate: Option<&'a mut dyn common::Delegate>,
7467 _additional_params: HashMap<String, String>,
7468 _scopes: BTreeSet<String>,
7469}
7470
7471impl<'a, C> common::CallBuilder for ProjectConstraintListCall<'a, C> {}
7472
7473impl<'a, C> ProjectConstraintListCall<'a, C>
7474where
7475 C: common::Connector,
7476{
7477 /// Perform the operation you have build so far.
7478 pub async fn doit(
7479 mut self,
7480 ) -> common::Result<(
7481 common::Response,
7482 GoogleCloudOrgpolicyV2ListConstraintsResponse,
7483 )> {
7484 use std::borrow::Cow;
7485 use std::io::{Read, Seek};
7486
7487 use common::{url::Params, ToParts};
7488 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
7489
7490 let mut dd = common::DefaultDelegate;
7491 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
7492 dlg.begin(common::MethodInfo {
7493 id: "orgpolicy.projects.constraints.list",
7494 http_method: hyper::Method::GET,
7495 });
7496
7497 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
7498 if self._additional_params.contains_key(field) {
7499 dlg.finished(false);
7500 return Err(common::Error::FieldClash(field));
7501 }
7502 }
7503
7504 let mut params = Params::with_capacity(5 + self._additional_params.len());
7505 params.push("parent", self._parent);
7506 if let Some(value) = self._page_token.as_ref() {
7507 params.push("pageToken", value);
7508 }
7509 if let Some(value) = self._page_size.as_ref() {
7510 params.push("pageSize", value.to_string());
7511 }
7512
7513 params.extend(self._additional_params.iter());
7514
7515 params.push("alt", "json");
7516 let mut url = self.hub._base_url.clone() + "v2/{+parent}/constraints";
7517 if self._scopes.is_empty() {
7518 self._scopes
7519 .insert(Scope::CloudPlatform.as_ref().to_string());
7520 }
7521
7522 #[allow(clippy::single_element_loop)]
7523 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
7524 url = params.uri_replacement(url, param_name, find_this, true);
7525 }
7526 {
7527 let to_remove = ["parent"];
7528 params.remove_params(&to_remove);
7529 }
7530
7531 let url = params.parse_with_url(&url);
7532
7533 loop {
7534 let token = match self
7535 .hub
7536 .auth
7537 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
7538 .await
7539 {
7540 Ok(token) => token,
7541 Err(e) => match dlg.token(e) {
7542 Ok(token) => token,
7543 Err(e) => {
7544 dlg.finished(false);
7545 return Err(common::Error::MissingToken(e));
7546 }
7547 },
7548 };
7549 let mut req_result = {
7550 let client = &self.hub.client;
7551 dlg.pre_request();
7552 let mut req_builder = hyper::Request::builder()
7553 .method(hyper::Method::GET)
7554 .uri(url.as_str())
7555 .header(USER_AGENT, self.hub._user_agent.clone());
7556
7557 if let Some(token) = token.as_ref() {
7558 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
7559 }
7560
7561 let request = req_builder
7562 .header(CONTENT_LENGTH, 0_u64)
7563 .body(common::to_body::<String>(None));
7564
7565 client.request(request.unwrap()).await
7566 };
7567
7568 match req_result {
7569 Err(err) => {
7570 if let common::Retry::After(d) = dlg.http_error(&err) {
7571 sleep(d).await;
7572 continue;
7573 }
7574 dlg.finished(false);
7575 return Err(common::Error::HttpError(err));
7576 }
7577 Ok(res) => {
7578 let (mut parts, body) = res.into_parts();
7579 let mut body = common::Body::new(body);
7580 if !parts.status.is_success() {
7581 let bytes = common::to_bytes(body).await.unwrap_or_default();
7582 let error = serde_json::from_str(&common::to_string(&bytes));
7583 let response = common::to_response(parts, bytes.into());
7584
7585 if let common::Retry::After(d) =
7586 dlg.http_failure(&response, error.as_ref().ok())
7587 {
7588 sleep(d).await;
7589 continue;
7590 }
7591
7592 dlg.finished(false);
7593
7594 return Err(match error {
7595 Ok(value) => common::Error::BadRequest(value),
7596 _ => common::Error::Failure(response),
7597 });
7598 }
7599 let response = {
7600 let bytes = common::to_bytes(body).await.unwrap_or_default();
7601 let encoded = common::to_string(&bytes);
7602 match serde_json::from_str(&encoded) {
7603 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
7604 Err(error) => {
7605 dlg.response_json_decode_error(&encoded, &error);
7606 return Err(common::Error::JsonDecodeError(
7607 encoded.to_string(),
7608 error,
7609 ));
7610 }
7611 }
7612 };
7613
7614 dlg.finished(true);
7615 return Ok(response);
7616 }
7617 }
7618 }
7619 }
7620
7621 /// Required. The Google Cloud resource that parents the constraint. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
7622 ///
7623 /// Sets the *parent* path property to the given value.
7624 ///
7625 /// Even though the property as already been set when instantiating this call,
7626 /// we provide this method for API completeness.
7627 pub fn parent(mut self, new_value: &str) -> ProjectConstraintListCall<'a, C> {
7628 self._parent = new_value.to_string();
7629 self
7630 }
7631 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
7632 ///
7633 /// Sets the *page token* query property to the given value.
7634 pub fn page_token(mut self, new_value: &str) -> ProjectConstraintListCall<'a, C> {
7635 self._page_token = Some(new_value.to_string());
7636 self
7637 }
7638 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
7639 ///
7640 /// Sets the *page size* query property to the given value.
7641 pub fn page_size(mut self, new_value: i32) -> ProjectConstraintListCall<'a, C> {
7642 self._page_size = Some(new_value);
7643 self
7644 }
7645 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
7646 /// while executing the actual API request.
7647 ///
7648 /// ````text
7649 /// It should be used to handle progress information, and to implement a certain level of resilience.
7650 /// ````
7651 ///
7652 /// Sets the *delegate* property to the given value.
7653 pub fn delegate(
7654 mut self,
7655 new_value: &'a mut dyn common::Delegate,
7656 ) -> ProjectConstraintListCall<'a, C> {
7657 self._delegate = Some(new_value);
7658 self
7659 }
7660
7661 /// Set any additional parameter of the query string used in the request.
7662 /// It should be used to set parameters which are not yet available through their own
7663 /// setters.
7664 ///
7665 /// Please note that this method must not be used to set any of the known parameters
7666 /// which have their own setter method. If done anyway, the request will fail.
7667 ///
7668 /// # Additional Parameters
7669 ///
7670 /// * *$.xgafv* (query-string) - V1 error format.
7671 /// * *access_token* (query-string) - OAuth access token.
7672 /// * *alt* (query-string) - Data format for response.
7673 /// * *callback* (query-string) - JSONP
7674 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
7675 /// * *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.
7676 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
7677 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
7678 /// * *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.
7679 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
7680 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
7681 pub fn param<T>(mut self, name: T, value: T) -> ProjectConstraintListCall<'a, C>
7682 where
7683 T: AsRef<str>,
7684 {
7685 self._additional_params
7686 .insert(name.as_ref().to_string(), value.as_ref().to_string());
7687 self
7688 }
7689
7690 /// Identifies the authorization scope for the method you are building.
7691 ///
7692 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
7693 /// [`Scope::CloudPlatform`].
7694 ///
7695 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
7696 /// tokens for more than one scope.
7697 ///
7698 /// Usually there is more than one suitable scope to authorize an operation, some of which may
7699 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
7700 /// sufficient, a read-write scope will do as well.
7701 pub fn add_scope<St>(mut self, scope: St) -> ProjectConstraintListCall<'a, C>
7702 where
7703 St: AsRef<str>,
7704 {
7705 self._scopes.insert(String::from(scope.as_ref()));
7706 self
7707 }
7708 /// Identifies the authorization scope(s) for the method you are building.
7709 ///
7710 /// See [`Self::add_scope()`] for details.
7711 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectConstraintListCall<'a, C>
7712 where
7713 I: IntoIterator<Item = St>,
7714 St: AsRef<str>,
7715 {
7716 self._scopes
7717 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
7718 self
7719 }
7720
7721 /// Removes all scopes, and no default scope will be used either.
7722 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
7723 /// for details).
7724 pub fn clear_scopes(mut self) -> ProjectConstraintListCall<'a, C> {
7725 self._scopes.clear();
7726 self
7727 }
7728}
7729
7730/// Creates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint does not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ALREADY_EXISTS` if the policy already exists on the given Google Cloud resource.
7731///
7732/// A builder for the *policies.create* method supported by a *project* resource.
7733/// It is not used directly, but through a [`ProjectMethods`] instance.
7734///
7735/// # Example
7736///
7737/// Instantiate a resource method builder
7738///
7739/// ```test_harness,no_run
7740/// # extern crate hyper;
7741/// # extern crate hyper_rustls;
7742/// # extern crate google_orgpolicy2 as orgpolicy2;
7743/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
7744/// # async fn dox() {
7745/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
7746///
7747/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
7748/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
7749/// # .with_native_roots()
7750/// # .unwrap()
7751/// # .https_only()
7752/// # .enable_http2()
7753/// # .build();
7754///
7755/// # let executor = hyper_util::rt::TokioExecutor::new();
7756/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
7757/// # secret,
7758/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
7759/// # yup_oauth2::client::CustomHyperClientBuilder::from(
7760/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
7761/// # ),
7762/// # ).build().await.unwrap();
7763///
7764/// # let client = hyper_util::client::legacy::Client::builder(
7765/// # hyper_util::rt::TokioExecutor::new()
7766/// # )
7767/// # .build(
7768/// # hyper_rustls::HttpsConnectorBuilder::new()
7769/// # .with_native_roots()
7770/// # .unwrap()
7771/// # .https_or_http()
7772/// # .enable_http2()
7773/// # .build()
7774/// # );
7775/// # let mut hub = OrgPolicyAPI::new(client, auth);
7776/// // As the method needs a request, you would usually fill it with the desired information
7777/// // into the respective structure. Some of the parts shown here might not be applicable !
7778/// // Values shown here are possibly random and not representative !
7779/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
7780///
7781/// // You can configure optional parameters by calling the respective setters at will, and
7782/// // execute the final call using `doit()`.
7783/// // Values shown here are possibly random and not representative !
7784/// let result = hub.projects().policies_create(req, "parent")
7785/// .doit().await;
7786/// # }
7787/// ```
7788pub struct ProjectPolicyCreateCall<'a, C>
7789where
7790 C: 'a,
7791{
7792 hub: &'a OrgPolicyAPI<C>,
7793 _request: GoogleCloudOrgpolicyV2Policy,
7794 _parent: String,
7795 _delegate: Option<&'a mut dyn common::Delegate>,
7796 _additional_params: HashMap<String, String>,
7797 _scopes: BTreeSet<String>,
7798}
7799
7800impl<'a, C> common::CallBuilder for ProjectPolicyCreateCall<'a, C> {}
7801
7802impl<'a, C> ProjectPolicyCreateCall<'a, C>
7803where
7804 C: common::Connector,
7805{
7806 /// Perform the operation you have build so far.
7807 pub async fn doit(
7808 mut self,
7809 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
7810 use std::borrow::Cow;
7811 use std::io::{Read, Seek};
7812
7813 use common::{url::Params, ToParts};
7814 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
7815
7816 let mut dd = common::DefaultDelegate;
7817 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
7818 dlg.begin(common::MethodInfo {
7819 id: "orgpolicy.projects.policies.create",
7820 http_method: hyper::Method::POST,
7821 });
7822
7823 for &field in ["alt", "parent"].iter() {
7824 if self._additional_params.contains_key(field) {
7825 dlg.finished(false);
7826 return Err(common::Error::FieldClash(field));
7827 }
7828 }
7829
7830 let mut params = Params::with_capacity(4 + self._additional_params.len());
7831 params.push("parent", self._parent);
7832
7833 params.extend(self._additional_params.iter());
7834
7835 params.push("alt", "json");
7836 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
7837 if self._scopes.is_empty() {
7838 self._scopes
7839 .insert(Scope::CloudPlatform.as_ref().to_string());
7840 }
7841
7842 #[allow(clippy::single_element_loop)]
7843 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
7844 url = params.uri_replacement(url, param_name, find_this, true);
7845 }
7846 {
7847 let to_remove = ["parent"];
7848 params.remove_params(&to_remove);
7849 }
7850
7851 let url = params.parse_with_url(&url);
7852
7853 let mut json_mime_type = mime::APPLICATION_JSON;
7854 let mut request_value_reader = {
7855 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
7856 common::remove_json_null_values(&mut value);
7857 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
7858 serde_json::to_writer(&mut dst, &value).unwrap();
7859 dst
7860 };
7861 let request_size = request_value_reader
7862 .seek(std::io::SeekFrom::End(0))
7863 .unwrap();
7864 request_value_reader
7865 .seek(std::io::SeekFrom::Start(0))
7866 .unwrap();
7867
7868 loop {
7869 let token = match self
7870 .hub
7871 .auth
7872 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
7873 .await
7874 {
7875 Ok(token) => token,
7876 Err(e) => match dlg.token(e) {
7877 Ok(token) => token,
7878 Err(e) => {
7879 dlg.finished(false);
7880 return Err(common::Error::MissingToken(e));
7881 }
7882 },
7883 };
7884 request_value_reader
7885 .seek(std::io::SeekFrom::Start(0))
7886 .unwrap();
7887 let mut req_result = {
7888 let client = &self.hub.client;
7889 dlg.pre_request();
7890 let mut req_builder = hyper::Request::builder()
7891 .method(hyper::Method::POST)
7892 .uri(url.as_str())
7893 .header(USER_AGENT, self.hub._user_agent.clone());
7894
7895 if let Some(token) = token.as_ref() {
7896 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
7897 }
7898
7899 let request = req_builder
7900 .header(CONTENT_TYPE, json_mime_type.to_string())
7901 .header(CONTENT_LENGTH, request_size as u64)
7902 .body(common::to_body(
7903 request_value_reader.get_ref().clone().into(),
7904 ));
7905
7906 client.request(request.unwrap()).await
7907 };
7908
7909 match req_result {
7910 Err(err) => {
7911 if let common::Retry::After(d) = dlg.http_error(&err) {
7912 sleep(d).await;
7913 continue;
7914 }
7915 dlg.finished(false);
7916 return Err(common::Error::HttpError(err));
7917 }
7918 Ok(res) => {
7919 let (mut parts, body) = res.into_parts();
7920 let mut body = common::Body::new(body);
7921 if !parts.status.is_success() {
7922 let bytes = common::to_bytes(body).await.unwrap_or_default();
7923 let error = serde_json::from_str(&common::to_string(&bytes));
7924 let response = common::to_response(parts, bytes.into());
7925
7926 if let common::Retry::After(d) =
7927 dlg.http_failure(&response, error.as_ref().ok())
7928 {
7929 sleep(d).await;
7930 continue;
7931 }
7932
7933 dlg.finished(false);
7934
7935 return Err(match error {
7936 Ok(value) => common::Error::BadRequest(value),
7937 _ => common::Error::Failure(response),
7938 });
7939 }
7940 let response = {
7941 let bytes = common::to_bytes(body).await.unwrap_or_default();
7942 let encoded = common::to_string(&bytes);
7943 match serde_json::from_str(&encoded) {
7944 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
7945 Err(error) => {
7946 dlg.response_json_decode_error(&encoded, &error);
7947 return Err(common::Error::JsonDecodeError(
7948 encoded.to_string(),
7949 error,
7950 ));
7951 }
7952 }
7953 };
7954
7955 dlg.finished(true);
7956 return Ok(response);
7957 }
7958 }
7959 }
7960 }
7961
7962 ///
7963 /// Sets the *request* property to the given value.
7964 ///
7965 /// Even though the property as already been set when instantiating this call,
7966 /// we provide this method for API completeness.
7967 pub fn request(
7968 mut self,
7969 new_value: GoogleCloudOrgpolicyV2Policy,
7970 ) -> ProjectPolicyCreateCall<'a, C> {
7971 self._request = new_value;
7972 self
7973 }
7974 /// Required. The Google Cloud resource that will parent the new policy. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
7975 ///
7976 /// Sets the *parent* path property to the given value.
7977 ///
7978 /// Even though the property as already been set when instantiating this call,
7979 /// we provide this method for API completeness.
7980 pub fn parent(mut self, new_value: &str) -> ProjectPolicyCreateCall<'a, C> {
7981 self._parent = new_value.to_string();
7982 self
7983 }
7984 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
7985 /// while executing the actual API request.
7986 ///
7987 /// ````text
7988 /// It should be used to handle progress information, and to implement a certain level of resilience.
7989 /// ````
7990 ///
7991 /// Sets the *delegate* property to the given value.
7992 pub fn delegate(
7993 mut self,
7994 new_value: &'a mut dyn common::Delegate,
7995 ) -> ProjectPolicyCreateCall<'a, C> {
7996 self._delegate = Some(new_value);
7997 self
7998 }
7999
8000 /// Set any additional parameter of the query string used in the request.
8001 /// It should be used to set parameters which are not yet available through their own
8002 /// setters.
8003 ///
8004 /// Please note that this method must not be used to set any of the known parameters
8005 /// which have their own setter method. If done anyway, the request will fail.
8006 ///
8007 /// # Additional Parameters
8008 ///
8009 /// * *$.xgafv* (query-string) - V1 error format.
8010 /// * *access_token* (query-string) - OAuth access token.
8011 /// * *alt* (query-string) - Data format for response.
8012 /// * *callback* (query-string) - JSONP
8013 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
8014 /// * *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.
8015 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
8016 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
8017 /// * *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.
8018 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
8019 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
8020 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyCreateCall<'a, C>
8021 where
8022 T: AsRef<str>,
8023 {
8024 self._additional_params
8025 .insert(name.as_ref().to_string(), value.as_ref().to_string());
8026 self
8027 }
8028
8029 /// Identifies the authorization scope for the method you are building.
8030 ///
8031 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
8032 /// [`Scope::CloudPlatform`].
8033 ///
8034 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
8035 /// tokens for more than one scope.
8036 ///
8037 /// Usually there is more than one suitable scope to authorize an operation, some of which may
8038 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
8039 /// sufficient, a read-write scope will do as well.
8040 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyCreateCall<'a, C>
8041 where
8042 St: AsRef<str>,
8043 {
8044 self._scopes.insert(String::from(scope.as_ref()));
8045 self
8046 }
8047 /// Identifies the authorization scope(s) for the method you are building.
8048 ///
8049 /// See [`Self::add_scope()`] for details.
8050 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyCreateCall<'a, C>
8051 where
8052 I: IntoIterator<Item = St>,
8053 St: AsRef<str>,
8054 {
8055 self._scopes
8056 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
8057 self
8058 }
8059
8060 /// Removes all scopes, and no default scope will be used either.
8061 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
8062 /// for details).
8063 pub fn clear_scopes(mut self) -> ProjectPolicyCreateCall<'a, C> {
8064 self._scopes.clear();
8065 self
8066 }
8067}
8068
8069/// Deletes a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or organization policy does not exist.
8070///
8071/// A builder for the *policies.delete* method supported by a *project* resource.
8072/// It is not used directly, but through a [`ProjectMethods`] instance.
8073///
8074/// # Example
8075///
8076/// Instantiate a resource method builder
8077///
8078/// ```test_harness,no_run
8079/// # extern crate hyper;
8080/// # extern crate hyper_rustls;
8081/// # extern crate google_orgpolicy2 as orgpolicy2;
8082/// # async fn dox() {
8083/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
8084///
8085/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
8086/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
8087/// # .with_native_roots()
8088/// # .unwrap()
8089/// # .https_only()
8090/// # .enable_http2()
8091/// # .build();
8092///
8093/// # let executor = hyper_util::rt::TokioExecutor::new();
8094/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
8095/// # secret,
8096/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
8097/// # yup_oauth2::client::CustomHyperClientBuilder::from(
8098/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
8099/// # ),
8100/// # ).build().await.unwrap();
8101///
8102/// # let client = hyper_util::client::legacy::Client::builder(
8103/// # hyper_util::rt::TokioExecutor::new()
8104/// # )
8105/// # .build(
8106/// # hyper_rustls::HttpsConnectorBuilder::new()
8107/// # .with_native_roots()
8108/// # .unwrap()
8109/// # .https_or_http()
8110/// # .enable_http2()
8111/// # .build()
8112/// # );
8113/// # let mut hub = OrgPolicyAPI::new(client, auth);
8114/// // You can configure optional parameters by calling the respective setters at will, and
8115/// // execute the final call using `doit()`.
8116/// // Values shown here are possibly random and not representative !
8117/// let result = hub.projects().policies_delete("name")
8118/// .etag("duo")
8119/// .doit().await;
8120/// # }
8121/// ```
8122pub struct ProjectPolicyDeleteCall<'a, C>
8123where
8124 C: 'a,
8125{
8126 hub: &'a OrgPolicyAPI<C>,
8127 _name: String,
8128 _etag: Option<String>,
8129 _delegate: Option<&'a mut dyn common::Delegate>,
8130 _additional_params: HashMap<String, String>,
8131 _scopes: BTreeSet<String>,
8132}
8133
8134impl<'a, C> common::CallBuilder for ProjectPolicyDeleteCall<'a, C> {}
8135
8136impl<'a, C> ProjectPolicyDeleteCall<'a, C>
8137where
8138 C: common::Connector,
8139{
8140 /// Perform the operation you have build so far.
8141 pub async fn doit(mut self) -> common::Result<(common::Response, GoogleProtobufEmpty)> {
8142 use std::borrow::Cow;
8143 use std::io::{Read, Seek};
8144
8145 use common::{url::Params, ToParts};
8146 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
8147
8148 let mut dd = common::DefaultDelegate;
8149 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
8150 dlg.begin(common::MethodInfo {
8151 id: "orgpolicy.projects.policies.delete",
8152 http_method: hyper::Method::DELETE,
8153 });
8154
8155 for &field in ["alt", "name", "etag"].iter() {
8156 if self._additional_params.contains_key(field) {
8157 dlg.finished(false);
8158 return Err(common::Error::FieldClash(field));
8159 }
8160 }
8161
8162 let mut params = Params::with_capacity(4 + self._additional_params.len());
8163 params.push("name", self._name);
8164 if let Some(value) = self._etag.as_ref() {
8165 params.push("etag", value);
8166 }
8167
8168 params.extend(self._additional_params.iter());
8169
8170 params.push("alt", "json");
8171 let mut url = self.hub._base_url.clone() + "v2/{+name}";
8172 if self._scopes.is_empty() {
8173 self._scopes
8174 .insert(Scope::CloudPlatform.as_ref().to_string());
8175 }
8176
8177 #[allow(clippy::single_element_loop)]
8178 for &(find_this, param_name) in [("{+name}", "name")].iter() {
8179 url = params.uri_replacement(url, param_name, find_this, true);
8180 }
8181 {
8182 let to_remove = ["name"];
8183 params.remove_params(&to_remove);
8184 }
8185
8186 let url = params.parse_with_url(&url);
8187
8188 loop {
8189 let token = match self
8190 .hub
8191 .auth
8192 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
8193 .await
8194 {
8195 Ok(token) => token,
8196 Err(e) => match dlg.token(e) {
8197 Ok(token) => token,
8198 Err(e) => {
8199 dlg.finished(false);
8200 return Err(common::Error::MissingToken(e));
8201 }
8202 },
8203 };
8204 let mut req_result = {
8205 let client = &self.hub.client;
8206 dlg.pre_request();
8207 let mut req_builder = hyper::Request::builder()
8208 .method(hyper::Method::DELETE)
8209 .uri(url.as_str())
8210 .header(USER_AGENT, self.hub._user_agent.clone());
8211
8212 if let Some(token) = token.as_ref() {
8213 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
8214 }
8215
8216 let request = req_builder
8217 .header(CONTENT_LENGTH, 0_u64)
8218 .body(common::to_body::<String>(None));
8219
8220 client.request(request.unwrap()).await
8221 };
8222
8223 match req_result {
8224 Err(err) => {
8225 if let common::Retry::After(d) = dlg.http_error(&err) {
8226 sleep(d).await;
8227 continue;
8228 }
8229 dlg.finished(false);
8230 return Err(common::Error::HttpError(err));
8231 }
8232 Ok(res) => {
8233 let (mut parts, body) = res.into_parts();
8234 let mut body = common::Body::new(body);
8235 if !parts.status.is_success() {
8236 let bytes = common::to_bytes(body).await.unwrap_or_default();
8237 let error = serde_json::from_str(&common::to_string(&bytes));
8238 let response = common::to_response(parts, bytes.into());
8239
8240 if let common::Retry::After(d) =
8241 dlg.http_failure(&response, error.as_ref().ok())
8242 {
8243 sleep(d).await;
8244 continue;
8245 }
8246
8247 dlg.finished(false);
8248
8249 return Err(match error {
8250 Ok(value) => common::Error::BadRequest(value),
8251 _ => common::Error::Failure(response),
8252 });
8253 }
8254 let response = {
8255 let bytes = common::to_bytes(body).await.unwrap_or_default();
8256 let encoded = common::to_string(&bytes);
8257 match serde_json::from_str(&encoded) {
8258 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
8259 Err(error) => {
8260 dlg.response_json_decode_error(&encoded, &error);
8261 return Err(common::Error::JsonDecodeError(
8262 encoded.to_string(),
8263 error,
8264 ));
8265 }
8266 }
8267 };
8268
8269 dlg.finished(true);
8270 return Ok(response);
8271 }
8272 }
8273 }
8274 }
8275
8276 /// Required. Name of the policy to delete. See the policy entry for naming rules.
8277 ///
8278 /// Sets the *name* path property to the given value.
8279 ///
8280 /// Even though the property as already been set when instantiating this call,
8281 /// we provide this method for API completeness.
8282 pub fn name(mut self, new_value: &str) -> ProjectPolicyDeleteCall<'a, C> {
8283 self._name = new_value.to_string();
8284 self
8285 }
8286 /// Optional. The current etag of policy. If an etag is provided and does not match the current etag of the policy, deletion will be blocked and an ABORTED error will be returned.
8287 ///
8288 /// Sets the *etag* query property to the given value.
8289 pub fn etag(mut self, new_value: &str) -> ProjectPolicyDeleteCall<'a, C> {
8290 self._etag = Some(new_value.to_string());
8291 self
8292 }
8293 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
8294 /// while executing the actual API request.
8295 ///
8296 /// ````text
8297 /// It should be used to handle progress information, and to implement a certain level of resilience.
8298 /// ````
8299 ///
8300 /// Sets the *delegate* property to the given value.
8301 pub fn delegate(
8302 mut self,
8303 new_value: &'a mut dyn common::Delegate,
8304 ) -> ProjectPolicyDeleteCall<'a, C> {
8305 self._delegate = Some(new_value);
8306 self
8307 }
8308
8309 /// Set any additional parameter of the query string used in the request.
8310 /// It should be used to set parameters which are not yet available through their own
8311 /// setters.
8312 ///
8313 /// Please note that this method must not be used to set any of the known parameters
8314 /// which have their own setter method. If done anyway, the request will fail.
8315 ///
8316 /// # Additional Parameters
8317 ///
8318 /// * *$.xgafv* (query-string) - V1 error format.
8319 /// * *access_token* (query-string) - OAuth access token.
8320 /// * *alt* (query-string) - Data format for response.
8321 /// * *callback* (query-string) - JSONP
8322 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
8323 /// * *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.
8324 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
8325 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
8326 /// * *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.
8327 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
8328 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
8329 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyDeleteCall<'a, C>
8330 where
8331 T: AsRef<str>,
8332 {
8333 self._additional_params
8334 .insert(name.as_ref().to_string(), value.as_ref().to_string());
8335 self
8336 }
8337
8338 /// Identifies the authorization scope for the method you are building.
8339 ///
8340 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
8341 /// [`Scope::CloudPlatform`].
8342 ///
8343 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
8344 /// tokens for more than one scope.
8345 ///
8346 /// Usually there is more than one suitable scope to authorize an operation, some of which may
8347 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
8348 /// sufficient, a read-write scope will do as well.
8349 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyDeleteCall<'a, C>
8350 where
8351 St: AsRef<str>,
8352 {
8353 self._scopes.insert(String::from(scope.as_ref()));
8354 self
8355 }
8356 /// Identifies the authorization scope(s) for the method you are building.
8357 ///
8358 /// See [`Self::add_scope()`] for details.
8359 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyDeleteCall<'a, C>
8360 where
8361 I: IntoIterator<Item = St>,
8362 St: AsRef<str>,
8363 {
8364 self._scopes
8365 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
8366 self
8367 }
8368
8369 /// Removes all scopes, and no default scope will be used either.
8370 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
8371 /// for details).
8372 pub fn clear_scopes(mut self) -> ProjectPolicyDeleteCall<'a, C> {
8373 self._scopes.clear();
8374 self
8375 }
8376}
8377
8378/// Gets a policy on a resource. If no policy is set on the resource, `NOT_FOUND` is returned. The `etag` value can be used with `UpdatePolicy()` to update a policy during read-modify-write.
8379///
8380/// A builder for the *policies.get* method supported by a *project* resource.
8381/// It is not used directly, but through a [`ProjectMethods`] instance.
8382///
8383/// # Example
8384///
8385/// Instantiate a resource method builder
8386///
8387/// ```test_harness,no_run
8388/// # extern crate hyper;
8389/// # extern crate hyper_rustls;
8390/// # extern crate google_orgpolicy2 as orgpolicy2;
8391/// # async fn dox() {
8392/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
8393///
8394/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
8395/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
8396/// # .with_native_roots()
8397/// # .unwrap()
8398/// # .https_only()
8399/// # .enable_http2()
8400/// # .build();
8401///
8402/// # let executor = hyper_util::rt::TokioExecutor::new();
8403/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
8404/// # secret,
8405/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
8406/// # yup_oauth2::client::CustomHyperClientBuilder::from(
8407/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
8408/// # ),
8409/// # ).build().await.unwrap();
8410///
8411/// # let client = hyper_util::client::legacy::Client::builder(
8412/// # hyper_util::rt::TokioExecutor::new()
8413/// # )
8414/// # .build(
8415/// # hyper_rustls::HttpsConnectorBuilder::new()
8416/// # .with_native_roots()
8417/// # .unwrap()
8418/// # .https_or_http()
8419/// # .enable_http2()
8420/// # .build()
8421/// # );
8422/// # let mut hub = OrgPolicyAPI::new(client, auth);
8423/// // You can configure optional parameters by calling the respective setters at will, and
8424/// // execute the final call using `doit()`.
8425/// // Values shown here are possibly random and not representative !
8426/// let result = hub.projects().policies_get("name")
8427/// .doit().await;
8428/// # }
8429/// ```
8430pub struct ProjectPolicyGetCall<'a, C>
8431where
8432 C: 'a,
8433{
8434 hub: &'a OrgPolicyAPI<C>,
8435 _name: String,
8436 _delegate: Option<&'a mut dyn common::Delegate>,
8437 _additional_params: HashMap<String, String>,
8438 _scopes: BTreeSet<String>,
8439}
8440
8441impl<'a, C> common::CallBuilder for ProjectPolicyGetCall<'a, C> {}
8442
8443impl<'a, C> ProjectPolicyGetCall<'a, C>
8444where
8445 C: common::Connector,
8446{
8447 /// Perform the operation you have build so far.
8448 pub async fn doit(
8449 mut self,
8450 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
8451 use std::borrow::Cow;
8452 use std::io::{Read, Seek};
8453
8454 use common::{url::Params, ToParts};
8455 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
8456
8457 let mut dd = common::DefaultDelegate;
8458 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
8459 dlg.begin(common::MethodInfo {
8460 id: "orgpolicy.projects.policies.get",
8461 http_method: hyper::Method::GET,
8462 });
8463
8464 for &field in ["alt", "name"].iter() {
8465 if self._additional_params.contains_key(field) {
8466 dlg.finished(false);
8467 return Err(common::Error::FieldClash(field));
8468 }
8469 }
8470
8471 let mut params = Params::with_capacity(3 + self._additional_params.len());
8472 params.push("name", self._name);
8473
8474 params.extend(self._additional_params.iter());
8475
8476 params.push("alt", "json");
8477 let mut url = self.hub._base_url.clone() + "v2/{+name}";
8478 if self._scopes.is_empty() {
8479 self._scopes
8480 .insert(Scope::CloudPlatform.as_ref().to_string());
8481 }
8482
8483 #[allow(clippy::single_element_loop)]
8484 for &(find_this, param_name) in [("{+name}", "name")].iter() {
8485 url = params.uri_replacement(url, param_name, find_this, true);
8486 }
8487 {
8488 let to_remove = ["name"];
8489 params.remove_params(&to_remove);
8490 }
8491
8492 let url = params.parse_with_url(&url);
8493
8494 loop {
8495 let token = match self
8496 .hub
8497 .auth
8498 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
8499 .await
8500 {
8501 Ok(token) => token,
8502 Err(e) => match dlg.token(e) {
8503 Ok(token) => token,
8504 Err(e) => {
8505 dlg.finished(false);
8506 return Err(common::Error::MissingToken(e));
8507 }
8508 },
8509 };
8510 let mut req_result = {
8511 let client = &self.hub.client;
8512 dlg.pre_request();
8513 let mut req_builder = hyper::Request::builder()
8514 .method(hyper::Method::GET)
8515 .uri(url.as_str())
8516 .header(USER_AGENT, self.hub._user_agent.clone());
8517
8518 if let Some(token) = token.as_ref() {
8519 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
8520 }
8521
8522 let request = req_builder
8523 .header(CONTENT_LENGTH, 0_u64)
8524 .body(common::to_body::<String>(None));
8525
8526 client.request(request.unwrap()).await
8527 };
8528
8529 match req_result {
8530 Err(err) => {
8531 if let common::Retry::After(d) = dlg.http_error(&err) {
8532 sleep(d).await;
8533 continue;
8534 }
8535 dlg.finished(false);
8536 return Err(common::Error::HttpError(err));
8537 }
8538 Ok(res) => {
8539 let (mut parts, body) = res.into_parts();
8540 let mut body = common::Body::new(body);
8541 if !parts.status.is_success() {
8542 let bytes = common::to_bytes(body).await.unwrap_or_default();
8543 let error = serde_json::from_str(&common::to_string(&bytes));
8544 let response = common::to_response(parts, bytes.into());
8545
8546 if let common::Retry::After(d) =
8547 dlg.http_failure(&response, error.as_ref().ok())
8548 {
8549 sleep(d).await;
8550 continue;
8551 }
8552
8553 dlg.finished(false);
8554
8555 return Err(match error {
8556 Ok(value) => common::Error::BadRequest(value),
8557 _ => common::Error::Failure(response),
8558 });
8559 }
8560 let response = {
8561 let bytes = common::to_bytes(body).await.unwrap_or_default();
8562 let encoded = common::to_string(&bytes);
8563 match serde_json::from_str(&encoded) {
8564 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
8565 Err(error) => {
8566 dlg.response_json_decode_error(&encoded, &error);
8567 return Err(common::Error::JsonDecodeError(
8568 encoded.to_string(),
8569 error,
8570 ));
8571 }
8572 }
8573 };
8574
8575 dlg.finished(true);
8576 return Ok(response);
8577 }
8578 }
8579 }
8580 }
8581
8582 /// Required. Resource name of the policy. See Policy for naming requirements.
8583 ///
8584 /// Sets the *name* path property to the given value.
8585 ///
8586 /// Even though the property as already been set when instantiating this call,
8587 /// we provide this method for API completeness.
8588 pub fn name(mut self, new_value: &str) -> ProjectPolicyGetCall<'a, C> {
8589 self._name = new_value.to_string();
8590 self
8591 }
8592 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
8593 /// while executing the actual API request.
8594 ///
8595 /// ````text
8596 /// It should be used to handle progress information, and to implement a certain level of resilience.
8597 /// ````
8598 ///
8599 /// Sets the *delegate* property to the given value.
8600 pub fn delegate(
8601 mut self,
8602 new_value: &'a mut dyn common::Delegate,
8603 ) -> ProjectPolicyGetCall<'a, C> {
8604 self._delegate = Some(new_value);
8605 self
8606 }
8607
8608 /// Set any additional parameter of the query string used in the request.
8609 /// It should be used to set parameters which are not yet available through their own
8610 /// setters.
8611 ///
8612 /// Please note that this method must not be used to set any of the known parameters
8613 /// which have their own setter method. If done anyway, the request will fail.
8614 ///
8615 /// # Additional Parameters
8616 ///
8617 /// * *$.xgafv* (query-string) - V1 error format.
8618 /// * *access_token* (query-string) - OAuth access token.
8619 /// * *alt* (query-string) - Data format for response.
8620 /// * *callback* (query-string) - JSONP
8621 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
8622 /// * *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.
8623 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
8624 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
8625 /// * *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.
8626 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
8627 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
8628 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyGetCall<'a, C>
8629 where
8630 T: AsRef<str>,
8631 {
8632 self._additional_params
8633 .insert(name.as_ref().to_string(), value.as_ref().to_string());
8634 self
8635 }
8636
8637 /// Identifies the authorization scope for the method you are building.
8638 ///
8639 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
8640 /// [`Scope::CloudPlatform`].
8641 ///
8642 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
8643 /// tokens for more than one scope.
8644 ///
8645 /// Usually there is more than one suitable scope to authorize an operation, some of which may
8646 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
8647 /// sufficient, a read-write scope will do as well.
8648 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyGetCall<'a, C>
8649 where
8650 St: AsRef<str>,
8651 {
8652 self._scopes.insert(String::from(scope.as_ref()));
8653 self
8654 }
8655 /// Identifies the authorization scope(s) for the method you are building.
8656 ///
8657 /// See [`Self::add_scope()`] for details.
8658 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyGetCall<'a, C>
8659 where
8660 I: IntoIterator<Item = St>,
8661 St: AsRef<str>,
8662 {
8663 self._scopes
8664 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
8665 self
8666 }
8667
8668 /// Removes all scopes, and no default scope will be used either.
8669 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
8670 /// for details).
8671 pub fn clear_scopes(mut self) -> ProjectPolicyGetCall<'a, C> {
8672 self._scopes.clear();
8673 self
8674 }
8675}
8676
8677/// Gets the effective policy on a resource. This is the result of merging policies in the resource hierarchy and evaluating conditions. The returned policy will not have an `etag` or `condition` set because it is an evaluated policy across multiple resources. Subtrees of Resource Manager resource hierarchy with 'under:' prefix will not be expanded.
8678///
8679/// A builder for the *policies.getEffectivePolicy* method supported by a *project* resource.
8680/// It is not used directly, but through a [`ProjectMethods`] instance.
8681///
8682/// # Example
8683///
8684/// Instantiate a resource method builder
8685///
8686/// ```test_harness,no_run
8687/// # extern crate hyper;
8688/// # extern crate hyper_rustls;
8689/// # extern crate google_orgpolicy2 as orgpolicy2;
8690/// # async fn dox() {
8691/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
8692///
8693/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
8694/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
8695/// # .with_native_roots()
8696/// # .unwrap()
8697/// # .https_only()
8698/// # .enable_http2()
8699/// # .build();
8700///
8701/// # let executor = hyper_util::rt::TokioExecutor::new();
8702/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
8703/// # secret,
8704/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
8705/// # yup_oauth2::client::CustomHyperClientBuilder::from(
8706/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
8707/// # ),
8708/// # ).build().await.unwrap();
8709///
8710/// # let client = hyper_util::client::legacy::Client::builder(
8711/// # hyper_util::rt::TokioExecutor::new()
8712/// # )
8713/// # .build(
8714/// # hyper_rustls::HttpsConnectorBuilder::new()
8715/// # .with_native_roots()
8716/// # .unwrap()
8717/// # .https_or_http()
8718/// # .enable_http2()
8719/// # .build()
8720/// # );
8721/// # let mut hub = OrgPolicyAPI::new(client, auth);
8722/// // You can configure optional parameters by calling the respective setters at will, and
8723/// // execute the final call using `doit()`.
8724/// // Values shown here are possibly random and not representative !
8725/// let result = hub.projects().policies_get_effective_policy("name")
8726/// .doit().await;
8727/// # }
8728/// ```
8729pub struct ProjectPolicyGetEffectivePolicyCall<'a, C>
8730where
8731 C: 'a,
8732{
8733 hub: &'a OrgPolicyAPI<C>,
8734 _name: String,
8735 _delegate: Option<&'a mut dyn common::Delegate>,
8736 _additional_params: HashMap<String, String>,
8737 _scopes: BTreeSet<String>,
8738}
8739
8740impl<'a, C> common::CallBuilder for ProjectPolicyGetEffectivePolicyCall<'a, C> {}
8741
8742impl<'a, C> ProjectPolicyGetEffectivePolicyCall<'a, C>
8743where
8744 C: common::Connector,
8745{
8746 /// Perform the operation you have build so far.
8747 pub async fn doit(
8748 mut self,
8749 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
8750 use std::borrow::Cow;
8751 use std::io::{Read, Seek};
8752
8753 use common::{url::Params, ToParts};
8754 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
8755
8756 let mut dd = common::DefaultDelegate;
8757 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
8758 dlg.begin(common::MethodInfo {
8759 id: "orgpolicy.projects.policies.getEffectivePolicy",
8760 http_method: hyper::Method::GET,
8761 });
8762
8763 for &field in ["alt", "name"].iter() {
8764 if self._additional_params.contains_key(field) {
8765 dlg.finished(false);
8766 return Err(common::Error::FieldClash(field));
8767 }
8768 }
8769
8770 let mut params = Params::with_capacity(3 + self._additional_params.len());
8771 params.push("name", self._name);
8772
8773 params.extend(self._additional_params.iter());
8774
8775 params.push("alt", "json");
8776 let mut url = self.hub._base_url.clone() + "v2/{+name}:getEffectivePolicy";
8777 if self._scopes.is_empty() {
8778 self._scopes
8779 .insert(Scope::CloudPlatform.as_ref().to_string());
8780 }
8781
8782 #[allow(clippy::single_element_loop)]
8783 for &(find_this, param_name) in [("{+name}", "name")].iter() {
8784 url = params.uri_replacement(url, param_name, find_this, true);
8785 }
8786 {
8787 let to_remove = ["name"];
8788 params.remove_params(&to_remove);
8789 }
8790
8791 let url = params.parse_with_url(&url);
8792
8793 loop {
8794 let token = match self
8795 .hub
8796 .auth
8797 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
8798 .await
8799 {
8800 Ok(token) => token,
8801 Err(e) => match dlg.token(e) {
8802 Ok(token) => token,
8803 Err(e) => {
8804 dlg.finished(false);
8805 return Err(common::Error::MissingToken(e));
8806 }
8807 },
8808 };
8809 let mut req_result = {
8810 let client = &self.hub.client;
8811 dlg.pre_request();
8812 let mut req_builder = hyper::Request::builder()
8813 .method(hyper::Method::GET)
8814 .uri(url.as_str())
8815 .header(USER_AGENT, self.hub._user_agent.clone());
8816
8817 if let Some(token) = token.as_ref() {
8818 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
8819 }
8820
8821 let request = req_builder
8822 .header(CONTENT_LENGTH, 0_u64)
8823 .body(common::to_body::<String>(None));
8824
8825 client.request(request.unwrap()).await
8826 };
8827
8828 match req_result {
8829 Err(err) => {
8830 if let common::Retry::After(d) = dlg.http_error(&err) {
8831 sleep(d).await;
8832 continue;
8833 }
8834 dlg.finished(false);
8835 return Err(common::Error::HttpError(err));
8836 }
8837 Ok(res) => {
8838 let (mut parts, body) = res.into_parts();
8839 let mut body = common::Body::new(body);
8840 if !parts.status.is_success() {
8841 let bytes = common::to_bytes(body).await.unwrap_or_default();
8842 let error = serde_json::from_str(&common::to_string(&bytes));
8843 let response = common::to_response(parts, bytes.into());
8844
8845 if let common::Retry::After(d) =
8846 dlg.http_failure(&response, error.as_ref().ok())
8847 {
8848 sleep(d).await;
8849 continue;
8850 }
8851
8852 dlg.finished(false);
8853
8854 return Err(match error {
8855 Ok(value) => common::Error::BadRequest(value),
8856 _ => common::Error::Failure(response),
8857 });
8858 }
8859 let response = {
8860 let bytes = common::to_bytes(body).await.unwrap_or_default();
8861 let encoded = common::to_string(&bytes);
8862 match serde_json::from_str(&encoded) {
8863 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
8864 Err(error) => {
8865 dlg.response_json_decode_error(&encoded, &error);
8866 return Err(common::Error::JsonDecodeError(
8867 encoded.to_string(),
8868 error,
8869 ));
8870 }
8871 }
8872 };
8873
8874 dlg.finished(true);
8875 return Ok(response);
8876 }
8877 }
8878 }
8879 }
8880
8881 /// Required. The effective policy to compute. See Policy for naming requirements.
8882 ///
8883 /// Sets the *name* path property to the given value.
8884 ///
8885 /// Even though the property as already been set when instantiating this call,
8886 /// we provide this method for API completeness.
8887 pub fn name(mut self, new_value: &str) -> ProjectPolicyGetEffectivePolicyCall<'a, C> {
8888 self._name = new_value.to_string();
8889 self
8890 }
8891 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
8892 /// while executing the actual API request.
8893 ///
8894 /// ````text
8895 /// It should be used to handle progress information, and to implement a certain level of resilience.
8896 /// ````
8897 ///
8898 /// Sets the *delegate* property to the given value.
8899 pub fn delegate(
8900 mut self,
8901 new_value: &'a mut dyn common::Delegate,
8902 ) -> ProjectPolicyGetEffectivePolicyCall<'a, C> {
8903 self._delegate = Some(new_value);
8904 self
8905 }
8906
8907 /// Set any additional parameter of the query string used in the request.
8908 /// It should be used to set parameters which are not yet available through their own
8909 /// setters.
8910 ///
8911 /// Please note that this method must not be used to set any of the known parameters
8912 /// which have their own setter method. If done anyway, the request will fail.
8913 ///
8914 /// # Additional Parameters
8915 ///
8916 /// * *$.xgafv* (query-string) - V1 error format.
8917 /// * *access_token* (query-string) - OAuth access token.
8918 /// * *alt* (query-string) - Data format for response.
8919 /// * *callback* (query-string) - JSONP
8920 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
8921 /// * *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.
8922 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
8923 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
8924 /// * *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.
8925 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
8926 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
8927 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyGetEffectivePolicyCall<'a, C>
8928 where
8929 T: AsRef<str>,
8930 {
8931 self._additional_params
8932 .insert(name.as_ref().to_string(), value.as_ref().to_string());
8933 self
8934 }
8935
8936 /// Identifies the authorization scope for the method you are building.
8937 ///
8938 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
8939 /// [`Scope::CloudPlatform`].
8940 ///
8941 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
8942 /// tokens for more than one scope.
8943 ///
8944 /// Usually there is more than one suitable scope to authorize an operation, some of which may
8945 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
8946 /// sufficient, a read-write scope will do as well.
8947 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyGetEffectivePolicyCall<'a, C>
8948 where
8949 St: AsRef<str>,
8950 {
8951 self._scopes.insert(String::from(scope.as_ref()));
8952 self
8953 }
8954 /// Identifies the authorization scope(s) for the method you are building.
8955 ///
8956 /// See [`Self::add_scope()`] for details.
8957 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyGetEffectivePolicyCall<'a, C>
8958 where
8959 I: IntoIterator<Item = St>,
8960 St: AsRef<str>,
8961 {
8962 self._scopes
8963 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
8964 self
8965 }
8966
8967 /// Removes all scopes, and no default scope will be used either.
8968 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
8969 /// for details).
8970 pub fn clear_scopes(mut self) -> ProjectPolicyGetEffectivePolicyCall<'a, C> {
8971 self._scopes.clear();
8972 self
8973 }
8974}
8975
8976/// Retrieves all of the policies that exist on a particular resource.
8977///
8978/// A builder for the *policies.list* method supported by a *project* resource.
8979/// It is not used directly, but through a [`ProjectMethods`] instance.
8980///
8981/// # Example
8982///
8983/// Instantiate a resource method builder
8984///
8985/// ```test_harness,no_run
8986/// # extern crate hyper;
8987/// # extern crate hyper_rustls;
8988/// # extern crate google_orgpolicy2 as orgpolicy2;
8989/// # async fn dox() {
8990/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
8991///
8992/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
8993/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
8994/// # .with_native_roots()
8995/// # .unwrap()
8996/// # .https_only()
8997/// # .enable_http2()
8998/// # .build();
8999///
9000/// # let executor = hyper_util::rt::TokioExecutor::new();
9001/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
9002/// # secret,
9003/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
9004/// # yup_oauth2::client::CustomHyperClientBuilder::from(
9005/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
9006/// # ),
9007/// # ).build().await.unwrap();
9008///
9009/// # let client = hyper_util::client::legacy::Client::builder(
9010/// # hyper_util::rt::TokioExecutor::new()
9011/// # )
9012/// # .build(
9013/// # hyper_rustls::HttpsConnectorBuilder::new()
9014/// # .with_native_roots()
9015/// # .unwrap()
9016/// # .https_or_http()
9017/// # .enable_http2()
9018/// # .build()
9019/// # );
9020/// # let mut hub = OrgPolicyAPI::new(client, auth);
9021/// // You can configure optional parameters by calling the respective setters at will, and
9022/// // execute the final call using `doit()`.
9023/// // Values shown here are possibly random and not representative !
9024/// let result = hub.projects().policies_list("parent")
9025/// .page_token("kasd")
9026/// .page_size(-24)
9027/// .doit().await;
9028/// # }
9029/// ```
9030pub struct ProjectPolicyListCall<'a, C>
9031where
9032 C: 'a,
9033{
9034 hub: &'a OrgPolicyAPI<C>,
9035 _parent: String,
9036 _page_token: Option<String>,
9037 _page_size: Option<i32>,
9038 _delegate: Option<&'a mut dyn common::Delegate>,
9039 _additional_params: HashMap<String, String>,
9040 _scopes: BTreeSet<String>,
9041}
9042
9043impl<'a, C> common::CallBuilder for ProjectPolicyListCall<'a, C> {}
9044
9045impl<'a, C> ProjectPolicyListCall<'a, C>
9046where
9047 C: common::Connector,
9048{
9049 /// Perform the operation you have build so far.
9050 pub async fn doit(
9051 mut self,
9052 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2ListPoliciesResponse)> {
9053 use std::borrow::Cow;
9054 use std::io::{Read, Seek};
9055
9056 use common::{url::Params, ToParts};
9057 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
9058
9059 let mut dd = common::DefaultDelegate;
9060 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
9061 dlg.begin(common::MethodInfo {
9062 id: "orgpolicy.projects.policies.list",
9063 http_method: hyper::Method::GET,
9064 });
9065
9066 for &field in ["alt", "parent", "pageToken", "pageSize"].iter() {
9067 if self._additional_params.contains_key(field) {
9068 dlg.finished(false);
9069 return Err(common::Error::FieldClash(field));
9070 }
9071 }
9072
9073 let mut params = Params::with_capacity(5 + self._additional_params.len());
9074 params.push("parent", self._parent);
9075 if let Some(value) = self._page_token.as_ref() {
9076 params.push("pageToken", value);
9077 }
9078 if let Some(value) = self._page_size.as_ref() {
9079 params.push("pageSize", value.to_string());
9080 }
9081
9082 params.extend(self._additional_params.iter());
9083
9084 params.push("alt", "json");
9085 let mut url = self.hub._base_url.clone() + "v2/{+parent}/policies";
9086 if self._scopes.is_empty() {
9087 self._scopes
9088 .insert(Scope::CloudPlatform.as_ref().to_string());
9089 }
9090
9091 #[allow(clippy::single_element_loop)]
9092 for &(find_this, param_name) in [("{+parent}", "parent")].iter() {
9093 url = params.uri_replacement(url, param_name, find_this, true);
9094 }
9095 {
9096 let to_remove = ["parent"];
9097 params.remove_params(&to_remove);
9098 }
9099
9100 let url = params.parse_with_url(&url);
9101
9102 loop {
9103 let token = match self
9104 .hub
9105 .auth
9106 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
9107 .await
9108 {
9109 Ok(token) => token,
9110 Err(e) => match dlg.token(e) {
9111 Ok(token) => token,
9112 Err(e) => {
9113 dlg.finished(false);
9114 return Err(common::Error::MissingToken(e));
9115 }
9116 },
9117 };
9118 let mut req_result = {
9119 let client = &self.hub.client;
9120 dlg.pre_request();
9121 let mut req_builder = hyper::Request::builder()
9122 .method(hyper::Method::GET)
9123 .uri(url.as_str())
9124 .header(USER_AGENT, self.hub._user_agent.clone());
9125
9126 if let Some(token) = token.as_ref() {
9127 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
9128 }
9129
9130 let request = req_builder
9131 .header(CONTENT_LENGTH, 0_u64)
9132 .body(common::to_body::<String>(None));
9133
9134 client.request(request.unwrap()).await
9135 };
9136
9137 match req_result {
9138 Err(err) => {
9139 if let common::Retry::After(d) = dlg.http_error(&err) {
9140 sleep(d).await;
9141 continue;
9142 }
9143 dlg.finished(false);
9144 return Err(common::Error::HttpError(err));
9145 }
9146 Ok(res) => {
9147 let (mut parts, body) = res.into_parts();
9148 let mut body = common::Body::new(body);
9149 if !parts.status.is_success() {
9150 let bytes = common::to_bytes(body).await.unwrap_or_default();
9151 let error = serde_json::from_str(&common::to_string(&bytes));
9152 let response = common::to_response(parts, bytes.into());
9153
9154 if let common::Retry::After(d) =
9155 dlg.http_failure(&response, error.as_ref().ok())
9156 {
9157 sleep(d).await;
9158 continue;
9159 }
9160
9161 dlg.finished(false);
9162
9163 return Err(match error {
9164 Ok(value) => common::Error::BadRequest(value),
9165 _ => common::Error::Failure(response),
9166 });
9167 }
9168 let response = {
9169 let bytes = common::to_bytes(body).await.unwrap_or_default();
9170 let encoded = common::to_string(&bytes);
9171 match serde_json::from_str(&encoded) {
9172 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
9173 Err(error) => {
9174 dlg.response_json_decode_error(&encoded, &error);
9175 return Err(common::Error::JsonDecodeError(
9176 encoded.to_string(),
9177 error,
9178 ));
9179 }
9180 }
9181 };
9182
9183 dlg.finished(true);
9184 return Ok(response);
9185 }
9186 }
9187 }
9188 }
9189
9190 /// Required. The target Google Cloud resource that parents the set of constraints and policies that will be returned from this call. Must be in one of the following forms: * `projects/{project_number}` * `projects/{project_id}` * `folders/{folder_id}` * `organizations/{organization_id}`
9191 ///
9192 /// Sets the *parent* path property to the given value.
9193 ///
9194 /// Even though the property as already been set when instantiating this call,
9195 /// we provide this method for API completeness.
9196 pub fn parent(mut self, new_value: &str) -> ProjectPolicyListCall<'a, C> {
9197 self._parent = new_value.to_string();
9198 self
9199 }
9200 /// Page token used to retrieve the next page. This is currently unsupported and will be ignored. The server may at any point start using this field.
9201 ///
9202 /// Sets the *page token* query property to the given value.
9203 pub fn page_token(mut self, new_value: &str) -> ProjectPolicyListCall<'a, C> {
9204 self._page_token = Some(new_value.to_string());
9205 self
9206 }
9207 /// Size of the pages to be returned. This is currently unsupported and will be ignored. The server may at any point start using this field to limit page size.
9208 ///
9209 /// Sets the *page size* query property to the given value.
9210 pub fn page_size(mut self, new_value: i32) -> ProjectPolicyListCall<'a, C> {
9211 self._page_size = Some(new_value);
9212 self
9213 }
9214 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
9215 /// while executing the actual API request.
9216 ///
9217 /// ````text
9218 /// It should be used to handle progress information, and to implement a certain level of resilience.
9219 /// ````
9220 ///
9221 /// Sets the *delegate* property to the given value.
9222 pub fn delegate(
9223 mut self,
9224 new_value: &'a mut dyn common::Delegate,
9225 ) -> ProjectPolicyListCall<'a, C> {
9226 self._delegate = Some(new_value);
9227 self
9228 }
9229
9230 /// Set any additional parameter of the query string used in the request.
9231 /// It should be used to set parameters which are not yet available through their own
9232 /// setters.
9233 ///
9234 /// Please note that this method must not be used to set any of the known parameters
9235 /// which have their own setter method. If done anyway, the request will fail.
9236 ///
9237 /// # Additional Parameters
9238 ///
9239 /// * *$.xgafv* (query-string) - V1 error format.
9240 /// * *access_token* (query-string) - OAuth access token.
9241 /// * *alt* (query-string) - Data format for response.
9242 /// * *callback* (query-string) - JSONP
9243 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
9244 /// * *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.
9245 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
9246 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
9247 /// * *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.
9248 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
9249 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
9250 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyListCall<'a, C>
9251 where
9252 T: AsRef<str>,
9253 {
9254 self._additional_params
9255 .insert(name.as_ref().to_string(), value.as_ref().to_string());
9256 self
9257 }
9258
9259 /// Identifies the authorization scope for the method you are building.
9260 ///
9261 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
9262 /// [`Scope::CloudPlatform`].
9263 ///
9264 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
9265 /// tokens for more than one scope.
9266 ///
9267 /// Usually there is more than one suitable scope to authorize an operation, some of which may
9268 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
9269 /// sufficient, a read-write scope will do as well.
9270 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyListCall<'a, C>
9271 where
9272 St: AsRef<str>,
9273 {
9274 self._scopes.insert(String::from(scope.as_ref()));
9275 self
9276 }
9277 /// Identifies the authorization scope(s) for the method you are building.
9278 ///
9279 /// See [`Self::add_scope()`] for details.
9280 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyListCall<'a, C>
9281 where
9282 I: IntoIterator<Item = St>,
9283 St: AsRef<str>,
9284 {
9285 self._scopes
9286 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
9287 self
9288 }
9289
9290 /// Removes all scopes, and no default scope will be used either.
9291 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
9292 /// for details).
9293 pub fn clear_scopes(mut self) -> ProjectPolicyListCall<'a, C> {
9294 self._scopes.clear();
9295 self
9296 }
9297}
9298
9299/// Updates a policy. Returns a `google.rpc.Status` with `google.rpc.Code.NOT_FOUND` if the constraint or the policy do not exist. Returns a `google.rpc.Status` with `google.rpc.Code.ABORTED` if the etag supplied in the request does not match the persisted etag of the policy Note: the supplied policy will perform a full overwrite of all fields.
9300///
9301/// A builder for the *policies.patch* method supported by a *project* resource.
9302/// It is not used directly, but through a [`ProjectMethods`] instance.
9303///
9304/// # Example
9305///
9306/// Instantiate a resource method builder
9307///
9308/// ```test_harness,no_run
9309/// # extern crate hyper;
9310/// # extern crate hyper_rustls;
9311/// # extern crate google_orgpolicy2 as orgpolicy2;
9312/// use orgpolicy2::api::GoogleCloudOrgpolicyV2Policy;
9313/// # async fn dox() {
9314/// # use orgpolicy2::{OrgPolicyAPI, FieldMask, hyper_rustls, hyper_util, yup_oauth2};
9315///
9316/// # let secret: yup_oauth2::ApplicationSecret = Default::default();
9317/// # let connector = hyper_rustls::HttpsConnectorBuilder::new()
9318/// # .with_native_roots()
9319/// # .unwrap()
9320/// # .https_only()
9321/// # .enable_http2()
9322/// # .build();
9323///
9324/// # let executor = hyper_util::rt::TokioExecutor::new();
9325/// # let auth = yup_oauth2::InstalledFlowAuthenticator::with_client(
9326/// # secret,
9327/// # yup_oauth2::InstalledFlowReturnMethod::HTTPRedirect,
9328/// # yup_oauth2::client::CustomHyperClientBuilder::from(
9329/// # hyper_util::client::legacy::Client::builder(executor).build(connector),
9330/// # ),
9331/// # ).build().await.unwrap();
9332///
9333/// # let client = hyper_util::client::legacy::Client::builder(
9334/// # hyper_util::rt::TokioExecutor::new()
9335/// # )
9336/// # .build(
9337/// # hyper_rustls::HttpsConnectorBuilder::new()
9338/// # .with_native_roots()
9339/// # .unwrap()
9340/// # .https_or_http()
9341/// # .enable_http2()
9342/// # .build()
9343/// # );
9344/// # let mut hub = OrgPolicyAPI::new(client, auth);
9345/// // As the method needs a request, you would usually fill it with the desired information
9346/// // into the respective structure. Some of the parts shown here might not be applicable !
9347/// // Values shown here are possibly random and not representative !
9348/// let mut req = GoogleCloudOrgpolicyV2Policy::default();
9349///
9350/// // You can configure optional parameters by calling the respective setters at will, and
9351/// // execute the final call using `doit()`.
9352/// // Values shown here are possibly random and not representative !
9353/// let result = hub.projects().policies_patch(req, "name")
9354/// .update_mask(FieldMask::new::<&str>(&[]))
9355/// .doit().await;
9356/// # }
9357/// ```
9358pub struct ProjectPolicyPatchCall<'a, C>
9359where
9360 C: 'a,
9361{
9362 hub: &'a OrgPolicyAPI<C>,
9363 _request: GoogleCloudOrgpolicyV2Policy,
9364 _name: String,
9365 _update_mask: Option<common::FieldMask>,
9366 _delegate: Option<&'a mut dyn common::Delegate>,
9367 _additional_params: HashMap<String, String>,
9368 _scopes: BTreeSet<String>,
9369}
9370
9371impl<'a, C> common::CallBuilder for ProjectPolicyPatchCall<'a, C> {}
9372
9373impl<'a, C> ProjectPolicyPatchCall<'a, C>
9374where
9375 C: common::Connector,
9376{
9377 /// Perform the operation you have build so far.
9378 pub async fn doit(
9379 mut self,
9380 ) -> common::Result<(common::Response, GoogleCloudOrgpolicyV2Policy)> {
9381 use std::borrow::Cow;
9382 use std::io::{Read, Seek};
9383
9384 use common::{url::Params, ToParts};
9385 use hyper::header::{AUTHORIZATION, CONTENT_LENGTH, CONTENT_TYPE, LOCATION, USER_AGENT};
9386
9387 let mut dd = common::DefaultDelegate;
9388 let mut dlg: &mut dyn common::Delegate = self._delegate.unwrap_or(&mut dd);
9389 dlg.begin(common::MethodInfo {
9390 id: "orgpolicy.projects.policies.patch",
9391 http_method: hyper::Method::PATCH,
9392 });
9393
9394 for &field in ["alt", "name", "updateMask"].iter() {
9395 if self._additional_params.contains_key(field) {
9396 dlg.finished(false);
9397 return Err(common::Error::FieldClash(field));
9398 }
9399 }
9400
9401 let mut params = Params::with_capacity(5 + self._additional_params.len());
9402 params.push("name", self._name);
9403 if let Some(value) = self._update_mask.as_ref() {
9404 params.push("updateMask", value.to_string());
9405 }
9406
9407 params.extend(self._additional_params.iter());
9408
9409 params.push("alt", "json");
9410 let mut url = self.hub._base_url.clone() + "v2/{+name}";
9411 if self._scopes.is_empty() {
9412 self._scopes
9413 .insert(Scope::CloudPlatform.as_ref().to_string());
9414 }
9415
9416 #[allow(clippy::single_element_loop)]
9417 for &(find_this, param_name) in [("{+name}", "name")].iter() {
9418 url = params.uri_replacement(url, param_name, find_this, true);
9419 }
9420 {
9421 let to_remove = ["name"];
9422 params.remove_params(&to_remove);
9423 }
9424
9425 let url = params.parse_with_url(&url);
9426
9427 let mut json_mime_type = mime::APPLICATION_JSON;
9428 let mut request_value_reader = {
9429 let mut value = serde_json::value::to_value(&self._request).expect("serde to work");
9430 common::remove_json_null_values(&mut value);
9431 let mut dst = std::io::Cursor::new(Vec::with_capacity(128));
9432 serde_json::to_writer(&mut dst, &value).unwrap();
9433 dst
9434 };
9435 let request_size = request_value_reader
9436 .seek(std::io::SeekFrom::End(0))
9437 .unwrap();
9438 request_value_reader
9439 .seek(std::io::SeekFrom::Start(0))
9440 .unwrap();
9441
9442 loop {
9443 let token = match self
9444 .hub
9445 .auth
9446 .get_token(&self._scopes.iter().map(String::as_str).collect::<Vec<_>>()[..])
9447 .await
9448 {
9449 Ok(token) => token,
9450 Err(e) => match dlg.token(e) {
9451 Ok(token) => token,
9452 Err(e) => {
9453 dlg.finished(false);
9454 return Err(common::Error::MissingToken(e));
9455 }
9456 },
9457 };
9458 request_value_reader
9459 .seek(std::io::SeekFrom::Start(0))
9460 .unwrap();
9461 let mut req_result = {
9462 let client = &self.hub.client;
9463 dlg.pre_request();
9464 let mut req_builder = hyper::Request::builder()
9465 .method(hyper::Method::PATCH)
9466 .uri(url.as_str())
9467 .header(USER_AGENT, self.hub._user_agent.clone());
9468
9469 if let Some(token) = token.as_ref() {
9470 req_builder = req_builder.header(AUTHORIZATION, format!("Bearer {}", token));
9471 }
9472
9473 let request = req_builder
9474 .header(CONTENT_TYPE, json_mime_type.to_string())
9475 .header(CONTENT_LENGTH, request_size as u64)
9476 .body(common::to_body(
9477 request_value_reader.get_ref().clone().into(),
9478 ));
9479
9480 client.request(request.unwrap()).await
9481 };
9482
9483 match req_result {
9484 Err(err) => {
9485 if let common::Retry::After(d) = dlg.http_error(&err) {
9486 sleep(d).await;
9487 continue;
9488 }
9489 dlg.finished(false);
9490 return Err(common::Error::HttpError(err));
9491 }
9492 Ok(res) => {
9493 let (mut parts, body) = res.into_parts();
9494 let mut body = common::Body::new(body);
9495 if !parts.status.is_success() {
9496 let bytes = common::to_bytes(body).await.unwrap_or_default();
9497 let error = serde_json::from_str(&common::to_string(&bytes));
9498 let response = common::to_response(parts, bytes.into());
9499
9500 if let common::Retry::After(d) =
9501 dlg.http_failure(&response, error.as_ref().ok())
9502 {
9503 sleep(d).await;
9504 continue;
9505 }
9506
9507 dlg.finished(false);
9508
9509 return Err(match error {
9510 Ok(value) => common::Error::BadRequest(value),
9511 _ => common::Error::Failure(response),
9512 });
9513 }
9514 let response = {
9515 let bytes = common::to_bytes(body).await.unwrap_or_default();
9516 let encoded = common::to_string(&bytes);
9517 match serde_json::from_str(&encoded) {
9518 Ok(decoded) => (common::to_response(parts, bytes.into()), decoded),
9519 Err(error) => {
9520 dlg.response_json_decode_error(&encoded, &error);
9521 return Err(common::Error::JsonDecodeError(
9522 encoded.to_string(),
9523 error,
9524 ));
9525 }
9526 }
9527 };
9528
9529 dlg.finished(true);
9530 return Ok(response);
9531 }
9532 }
9533 }
9534 }
9535
9536 ///
9537 /// Sets the *request* property to the given value.
9538 ///
9539 /// Even though the property as already been set when instantiating this call,
9540 /// we provide this method for API completeness.
9541 pub fn request(
9542 mut self,
9543 new_value: GoogleCloudOrgpolicyV2Policy,
9544 ) -> ProjectPolicyPatchCall<'a, C> {
9545 self._request = new_value;
9546 self
9547 }
9548 /// Immutable. The resource name of the policy. Must be one of the following forms, where `constraint_name` is the name of the constraint which this policy configures: * `projects/{project_number}/policies/{constraint_name}` * `folders/{folder_id}/policies/{constraint_name}` * `organizations/{organization_id}/policies/{constraint_name}` For example, `projects/123/policies/compute.disableSerialPortAccess`. Note: `projects/{project_id}/policies/{constraint_name}` is also an acceptable name for API requests, but responses will return the name using the equivalent project number.
9549 ///
9550 /// Sets the *name* path property to the given value.
9551 ///
9552 /// Even though the property as already been set when instantiating this call,
9553 /// we provide this method for API completeness.
9554 pub fn name(mut self, new_value: &str) -> ProjectPolicyPatchCall<'a, C> {
9555 self._name = new_value.to_string();
9556 self
9557 }
9558 /// Field mask used to specify the fields to be overwritten in the policy by the set. The fields specified in the update_mask are relative to the policy, not the full request.
9559 ///
9560 /// Sets the *update mask* query property to the given value.
9561 pub fn update_mask(mut self, new_value: common::FieldMask) -> ProjectPolicyPatchCall<'a, C> {
9562 self._update_mask = Some(new_value);
9563 self
9564 }
9565 /// The delegate implementation is consulted whenever there is an intermediate result, or if something goes wrong
9566 /// while executing the actual API request.
9567 ///
9568 /// ````text
9569 /// It should be used to handle progress information, and to implement a certain level of resilience.
9570 /// ````
9571 ///
9572 /// Sets the *delegate* property to the given value.
9573 pub fn delegate(
9574 mut self,
9575 new_value: &'a mut dyn common::Delegate,
9576 ) -> ProjectPolicyPatchCall<'a, C> {
9577 self._delegate = Some(new_value);
9578 self
9579 }
9580
9581 /// Set any additional parameter of the query string used in the request.
9582 /// It should be used to set parameters which are not yet available through their own
9583 /// setters.
9584 ///
9585 /// Please note that this method must not be used to set any of the known parameters
9586 /// which have their own setter method. If done anyway, the request will fail.
9587 ///
9588 /// # Additional Parameters
9589 ///
9590 /// * *$.xgafv* (query-string) - V1 error format.
9591 /// * *access_token* (query-string) - OAuth access token.
9592 /// * *alt* (query-string) - Data format for response.
9593 /// * *callback* (query-string) - JSONP
9594 /// * *fields* (query-string) - Selector specifying which fields to include in a partial response.
9595 /// * *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.
9596 /// * *oauth_token* (query-string) - OAuth 2.0 token for the current user.
9597 /// * *prettyPrint* (query-boolean) - Returns response with indentations and line breaks.
9598 /// * *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.
9599 /// * *uploadType* (query-string) - Legacy upload protocol for media (e.g. "media", "multipart").
9600 /// * *upload_protocol* (query-string) - Upload protocol for media (e.g. "raw", "multipart").
9601 pub fn param<T>(mut self, name: T, value: T) -> ProjectPolicyPatchCall<'a, C>
9602 where
9603 T: AsRef<str>,
9604 {
9605 self._additional_params
9606 .insert(name.as_ref().to_string(), value.as_ref().to_string());
9607 self
9608 }
9609
9610 /// Identifies the authorization scope for the method you are building.
9611 ///
9612 /// Use this method to actively specify which scope should be used, instead of the default [`Scope`] variant
9613 /// [`Scope::CloudPlatform`].
9614 ///
9615 /// The `scope` will be added to a set of scopes. This is important as one can maintain access
9616 /// tokens for more than one scope.
9617 ///
9618 /// Usually there is more than one suitable scope to authorize an operation, some of which may
9619 /// encompass more rights than others. For example, for listing resources, a *read-only* scope will be
9620 /// sufficient, a read-write scope will do as well.
9621 pub fn add_scope<St>(mut self, scope: St) -> ProjectPolicyPatchCall<'a, C>
9622 where
9623 St: AsRef<str>,
9624 {
9625 self._scopes.insert(String::from(scope.as_ref()));
9626 self
9627 }
9628 /// Identifies the authorization scope(s) for the method you are building.
9629 ///
9630 /// See [`Self::add_scope()`] for details.
9631 pub fn add_scopes<I, St>(mut self, scopes: I) -> ProjectPolicyPatchCall<'a, C>
9632 where
9633 I: IntoIterator<Item = St>,
9634 St: AsRef<str>,
9635 {
9636 self._scopes
9637 .extend(scopes.into_iter().map(|s| String::from(s.as_ref())));
9638 self
9639 }
9640
9641 /// Removes all scopes, and no default scope will be used either.
9642 /// In this case, you have to specify your API-key using the `key` parameter (see [`Self::param()`]
9643 /// for details).
9644 pub fn clear_scopes(mut self) -> ProjectPolicyPatchCall<'a, C> {
9645 self._scopes.clear();
9646 self
9647 }
9648}