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