google-cloud-iam-v1 1.8.0

Google Cloud Client Libraries for Rust - IAM Meta API
Documentation
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

pub mod iam_policy {
    use crate::Result;

    /// A builder for [IAMPolicy][crate::client::IAMPolicy].
    ///
    /// ```
    /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
    /// # use google_cloud_iam_v1::*;
    /// # use builder::iam_policy::ClientBuilder;
    /// # use client::IAMPolicy;
    /// let builder : ClientBuilder = IAMPolicy::builder();
    /// let client = builder
    ///     .with_endpoint("https://iam-meta-api.googleapis.com")
    ///     .build().await?;
    /// # Ok(()) }
    /// ```
    pub type ClientBuilder = crate::ClientBuilder<client::Factory, gaxi::options::Credentials>;

    pub(crate) mod client {
        use super::super::super::client::IAMPolicy;
        pub struct Factory;
        impl crate::ClientFactory for Factory {
            type Client = IAMPolicy;
            type Credentials = gaxi::options::Credentials;
            async fn build(
                self,
                config: gaxi::options::ClientConfig,
            ) -> crate::ClientBuilderResult<Self::Client> {
                Self::Client::new(config).await
            }
        }
    }

    /// Common implementation for [crate::client::IAMPolicy] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
        request: R,
        options: crate::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
        ) -> Self {
            Self {
                stub,
                request: R::default(),
                options: crate::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [IAMPolicy::set_iam_policy][crate::client::IAMPolicy::set_iam_policy] calls.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_iam_v1::builder::iam_policy::SetIamPolicy;
    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # Ok(()) }
    ///
    /// fn prepare_request_builder() -> SetIamPolicy {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct SetIamPolicy(RequestBuilder<crate::model::SetIamPolicyRequest>);

    impl SetIamPolicy {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::SetIamPolicyRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::Policy> {
            (*self.0.stub)
                .set_iam_policy(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [resource][crate::model::SetIamPolicyRequest::resource].
        ///
        /// This is a **required** field for requests.
        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.resource = v.into();
            self
        }

        /// Sets the value of [policy][crate::model::SetIamPolicyRequest::policy].
        ///
        /// This is a **required** field for requests.
        pub fn set_policy<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::Policy>,
        {
            self.0.request.policy = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [policy][crate::model::SetIamPolicyRequest::policy].
        ///
        /// This is a **required** field for requests.
        pub fn set_or_clear_policy<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::Policy>,
        {
            self.0.request.policy = v.map(|x| x.into());
            self
        }

        /// Sets the value of [update_mask][crate::model::SetIamPolicyRequest::update_mask].
        pub fn set_update_mask<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<wkt::FieldMask>,
        {
            self.0.request.update_mask = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [update_mask][crate::model::SetIamPolicyRequest::update_mask].
        pub fn set_or_clear_update_mask<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<wkt::FieldMask>,
        {
            self.0.request.update_mask = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for SetIamPolicy {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [IAMPolicy::get_iam_policy][crate::client::IAMPolicy::get_iam_policy] calls.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_iam_v1::builder::iam_policy::GetIamPolicy;
    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # Ok(()) }
    ///
    /// fn prepare_request_builder() -> GetIamPolicy {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct GetIamPolicy(RequestBuilder<crate::model::GetIamPolicyRequest>);

    impl GetIamPolicy {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::GetIamPolicyRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::Policy> {
            (*self.0.stub)
                .get_iam_policy(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [resource][crate::model::GetIamPolicyRequest::resource].
        ///
        /// This is a **required** field for requests.
        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.resource = v.into();
            self
        }

        /// Sets the value of [options][crate::model::GetIamPolicyRequest::options].
        pub fn set_options<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::GetPolicyOptions>,
        {
            self.0.request.options = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [options][crate::model::GetIamPolicyRequest::options].
        pub fn set_or_clear_options<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::GetPolicyOptions>,
        {
            self.0.request.options = v.map(|x| x.into());
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for GetIamPolicy {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [IAMPolicy::test_iam_permissions][crate::client::IAMPolicy::test_iam_permissions] calls.
    ///
    /// # Example
    /// ```
    /// # use google_cloud_iam_v1::builder::iam_policy::TestIamPermissions;
    /// # async fn sample() -> google_cloud_iam_v1::Result<()> {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # Ok(()) }
    ///
    /// fn prepare_request_builder() -> TestIamPermissions {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct TestIamPermissions(RequestBuilder<crate::model::TestIamPermissionsRequest>);

    impl TestIamPermissions {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::IAMPolicy>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::TestIamPermissionsRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<crate::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::TestIamPermissionsResponse> {
            (*self.0.stub)
                .test_iam_permissions(self.0.request, self.0.options)
                .await
                .map(crate::Response::into_body)
        }

        /// Sets the value of [resource][crate::model::TestIamPermissionsRequest::resource].
        ///
        /// This is a **required** field for requests.
        pub fn set_resource<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.resource = v.into();
            self
        }

        /// Sets the value of [permissions][crate::model::TestIamPermissionsRequest::permissions].
        ///
        /// This is a **required** field for requests.
        pub fn set_permissions<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<std::string::String>,
        {
            use std::iter::Iterator;
            self.0.request.permissions = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    #[doc(hidden)]
    impl crate::RequestBuilder for TestIamPermissions {
        fn request_options(&mut self) -> &mut crate::RequestOptions {
            &mut self.0.options
        }
    }
}