google_cloud_iam_v2/
builder.rs

1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16
17pub mod policies {
18    use crate::Result;
19
20    /// A builder for [Policies][crate::client::Policies].
21    ///
22    /// ```
23    /// # tokio_test::block_on(async {
24    /// # use google_cloud_iam_v2::*;
25    /// # use builder::policies::ClientBuilder;
26    /// # use client::Policies;
27    /// let builder : ClientBuilder = Policies::builder();
28    /// let client = builder
29    ///     .with_endpoint("https://iam.googleapis.com")
30    ///     .build().await?;
31    /// # gax::client_builder::Result::<()>::Ok(()) });
32    /// ```
33    pub type ClientBuilder =
34        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;
35
36    pub(crate) mod client {
37        use super::super::super::client::Policies;
38        pub struct Factory;
39        impl gax::client_builder::internal::ClientFactory for Factory {
40            type Client = Policies;
41            type Credentials = gaxi::options::Credentials;
42            async fn build(
43                self,
44                config: gaxi::options::ClientConfig,
45            ) -> gax::client_builder::Result<Self::Client> {
46                Self::Client::new(config).await
47            }
48        }
49    }
50
51    /// Common implementation for [crate::client::Policies] 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::Policies>,
55        request: R,
56        options: gax::options::RequestOptions,
57    }
58
59    impl<R> RequestBuilder<R>
60    where
61        R: std::default::Default,
62    {
63        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
64            Self {
65                stub,
66                request: R::default(),
67                options: gax::options::RequestOptions::default(),
68            }
69        }
70    }
71
72    /// The request builder for [Policies::list_policies][crate::client::Policies::list_policies] calls.
73    ///
74    /// # Example
75    /// ```no_run
76    /// # use google_cloud_iam_v2::builder;
77    /// use builder::policies::ListPolicies;
78    /// # tokio_test::block_on(async {
79    /// use gax::paginator::ItemPaginator;
80    ///
81    /// let builder = prepare_request_builder();
82    /// let mut items = builder.by_item();
83    /// while let Some(result) = items.next().await {
84    ///   let item = result?;
85    /// }
86    /// # gax::Result::<()>::Ok(()) });
87    ///
88    /// fn prepare_request_builder() -> ListPolicies {
89    ///   # panic!();
90    ///   // ... details omitted ...
91    /// }
92    /// ```
93    #[derive(Clone, Debug)]
94    pub struct ListPolicies(RequestBuilder<crate::model::ListPoliciesRequest>);
95
96    impl ListPolicies {
97        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
98            Self(RequestBuilder::new(stub))
99        }
100
101        /// Sets the full request, replacing any prior values.
102        pub fn with_request<V: Into<crate::model::ListPoliciesRequest>>(mut self, v: V) -> Self {
103            self.0.request = v.into();
104            self
105        }
106
107        /// Sets all the options, replacing any prior values.
108        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
109            self.0.options = v.into();
110            self
111        }
112
113        /// Sends the request.
114        pub async fn send(self) -> Result<crate::model::ListPoliciesResponse> {
115            (*self.0.stub)
116                .list_policies(self.0.request, self.0.options)
117                .await
118                .map(gax::response::Response::into_body)
119        }
120
121        /// Streams each page in the collection.
122        pub fn by_page(
123            self,
124        ) -> impl gax::paginator::Paginator<crate::model::ListPoliciesResponse, gax::error::Error>
125        {
126            use std::clone::Clone;
127            let token = self.0.request.page_token.clone();
128            let execute = move |token: String| {
129                let mut builder = self.clone();
130                builder.0.request = builder.0.request.set_page_token(token);
131                builder.send()
132            };
133            gax::paginator::internal::new_paginator(token, execute)
134        }
135
136        /// Streams each item in the collection.
137        pub fn by_item(
138            self,
139        ) -> impl gax::paginator::ItemPaginator<crate::model::ListPoliciesResponse, gax::error::Error>
140        {
141            use gax::paginator::Paginator;
142            self.by_page().items()
143        }
144
145        /// Sets the value of [parent][crate::model::ListPoliciesRequest::parent].
146        ///
147        /// This is a **required** field for requests.
148        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
149            self.0.request.parent = v.into();
150            self
151        }
152
153        /// Sets the value of [page_size][crate::model::ListPoliciesRequest::page_size].
154        pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
155            self.0.request.page_size = v.into();
156            self
157        }
158
159        /// Sets the value of [page_token][crate::model::ListPoliciesRequest::page_token].
160        pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
161            self.0.request.page_token = v.into();
162            self
163        }
164    }
165
166    #[doc(hidden)]
167    impl gax::options::internal::RequestBuilder for ListPolicies {
168        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
169            &mut self.0.options
170        }
171    }
172
173    /// The request builder for [Policies::get_policy][crate::client::Policies::get_policy] calls.
174    ///
175    /// # Example
176    /// ```no_run
177    /// # use google_cloud_iam_v2::builder;
178    /// use builder::policies::GetPolicy;
179    /// # tokio_test::block_on(async {
180    ///
181    /// let builder = prepare_request_builder();
182    /// let response = builder.send().await?;
183    /// # gax::Result::<()>::Ok(()) });
184    ///
185    /// fn prepare_request_builder() -> GetPolicy {
186    ///   # panic!();
187    ///   // ... details omitted ...
188    /// }
189    /// ```
190    #[derive(Clone, Debug)]
191    pub struct GetPolicy(RequestBuilder<crate::model::GetPolicyRequest>);
192
193    impl GetPolicy {
194        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
195            Self(RequestBuilder::new(stub))
196        }
197
198        /// Sets the full request, replacing any prior values.
199        pub fn with_request<V: Into<crate::model::GetPolicyRequest>>(mut self, v: V) -> Self {
200            self.0.request = v.into();
201            self
202        }
203
204        /// Sets all the options, replacing any prior values.
205        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
206            self.0.options = v.into();
207            self
208        }
209
210        /// Sends the request.
211        pub async fn send(self) -> Result<crate::model::Policy> {
212            (*self.0.stub)
213                .get_policy(self.0.request, self.0.options)
214                .await
215                .map(gax::response::Response::into_body)
216        }
217
218        /// Sets the value of [name][crate::model::GetPolicyRequest::name].
219        ///
220        /// This is a **required** field for requests.
221        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
222            self.0.request.name = v.into();
223            self
224        }
225    }
226
227    #[doc(hidden)]
228    impl gax::options::internal::RequestBuilder for GetPolicy {
229        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
230            &mut self.0.options
231        }
232    }
233
234    /// The request builder for [Policies::create_policy][crate::client::Policies::create_policy] calls.
235    ///
236    /// # Example
237    /// ```no_run
238    /// # use google_cloud_iam_v2::builder;
239    /// use builder::policies::CreatePolicy;
240    /// # tokio_test::block_on(async {
241    /// use lro::Poller;
242    ///
243    /// let builder = prepare_request_builder();
244    /// let response = builder.poller().until_done().await?;
245    /// # gax::Result::<()>::Ok(()) });
246    ///
247    /// fn prepare_request_builder() -> CreatePolicy {
248    ///   # panic!();
249    ///   // ... details omitted ...
250    /// }
251    /// ```
252    #[derive(Clone, Debug)]
253    pub struct CreatePolicy(RequestBuilder<crate::model::CreatePolicyRequest>);
254
255    impl CreatePolicy {
256        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
257            Self(RequestBuilder::new(stub))
258        }
259
260        /// Sets the full request, replacing any prior values.
261        pub fn with_request<V: Into<crate::model::CreatePolicyRequest>>(mut self, v: V) -> Self {
262            self.0.request = v.into();
263            self
264        }
265
266        /// Sets all the options, replacing any prior values.
267        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
268            self.0.options = v.into();
269            self
270        }
271
272        /// Sends the request.
273        ///
274        /// # Long running operations
275        ///
276        /// This starts, but does not poll, a longrunning operation. More information
277        /// on [create_policy][crate::client::Policies::create_policy].
278        pub async fn send(self) -> Result<longrunning::model::Operation> {
279            (*self.0.stub)
280                .create_policy(self.0.request, self.0.options)
281                .await
282                .map(gax::response::Response::into_body)
283        }
284
285        /// Creates a [Poller][lro::Poller] to work with `create_policy`.
286        pub fn poller(
287            self,
288        ) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
289            type Operation = lro::internal::Operation<
290                crate::model::Policy,
291                crate::model::PolicyOperationMetadata,
292            >;
293            let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
294            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
295
296            let stub = self.0.stub.clone();
297            let mut options = self.0.options.clone();
298            options.set_retry_policy(gax::retry_policy::NeverRetry);
299            let query = move |name| {
300                let stub = stub.clone();
301                let options = options.clone();
302                async {
303                    let op = GetOperation::new(stub)
304                        .set_name(name)
305                        .with_options(options)
306                        .send()
307                        .await?;
308                    Ok(Operation::new(op))
309                }
310            };
311
312            let start = move || async {
313                let op = self.send().await?;
314                Ok(Operation::new(op))
315            };
316
317            lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
318        }
319
320        /// Sets the value of [parent][crate::model::CreatePolicyRequest::parent].
321        ///
322        /// This is a **required** field for requests.
323        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
324            self.0.request.parent = v.into();
325            self
326        }
327
328        /// Sets the value of [policy][crate::model::CreatePolicyRequest::policy].
329        ///
330        /// This is a **required** field for requests.
331        pub fn set_policy<T>(mut self, v: T) -> Self
332        where
333            T: std::convert::Into<crate::model::Policy>,
334        {
335            self.0.request.policy = std::option::Option::Some(v.into());
336            self
337        }
338
339        /// Sets or clears the value of [policy][crate::model::CreatePolicyRequest::policy].
340        ///
341        /// This is a **required** field for requests.
342        pub fn set_or_clear_policy<T>(mut self, v: std::option::Option<T>) -> Self
343        where
344            T: std::convert::Into<crate::model::Policy>,
345        {
346            self.0.request.policy = v.map(|x| x.into());
347            self
348        }
349
350        /// Sets the value of [policy_id][crate::model::CreatePolicyRequest::policy_id].
351        pub fn set_policy_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
352            self.0.request.policy_id = v.into();
353            self
354        }
355    }
356
357    #[doc(hidden)]
358    impl gax::options::internal::RequestBuilder for CreatePolicy {
359        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
360            &mut self.0.options
361        }
362    }
363
364    /// The request builder for [Policies::update_policy][crate::client::Policies::update_policy] calls.
365    ///
366    /// # Example
367    /// ```no_run
368    /// # use google_cloud_iam_v2::builder;
369    /// use builder::policies::UpdatePolicy;
370    /// # tokio_test::block_on(async {
371    /// use lro::Poller;
372    ///
373    /// let builder = prepare_request_builder();
374    /// let response = builder.poller().until_done().await?;
375    /// # gax::Result::<()>::Ok(()) });
376    ///
377    /// fn prepare_request_builder() -> UpdatePolicy {
378    ///   # panic!();
379    ///   // ... details omitted ...
380    /// }
381    /// ```
382    #[derive(Clone, Debug)]
383    pub struct UpdatePolicy(RequestBuilder<crate::model::UpdatePolicyRequest>);
384
385    impl UpdatePolicy {
386        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
387            Self(RequestBuilder::new(stub))
388        }
389
390        /// Sets the full request, replacing any prior values.
391        pub fn with_request<V: Into<crate::model::UpdatePolicyRequest>>(mut self, v: V) -> Self {
392            self.0.request = v.into();
393            self
394        }
395
396        /// Sets all the options, replacing any prior values.
397        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
398            self.0.options = v.into();
399            self
400        }
401
402        /// Sends the request.
403        ///
404        /// # Long running operations
405        ///
406        /// This starts, but does not poll, a longrunning operation. More information
407        /// on [update_policy][crate::client::Policies::update_policy].
408        pub async fn send(self) -> Result<longrunning::model::Operation> {
409            (*self.0.stub)
410                .update_policy(self.0.request, self.0.options)
411                .await
412                .map(gax::response::Response::into_body)
413        }
414
415        /// Creates a [Poller][lro::Poller] to work with `update_policy`.
416        pub fn poller(
417            self,
418        ) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
419            type Operation = lro::internal::Operation<
420                crate::model::Policy,
421                crate::model::PolicyOperationMetadata,
422            >;
423            let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
424            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
425
426            let stub = self.0.stub.clone();
427            let mut options = self.0.options.clone();
428            options.set_retry_policy(gax::retry_policy::NeverRetry);
429            let query = move |name| {
430                let stub = stub.clone();
431                let options = options.clone();
432                async {
433                    let op = GetOperation::new(stub)
434                        .set_name(name)
435                        .with_options(options)
436                        .send()
437                        .await?;
438                    Ok(Operation::new(op))
439                }
440            };
441
442            let start = move || async {
443                let op = self.send().await?;
444                Ok(Operation::new(op))
445            };
446
447            lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
448        }
449
450        /// Sets the value of [policy][crate::model::UpdatePolicyRequest::policy].
451        ///
452        /// This is a **required** field for requests.
453        pub fn set_policy<T>(mut self, v: T) -> Self
454        where
455            T: std::convert::Into<crate::model::Policy>,
456        {
457            self.0.request.policy = std::option::Option::Some(v.into());
458            self
459        }
460
461        /// Sets or clears the value of [policy][crate::model::UpdatePolicyRequest::policy].
462        ///
463        /// This is a **required** field for requests.
464        pub fn set_or_clear_policy<T>(mut self, v: std::option::Option<T>) -> Self
465        where
466            T: std::convert::Into<crate::model::Policy>,
467        {
468            self.0.request.policy = v.map(|x| x.into());
469            self
470        }
471    }
472
473    #[doc(hidden)]
474    impl gax::options::internal::RequestBuilder for UpdatePolicy {
475        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
476            &mut self.0.options
477        }
478    }
479
480    /// The request builder for [Policies::delete_policy][crate::client::Policies::delete_policy] calls.
481    ///
482    /// # Example
483    /// ```no_run
484    /// # use google_cloud_iam_v2::builder;
485    /// use builder::policies::DeletePolicy;
486    /// # tokio_test::block_on(async {
487    /// use lro::Poller;
488    ///
489    /// let builder = prepare_request_builder();
490    /// let response = builder.poller().until_done().await?;
491    /// # gax::Result::<()>::Ok(()) });
492    ///
493    /// fn prepare_request_builder() -> DeletePolicy {
494    ///   # panic!();
495    ///   // ... details omitted ...
496    /// }
497    /// ```
498    #[derive(Clone, Debug)]
499    pub struct DeletePolicy(RequestBuilder<crate::model::DeletePolicyRequest>);
500
501    impl DeletePolicy {
502        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
503            Self(RequestBuilder::new(stub))
504        }
505
506        /// Sets the full request, replacing any prior values.
507        pub fn with_request<V: Into<crate::model::DeletePolicyRequest>>(mut self, v: V) -> Self {
508            self.0.request = v.into();
509            self
510        }
511
512        /// Sets all the options, replacing any prior values.
513        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
514            self.0.options = v.into();
515            self
516        }
517
518        /// Sends the request.
519        ///
520        /// # Long running operations
521        ///
522        /// This starts, but does not poll, a longrunning operation. More information
523        /// on [delete_policy][crate::client::Policies::delete_policy].
524        pub async fn send(self) -> Result<longrunning::model::Operation> {
525            (*self.0.stub)
526                .delete_policy(self.0.request, self.0.options)
527                .await
528                .map(gax::response::Response::into_body)
529        }
530
531        /// Creates a [Poller][lro::Poller] to work with `delete_policy`.
532        pub fn poller(
533            self,
534        ) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
535            type Operation = lro::internal::Operation<
536                crate::model::Policy,
537                crate::model::PolicyOperationMetadata,
538            >;
539            let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
540            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
541
542            let stub = self.0.stub.clone();
543            let mut options = self.0.options.clone();
544            options.set_retry_policy(gax::retry_policy::NeverRetry);
545            let query = move |name| {
546                let stub = stub.clone();
547                let options = options.clone();
548                async {
549                    let op = GetOperation::new(stub)
550                        .set_name(name)
551                        .with_options(options)
552                        .send()
553                        .await?;
554                    Ok(Operation::new(op))
555                }
556            };
557
558            let start = move || async {
559                let op = self.send().await?;
560                Ok(Operation::new(op))
561            };
562
563            lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
564        }
565
566        /// Sets the value of [name][crate::model::DeletePolicyRequest::name].
567        ///
568        /// This is a **required** field for requests.
569        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
570            self.0.request.name = v.into();
571            self
572        }
573
574        /// Sets the value of [etag][crate::model::DeletePolicyRequest::etag].
575        pub fn set_etag<T: Into<std::string::String>>(mut self, v: T) -> Self {
576            self.0.request.etag = v.into();
577            self
578        }
579    }
580
581    #[doc(hidden)]
582    impl gax::options::internal::RequestBuilder for DeletePolicy {
583        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
584            &mut self.0.options
585        }
586    }
587
588    /// The request builder for [Policies::get_operation][crate::client::Policies::get_operation] calls.
589    ///
590    /// # Example
591    /// ```no_run
592    /// # use google_cloud_iam_v2::builder;
593    /// use builder::policies::GetOperation;
594    /// # tokio_test::block_on(async {
595    ///
596    /// let builder = prepare_request_builder();
597    /// let response = builder.send().await?;
598    /// # gax::Result::<()>::Ok(()) });
599    ///
600    /// fn prepare_request_builder() -> GetOperation {
601    ///   # panic!();
602    ///   // ... details omitted ...
603    /// }
604    /// ```
605    #[derive(Clone, Debug)]
606    pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
607
608    impl GetOperation {
609        pub(crate) fn new(stub: std::sync::Arc<dyn super::super::stub::dynamic::Policies>) -> Self {
610            Self(RequestBuilder::new(stub))
611        }
612
613        /// Sets the full request, replacing any prior values.
614        pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
615            mut self,
616            v: V,
617        ) -> Self {
618            self.0.request = v.into();
619            self
620        }
621
622        /// Sets all the options, replacing any prior values.
623        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
624            self.0.options = v.into();
625            self
626        }
627
628        /// Sends the request.
629        pub async fn send(self) -> Result<longrunning::model::Operation> {
630            (*self.0.stub)
631                .get_operation(self.0.request, self.0.options)
632                .await
633                .map(gax::response::Response::into_body)
634        }
635
636        /// Sets the value of [name][longrunning::model::GetOperationRequest::name].
637        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
638            self.0.request.name = v.into();
639            self
640        }
641    }
642
643    #[doc(hidden)]
644    impl gax::options::internal::RequestBuilder for GetOperation {
645        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
646            &mut self.0.options
647        }
648    }
649}