google_cloud_iam_v2/
builder.rs1pub mod policies {
18 use crate::Result;
19
20 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 #[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 #[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 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 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 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 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 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 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 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 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 #[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 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 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 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 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 #[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 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 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 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 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 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 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 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 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 #[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 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 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 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 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 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 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 #[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 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 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 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 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 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 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 #[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 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 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 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 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}