gcp_sdk_iam_v2/
builders.rspub mod policies {
use crate::Result;
use std::sync::Arc;
#[derive(Clone, Debug)]
pub struct RequestBuilder<R: std::default::Default> {
stub: Arc<dyn crate::stubs::dynamic::Policies>,
request: R,
options: gax::options::RequestOptions,
}
impl<R> RequestBuilder<R>
where
R: std::default::Default,
{
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self {
stub,
request: R::default(),
options: gax::options::RequestOptions::default(),
}
}
}
#[derive(Clone, Debug)]
pub struct ListPolicies(RequestBuilder<crate::model::ListPoliciesRequest>);
impl ListPolicies {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<crate::model::ListPoliciesRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<crate::model::ListPoliciesResponse> {
(*self.0.stub)
.list_policies(self.0.request, self.0.options)
.await
}
#[cfg(feature = "unstable-stream")]
pub async fn stream(
self,
) -> gax::paginator::Paginator<crate::model::ListPoliciesResponse, gax::error::Error>
{
let token = gax::paginator::extract_token(&self.0.request.page_token);
let execute = move |token: String| {
let builder = self.clone();
builder.0.request.clone().set_page_token(token);
builder.send()
};
gax::paginator::Paginator::new(token, execute)
}
pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.parent = v.into();
self
}
pub fn set_page_size<T: Into<i32>>(mut self, v: T) -> Self {
self.0.request.page_size = v.into();
self
}
pub fn set_page_token<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.page_token = v.into();
self
}
}
impl gax::options::RequestBuilder for ListPolicies {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
#[derive(Clone, Debug)]
pub struct GetPolicy(RequestBuilder<crate::model::GetPolicyRequest>);
impl GetPolicy {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<crate::model::GetPolicyRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<crate::model::Policy> {
(*self.0.stub)
.get_policy(self.0.request, self.0.options)
.await
}
pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.name = v.into();
self
}
}
impl gax::options::RequestBuilder for GetPolicy {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
#[derive(Clone, Debug)]
pub struct CreatePolicy(RequestBuilder<crate::model::CreatePolicyRequest>);
impl CreatePolicy {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<crate::model::CreatePolicyRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<longrunning::model::Operation> {
(*self.0.stub)
.create_policy(self.0.request, self.0.options)
.await
}
pub fn poller(
self,
) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
type Operation =
lro::Operation<crate::model::Policy, crate::model::PolicyOperationMetadata>;
let polling_policy = self.0.stub.get_polling_policy(&self.0.options);
let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
let stub = self.0.stub.clone();
let mut options = self.0.options.clone();
options.set_retry_policy(gax::retry_policy::NeverRetry);
let query = move |name| {
let stub = stub.clone();
let options = options.clone();
async {
let op = GetOperation::new(stub)
.set_name(name)
.with_options(options)
.send()
.await?;
Ok(Operation::new(op))
}
};
let start = move || async {
let op = self.send().await?;
Ok(Operation::new(op))
};
lro::new_poller(polling_policy, polling_backoff_policy, start, query)
}
pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.parent = v.into();
self
}
pub fn set_policy<T: Into<std::option::Option<crate::model::Policy>>>(
mut self,
v: T,
) -> Self {
self.0.request.policy = v.into();
self
}
pub fn set_policy_id<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.policy_id = v.into();
self
}
}
impl gax::options::RequestBuilder for CreatePolicy {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
#[derive(Clone, Debug)]
pub struct UpdatePolicy(RequestBuilder<crate::model::UpdatePolicyRequest>);
impl UpdatePolicy {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<crate::model::UpdatePolicyRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<longrunning::model::Operation> {
(*self.0.stub)
.update_policy(self.0.request, self.0.options)
.await
}
pub fn poller(
self,
) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
type Operation =
lro::Operation<crate::model::Policy, crate::model::PolicyOperationMetadata>;
let polling_policy = self.0.stub.get_polling_policy(&self.0.options);
let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
let stub = self.0.stub.clone();
let mut options = self.0.options.clone();
options.set_retry_policy(gax::retry_policy::NeverRetry);
let query = move |name| {
let stub = stub.clone();
let options = options.clone();
async {
let op = GetOperation::new(stub)
.set_name(name)
.with_options(options)
.send()
.await?;
Ok(Operation::new(op))
}
};
let start = move || async {
let op = self.send().await?;
Ok(Operation::new(op))
};
lro::new_poller(polling_policy, polling_backoff_policy, start, query)
}
pub fn set_policy<T: Into<std::option::Option<crate::model::Policy>>>(
mut self,
v: T,
) -> Self {
self.0.request.policy = v.into();
self
}
}
impl gax::options::RequestBuilder for UpdatePolicy {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
#[derive(Clone, Debug)]
pub struct DeletePolicy(RequestBuilder<crate::model::DeletePolicyRequest>);
impl DeletePolicy {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<crate::model::DeletePolicyRequest>>(mut self, v: V) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<longrunning::model::Operation> {
(*self.0.stub)
.delete_policy(self.0.request, self.0.options)
.await
}
pub fn poller(
self,
) -> impl lro::Poller<crate::model::Policy, crate::model::PolicyOperationMetadata> {
type Operation =
lro::Operation<crate::model::Policy, crate::model::PolicyOperationMetadata>;
let polling_policy = self.0.stub.get_polling_policy(&self.0.options);
let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);
let stub = self.0.stub.clone();
let mut options = self.0.options.clone();
options.set_retry_policy(gax::retry_policy::NeverRetry);
let query = move |name| {
let stub = stub.clone();
let options = options.clone();
async {
let op = GetOperation::new(stub)
.set_name(name)
.with_options(options)
.send()
.await?;
Ok(Operation::new(op))
}
};
let start = move || async {
let op = self.send().await?;
Ok(Operation::new(op))
};
lro::new_poller(polling_policy, polling_backoff_policy, start, query)
}
pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.name = v.into();
self
}
pub fn set_etag<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.etag = v.into();
self
}
}
impl gax::options::RequestBuilder for DeletePolicy {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
#[derive(Clone, Debug)]
pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);
impl GetOperation {
pub(crate) fn new(stub: Arc<dyn crate::stubs::dynamic::Policies>) -> Self {
Self(RequestBuilder::new(stub))
}
pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
mut self,
v: V,
) -> Self {
self.0.request = v.into();
self
}
pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
self.0.options = v.into();
self
}
pub async fn send(self) -> Result<longrunning::model::Operation> {
(*self.0.stub)
.get_operation(self.0.request, self.0.options)
.await
}
pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
self.0.request.name = v.into();
self
}
}
impl gax::options::RequestBuilder for GetOperation {
fn request_options(&mut self) -> &mut gax::options::RequestOptions {
&mut self.0.options
}
}
}