Skip to main content

google_cloud_iam_v1/
builder.rs

1// Copyright 2024 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17/// Request and client builders for [IAMPolicy][crate::client::IAMPolicy].
18pub mod iam_policy {
19    use crate::Result;
20
21    /// A builder for [IAMPolicy][crate::client::IAMPolicy].
22    ///
23    /// ```
24    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
25    /// # use google_cloud_iam_v1::*;
26    /// # use builder::iam_policy::ClientBuilder;
27    /// # use client::IAMPolicy;
28    /// let builder : ClientBuilder = IAMPolicy::builder();
29    /// let client = builder
30    ///     .with_endpoint("https://iam-meta-api.googleapis.com")
31    ///     .build().await?;
32    /// # Ok(()) }
33    /// ```
34    pub type ClientBuilder = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::IAMPolicy;
38        pub struct Factory;
39        impl crate::ClientFactory for Factory {
40            type Client = IAMPolicy;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> crate::ClientBuilderResult<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::IAMPolicy] request builders.
52    #[derive(Clone, Debug)]
53    pub(crate) struct RequestBuilder<R: std::default::Default> {
54        stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
55        request: R,
56        options: crate::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(
64            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
65        ) -> Self {
66            Self {
67                stub,
68                request: R::default(),
69                options: crate::RequestOptions::default(),
70            }
71        }
72    }
73
74    /// The request builder for [IAMPolicy::set_iam_policy][crate::client::IAMPolicy::set_iam_policy] calls.
75    ///
76    /// # Example
77    /// ```
78    /// # use google_cloud_iam_v1::builder::iam_policy::SetIamPolicy;
79    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
80    ///
81    /// let builder = prepare_request_builder();
82    /// let response = builder.send().await?;
83    /// # Ok(()) }
84    ///
85    /// fn prepare_request_builder() -> SetIamPolicy {
86    ///   # panic!();
87    ///   // ... details omitted ...
88    /// }
89    /// ```
90    #[derive(Clone, Debug)]
91    pub struct SetIamPolicy(RequestBuilder<crate::model::SetIamPolicyRequest>);
92
93    impl SetIamPolicy {
94        pub(crate) fn new(
95            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
96        ) -> Self {
97            Self(RequestBuilder::new(stub))
98        }
99
100        /// Sets the full request, replacing any prior values.
101        pub fn with_request<V: Into<crate::model::SetIamPolicyRequest>>(mut self, v: V) -> Self {
102            self.0.request = v.into();
103            self
104        }
105
106        /// Sets all the options, replacing any prior values.
107        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
108            self.0.options = v.into();
109            self
110        }
111
112        /// Sends the request.
113        pub async fn send(self) -> Result<crate::model::Policy> {
114            (*self.0.stub)
115                .set_iam_policy(self.0.request, self.0.options)
116                .await
117                .map(crate::Response::into_body)
118        }
119
120        /// Sets the value of [resource][crate::model::SetIamPolicyRequest::resource].
121        ///
122        /// This is a **required** field for requests.
123        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
124            self.0.request.resource = v.into();
125            self
126        }
127
128        /// Sets the value of [policy][crate::model::SetIamPolicyRequest::policy].
129        ///
130        /// This is a **required** field for requests.
131        pub fn set_policy<T>(mut self, v: T) -> Self
132        where
133            T: std::convert::Into<crate::model::Policy>,
134        {
135            self.0.request.policy = std::option::Option::Some(v.into());
136            self
137        }
138
139        /// Sets or clears the value of [policy][crate::model::SetIamPolicyRequest::policy].
140        ///
141        /// This is a **required** field for requests.
142        pub fn set_or_clear_policy<T>(mut self, v: std::option::Option<T>) -> Self
143        where
144            T: std::convert::Into<crate::model::Policy>,
145        {
146            self.0.request.policy = v.map(|x| x.into());
147            self
148        }
149
150        /// Sets the value of [update_mask][crate::model::SetIamPolicyRequest::update_mask].
151        pub fn set_update_mask<T>(mut self, v: T) -> Self
152        where
153            T: std::convert::Into<wkt::FieldMask>,
154        {
155            self.0.request.update_mask = std::option::Option::Some(v.into());
156            self
157        }
158
159        /// Sets or clears the value of [update_mask][crate::model::SetIamPolicyRequest::update_mask].
160        pub fn set_or_clear_update_mask<T>(mut self, v: std::option::Option<T>) -> Self
161        where
162            T: std::convert::Into<wkt::FieldMask>,
163        {
164            self.0.request.update_mask = v.map(|x| x.into());
165            self
166        }
167    }
168
169    #[doc(hidden)]
170    impl crate::RequestBuilder for SetIamPolicy {
171        fn request_options(&mut self) -> &mut crate::RequestOptions {
172            &mut self.0.options
173        }
174    }
175
176    /// The request builder for [IAMPolicy::get_iam_policy][crate::client::IAMPolicy::get_iam_policy] calls.
177    ///
178    /// # Example
179    /// ```
180    /// # use google_cloud_iam_v1::builder::iam_policy::GetIamPolicy;
181    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
182    ///
183    /// let builder = prepare_request_builder();
184    /// let response = builder.send().await?;
185    /// # Ok(()) }
186    ///
187    /// fn prepare_request_builder() -> GetIamPolicy {
188    ///   # panic!();
189    ///   // ... details omitted ...
190    /// }
191    /// ```
192    #[derive(Clone, Debug)]
193    pub struct GetIamPolicy(RequestBuilder<crate::model::GetIamPolicyRequest>);
194
195    impl GetIamPolicy {
196        pub(crate) fn new(
197            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
198        ) -> Self {
199            Self(RequestBuilder::new(stub))
200        }
201
202        /// Sets the full request, replacing any prior values.
203        pub fn with_request<V: Into<crate::model::GetIamPolicyRequest>>(mut self, v: V) -> Self {
204            self.0.request = v.into();
205            self
206        }
207
208        /// Sets all the options, replacing any prior values.
209        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
210            self.0.options = v.into();
211            self
212        }
213
214        /// Sends the request.
215        pub async fn send(self) -> Result<crate::model::Policy> {
216            (*self.0.stub)
217                .get_iam_policy(self.0.request, self.0.options)
218                .await
219                .map(crate::Response::into_body)
220        }
221
222        /// Sets the value of [resource][crate::model::GetIamPolicyRequest::resource].
223        ///
224        /// This is a **required** field for requests.
225        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
226            self.0.request.resource = v.into();
227            self
228        }
229
230        /// Sets the value of [options][crate::model::GetIamPolicyRequest::options].
231        pub fn set_options<T>(mut self, v: T) -> Self
232        where
233            T: std::convert::Into<crate::model::GetPolicyOptions>,
234        {
235            self.0.request.options = std::option::Option::Some(v.into());
236            self
237        }
238
239        /// Sets or clears the value of [options][crate::model::GetIamPolicyRequest::options].
240        pub fn set_or_clear_options<T>(mut self, v: std::option::Option<T>) -> Self
241        where
242            T: std::convert::Into<crate::model::GetPolicyOptions>,
243        {
244            self.0.request.options = v.map(|x| x.into());
245            self
246        }
247    }
248
249    #[doc(hidden)]
250    impl crate::RequestBuilder for GetIamPolicy {
251        fn request_options(&mut self) -> &mut crate::RequestOptions {
252            &mut self.0.options
253        }
254    }
255
256    /// The request builder for [IAMPolicy::test_iam_permissions][crate::client::IAMPolicy::test_iam_permissions] calls.
257    ///
258    /// # Example
259    /// ```
260    /// # use google_cloud_iam_v1::builder::iam_policy::TestIamPermissions;
261    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
262    ///
263    /// let builder = prepare_request_builder();
264    /// let response = builder.send().await?;
265    /// # Ok(()) }
266    ///
267    /// fn prepare_request_builder() -> TestIamPermissions {
268    ///   # panic!();
269    ///   // ... details omitted ...
270    /// }
271    /// ```
272    #[derive(Clone, Debug)]
273    pub struct TestIamPermissions(RequestBuilder<crate::model::TestIamPermissionsRequest>);
274
275    impl TestIamPermissions {
276        pub(crate) fn new(
277            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
278        ) -> Self {
279            Self(RequestBuilder::new(stub))
280        }
281
282        /// Sets the full request, replacing any prior values.
283        pub fn with_request<V: Into<crate::model::TestIamPermissionsRequest>>(
284            mut self,
285            v: V,
286        ) -> Self {
287            self.0.request = v.into();
288            self
289        }
290
291        /// Sets all the options, replacing any prior values.
292        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
293            self.0.options = v.into();
294            self
295        }
296
297        /// Sends the request.
298        pub async fn send(self) -> Result<crate::model::TestIamPermissionsResponse> {
299            (*self.0.stub)
300                .test_iam_permissions(self.0.request, self.0.options)
301                .await
302                .map(crate::Response::into_body)
303        }
304
305        /// Sets the value of [resource][crate::model::TestIamPermissionsRequest::resource].
306        ///
307        /// This is a **required** field for requests.
308        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
309            self.0.request.resource = v.into();
310            self
311        }
312
313        /// Sets the value of [permissions][crate::model::TestIamPermissionsRequest::permissions].
314        ///
315        /// This is a **required** field for requests.
316        pub fn set_permissions<T, V>(mut self, v: T) -> Self
317        where
318            T: std::iter::IntoIterator<Item = V>,
319            V: std::convert::Into<std::string::String>,
320        {
321            use std::iter::Iterator;
322            self.0.request.permissions = v.into_iter().map(|i| i.into()).collect();
323            self
324        }
325    }
326
327    #[doc(hidden)]
328    impl crate::RequestBuilder for TestIamPermissions {
329        fn request_options(&mut self) -> &mut crate::RequestOptions {
330            &mut self.0.options
331        }
332    }
333}