Skip to main content

unitycatalog_client/codegen/recipients/
builders.rs

1// @generated — do not edit by hand.
2#![allow(unused_mut)]
3#![allow(unused_imports)]
4#[cfg(not(target_arch = "wasm32"))]
5type BoxFut<'a, T> = ::futures::future::BoxFuture<'a, T>;
6#[cfg(target_arch = "wasm32")]
7type BoxFut<'a, T> = ::futures::future::LocalBoxFuture<'a, T>;
8#[cfg(not(target_arch = "wasm32"))]
9type BoxStr<'a, T> = ::futures::stream::BoxStream<'a, T>;
10#[cfg(target_arch = "wasm32")]
11type BoxStr<'a, T> = ::futures::stream::LocalBoxStream<'a, T>;
12use super::super::stream_paginated;
13use super::client::*;
14use crate::Result;
15use futures::{StreamExt, TryStreamExt};
16use std::future::IntoFuture;
17use unitycatalog_common::models::recipients::v1::*;
18/// Builder for listing recipients
19pub struct ListRecipientsBuilder {
20    client: RecipientServiceClient,
21    request: ListRecipientsRequest,
22}
23impl ListRecipientsBuilder {
24    /// Create a new builder instance.
25    /// Obtain via the corresponding method on `RecipientServiceClient`.
26    pub(crate) fn new(client: RecipientServiceClient) -> Self {
27        let request = ListRecipientsRequest {
28            ..Default::default()
29        };
30        Self { client, request }
31    }
32    /// The maximum number of results per page that should be returned.
33    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
34        self.request.max_results = max_results.into();
35        self
36    }
37    /// Opaque pagination token to go to next page based on previous query.
38    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
39        self.request.page_token = page_token.into();
40        self
41    }
42    /// Convert paginated request into stream of results
43    pub fn into_stream(self) -> BoxStr<'static, Result<Recipient>> {
44        let remaining = self.request.max_results;
45        let stream = stream_paginated(
46            (self, remaining),
47            move |(mut builder, mut remaining), page_token| async move {
48                builder.request.page_token = page_token;
49                let res = builder.client.list_recipients(&builder.request).await?;
50                if let Some(ref mut rem) = remaining {
51                    *rem -= res.recipients.len() as i32;
52                }
53                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
54                    None
55                } else {
56                    res.next_page_token.clone()
57                };
58                Ok((res, (builder, remaining), next_page_token))
59            },
60        )
61        .map_ok(|resp| futures::stream::iter(resp.recipients.into_iter().map(Ok)))
62        .try_flatten();
63        #[cfg(not(target_arch = "wasm32"))]
64        let stream = stream.boxed();
65        #[cfg(target_arch = "wasm32")]
66        let stream = stream.boxed_local();
67        stream
68    }
69}
70impl IntoFuture for ListRecipientsBuilder {
71    type Output = Result<ListRecipientsResponse>;
72    type IntoFuture = BoxFut<'static, Self::Output>;
73    fn into_future(self) -> Self::IntoFuture {
74        let client = self.client;
75        let request = self.request;
76        Box::pin(async move { client.list_recipients(&request).await })
77    }
78}
79/// Builder for creating a recipient
80pub struct CreateRecipientBuilder {
81    client: RecipientServiceClient,
82    request: CreateRecipientRequest,
83}
84impl CreateRecipientBuilder {
85    /// Create a new builder instance.
86    /// Obtain via the corresponding method on `RecipientServiceClient`.
87    pub(crate) fn new(
88        client: RecipientServiceClient,
89        name: impl Into<String>,
90        authentication_type: AuthenticationType,
91        owner: impl Into<String>,
92    ) -> Self {
93        let request = CreateRecipientRequest {
94            name: name.into(),
95            authentication_type: buffa::EnumValue::Known(authentication_type),
96            owner: owner.into(),
97            ..Default::default()
98        };
99        Self { client, request }
100    }
101    /// Description about the recipient.
102    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
103        self.request.comment = comment.into();
104        self
105    }
106    /** Recipient properties as map of string key-value pairs.
107
108    When provided in update request, the specified properties will override the existing properties.
109    To add and remove properties, one would need to perform a read-modify-write.*/
110    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
111    where
112        I: IntoIterator<Item = (K, V)>,
113        K: Into<String>,
114        V: Into<String>,
115    {
116        self.request.properties = properties
117            .into_iter()
118            .map(|(k, v)| (k.into(), v.into()))
119            .collect();
120        self
121    }
122    /// Expiration timestamp of the token, in epoch milliseconds.
123    pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
124        self.request.expiration_time = expiration_time.into();
125        self
126    }
127}
128impl IntoFuture for CreateRecipientBuilder {
129    type Output = Result<Recipient>;
130    type IntoFuture = BoxFut<'static, Self::Output>;
131    fn into_future(self) -> Self::IntoFuture {
132        let client = self.client;
133        let request = self.request;
134        Box::pin(async move { client.create_recipient(&request).await })
135    }
136}
137/// Builder for getting a recipient
138pub struct GetRecipientBuilder {
139    client: RecipientServiceClient,
140    request: GetRecipientRequest,
141}
142impl GetRecipientBuilder {
143    /// Create a new builder instance.
144    /// Obtain via the corresponding method on `RecipientServiceClient`.
145    pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
146        let request = GetRecipientRequest {
147            name: name.into(),
148            ..Default::default()
149        };
150        Self { client, request }
151    }
152}
153impl IntoFuture for GetRecipientBuilder {
154    type Output = Result<Recipient>;
155    type IntoFuture = BoxFut<'static, Self::Output>;
156    fn into_future(self) -> Self::IntoFuture {
157        let client = self.client;
158        let request = self.request;
159        Box::pin(async move { client.get_recipient(&request).await })
160    }
161}
162/// Builder for updating a recipient
163pub struct UpdateRecipientBuilder {
164    client: RecipientServiceClient,
165    request: UpdateRecipientRequest,
166}
167impl UpdateRecipientBuilder {
168    /// Create a new builder instance.
169    /// Obtain via the corresponding method on `RecipientServiceClient`.
170    pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
171        let request = UpdateRecipientRequest {
172            name: name.into(),
173            ..Default::default()
174        };
175        Self { client, request }
176    }
177    /// New name for the recipient
178    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
179        self.request.new_name = new_name.into();
180        self
181    }
182    /// Username of the recipient owner.
183    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
184        self.request.owner = owner.into();
185        self
186    }
187    /// Description about the recipient.
188    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
189        self.request.comment = comment.into();
190        self
191    }
192    /** Recipient properties as map of string key-value pairs.
193
194    When provided in update request, the specified properties will override the existing properties.
195    To add and remove properties, one would need to perform a read-modify-write.*/
196    pub fn with_properties<I, K, V>(mut self, properties: I) -> Self
197    where
198        I: IntoIterator<Item = (K, V)>,
199        K: Into<String>,
200        V: Into<String>,
201    {
202        self.request.properties = properties
203            .into_iter()
204            .map(|(k, v)| (k.into(), v.into()))
205            .collect();
206        self
207    }
208    /// Expiration timestamp of the token, in epoch milliseconds.
209    pub fn with_expiration_time(mut self, expiration_time: impl Into<Option<i64>>) -> Self {
210        self.request.expiration_time = expiration_time.into();
211        self
212    }
213}
214impl IntoFuture for UpdateRecipientBuilder {
215    type Output = Result<Recipient>;
216    type IntoFuture = BoxFut<'static, Self::Output>;
217    fn into_future(self) -> Self::IntoFuture {
218        let client = self.client;
219        let request = self.request;
220        Box::pin(async move { client.update_recipient(&request).await })
221    }
222}
223/// Builder for deleting a recipient
224pub struct DeleteRecipientBuilder {
225    client: RecipientServiceClient,
226    request: DeleteRecipientRequest,
227}
228impl DeleteRecipientBuilder {
229    /// Create a new builder instance.
230    /// Obtain via the corresponding method on `RecipientServiceClient`.
231    pub(crate) fn new(client: RecipientServiceClient, name: impl Into<String>) -> Self {
232        let request = DeleteRecipientRequest {
233            name: name.into(),
234            ..Default::default()
235        };
236        Self { client, request }
237    }
238}
239impl IntoFuture for DeleteRecipientBuilder {
240    type Output = Result<()>;
241    type IntoFuture = BoxFut<'static, Self::Output>;
242    fn into_future(self) -> Self::IntoFuture {
243        let client = self.client;
244        let request = self.request;
245        Box::pin(async move { client.delete_recipient(&request).await })
246    }
247}