Skip to main content

unitycatalog_client/codegen/credentials/
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::credentials::v1::*;
12/// Builder for listing credentials
13pub struct ListCredentialsBuilder {
14    client: CredentialServiceClient,
15    request: ListCredentialsRequest,
16}
17impl ListCredentialsBuilder {
18    /// Create a new builder instance.
19    /// Obtain via the corresponding method on `CredentialServiceClient`.
20    pub(crate) fn new(client: CredentialServiceClient) -> Self {
21        let request = ListCredentialsRequest {
22            ..Default::default()
23        };
24        Self { client, request }
25    }
26    /// Return only credentials for the specified purpose.
27    pub fn with_purpose(mut self, purpose: impl Into<Option<Purpose>>) -> Self {
28        self.request.purpose = purpose.into().map(buffa::EnumValue::Known);
29        self
30    }
31    /// The maximum number of results per page that should be returned.
32    pub fn with_max_results(mut self, max_results: impl Into<Option<i32>>) -> Self {
33        self.request.max_results = max_results.into();
34        self
35    }
36    /// Opaque pagination token to go to next page based on previous query.
37    pub fn with_page_token(mut self, page_token: impl Into<Option<String>>) -> Self {
38        self.request.page_token = page_token.into();
39        self
40    }
41    /// Convert paginated request into stream of results
42    pub fn into_stream(self) -> BoxStr<'static, Result<Credential>> {
43        let remaining = self.request.max_results;
44        let stream = stream_paginated(
45            (self, remaining),
46            move |(mut builder, mut remaining), page_token| async move {
47                builder.request.page_token = page_token;
48                let res = builder.client.list_credentials(&builder.request).await?;
49                if let Some(ref mut rem) = remaining {
50                    *rem -= res.credentials.len() as i32;
51                }
52                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
53                    None
54                } else {
55                    res.next_page_token.clone()
56                };
57                Ok((res, (builder, remaining), next_page_token))
58            },
59        )
60        .map_ok(|resp| futures::stream::iter(resp.credentials.into_iter().map(Ok)))
61        .try_flatten();
62        stream.boxed()
63    }
64}
65impl IntoFuture for ListCredentialsBuilder {
66    type Output = Result<ListCredentialsResponse>;
67    type IntoFuture = BoxFut<'static, Self::Output>;
68    fn into_future(self) -> Self::IntoFuture {
69        let client = self.client;
70        let request = self.request;
71        Box::pin(async move { client.list_credentials(&request).await })
72    }
73}
74/// Builder for creating a credential
75pub struct CreateCredentialBuilder {
76    client: CredentialServiceClient,
77    request: CreateCredentialRequest,
78}
79impl CreateCredentialBuilder {
80    /// Create a new builder instance.
81    /// Obtain via the corresponding method on `CredentialServiceClient`.
82    pub(crate) fn new(
83        client: CredentialServiceClient,
84        name: impl Into<String>,
85        purpose: Purpose,
86    ) -> Self {
87        let request = CreateCredentialRequest {
88            name: name.into(),
89            purpose: buffa::EnumValue::Known(purpose),
90            ..Default::default()
91        };
92        Self { client, request }
93    }
94    /// Comment associated with the credential.
95    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
96        self.request.comment = comment.into();
97        self
98    }
99    /// Whether the credential is usable only for read operations. Only applicable when purpose is STORAGE.
100    pub fn with_read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
101        self.request.read_only = read_only.into();
102        self
103    }
104    /// Optional. Supplying true to this argument skips validation of the created set of credentials.
105    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
106        self.request.skip_validation = skip_validation.into();
107        self
108    }
109    /// The Azure service principal configuration.
110    pub fn with_azure_service_principal(
111        mut self,
112        azure_service_principal: impl Into<Option<AzureServicePrincipal>>,
113    ) -> Self {
114        self.request.azure_service_principal = {
115            let azure_service_principal: ::core::option::Option<_> = azure_service_principal.into();
116            buffa::MessageField::from(azure_service_principal)
117        };
118        self
119    }
120    /// The Azure managed identity configuration.
121    pub fn with_azure_managed_identity(
122        mut self,
123        azure_managed_identity: impl Into<Option<AzureManagedIdentity>>,
124    ) -> Self {
125        self.request.azure_managed_identity = {
126            let azure_managed_identity: ::core::option::Option<_> = azure_managed_identity.into();
127            buffa::MessageField::from(azure_managed_identity)
128        };
129        self
130    }
131    /// The Azure storage key configuration.
132    pub fn with_azure_storage_key(
133        mut self,
134        azure_storage_key: impl Into<Option<AzureStorageKey>>,
135    ) -> Self {
136        self.request.azure_storage_key = {
137            let azure_storage_key: ::core::option::Option<_> = azure_storage_key.into();
138            buffa::MessageField::from(azure_storage_key)
139        };
140        self
141    }
142    /// The AWS IAM role configuration.
143    pub fn with_aws_iam_role(mut self, aws_iam_role: impl Into<Option<AwsIamRoleConfig>>) -> Self {
144        self.request.aws_iam_role = {
145            let aws_iam_role: ::core::option::Option<_> = aws_iam_role.into();
146            buffa::MessageField::from(aws_iam_role)
147        };
148        self
149    }
150    /// The Databricks managed GCP service account configuration.
151    pub fn with_databricks_gcp_service_account(
152        mut self,
153        databricks_gcp_service_account: impl Into<Option<DatabricksGcpServiceAccount>>,
154    ) -> Self {
155        self.request.databricks_gcp_service_account = {
156            let databricks_gcp_service_account: ::core::option::Option<_> =
157                databricks_gcp_service_account.into();
158            buffa::MessageField::from(databricks_gcp_service_account)
159        };
160        self
161    }
162}
163impl IntoFuture for CreateCredentialBuilder {
164    type Output = Result<Credential>;
165    type IntoFuture = BoxFut<'static, Self::Output>;
166    fn into_future(self) -> Self::IntoFuture {
167        let client = self.client;
168        let request = self.request;
169        Box::pin(async move { client.create_credential(&request).await })
170    }
171}
172/// Builder for getting a credential
173pub struct GetCredentialBuilder {
174    client: CredentialServiceClient,
175    request: GetCredentialRequest,
176}
177impl GetCredentialBuilder {
178    /// Create a new builder instance.
179    /// Obtain via the corresponding method on `CredentialServiceClient`.
180    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
181        let request = GetCredentialRequest {
182            name: name.into(),
183            ..Default::default()
184        };
185        Self { client, request }
186    }
187}
188impl IntoFuture for GetCredentialBuilder {
189    type Output = Result<Credential>;
190    type IntoFuture = BoxFut<'static, Self::Output>;
191    fn into_future(self) -> Self::IntoFuture {
192        let client = self.client;
193        let request = self.request;
194        Box::pin(async move { client.get_credential(&request).await })
195    }
196}
197/// Builder for updating a credential
198pub struct UpdateCredentialBuilder {
199    client: CredentialServiceClient,
200    request: UpdateCredentialRequest,
201}
202impl UpdateCredentialBuilder {
203    /// Create a new builder instance.
204    /// Obtain via the corresponding method on `CredentialServiceClient`.
205    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
206        let request = UpdateCredentialRequest {
207            name: name.into(),
208            ..Default::default()
209        };
210        Self { client, request }
211    }
212    /// New name of the credential.
213    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
214        self.request.new_name = new_name.into();
215        self
216    }
217    /// Comment associated with the credential.
218    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
219        self.request.comment = comment.into();
220        self
221    }
222    /// Whether the credential is usable only for read operations. Only applicable when purpose is STORAGE.
223    pub fn with_read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
224        self.request.read_only = read_only.into();
225        self
226    }
227    /// Username of current owner of credential.
228    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
229        self.request.owner = owner.into();
230        self
231    }
232    /// Supply true to this argument to skip validation of the updated credential.
233    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
234        self.request.skip_validation = skip_validation.into();
235        self
236    }
237    /** Force an update even if there are dependent services (when purpose is SERVICE)
238    or dependent external locations and external tables (when purpose is STORAGE).*/
239    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
240        self.request.force = force.into();
241        self
242    }
243    /// The Azure service principal configuration.
244    pub fn with_azure_service_principal(
245        mut self,
246        azure_service_principal: impl Into<Option<AzureServicePrincipal>>,
247    ) -> Self {
248        self.request.azure_service_principal = {
249            let azure_service_principal: ::core::option::Option<_> = azure_service_principal.into();
250            buffa::MessageField::from(azure_service_principal)
251        };
252        self
253    }
254    /// The Azure managed identity configuration.
255    pub fn with_azure_managed_identity(
256        mut self,
257        azure_managed_identity: impl Into<Option<AzureManagedIdentity>>,
258    ) -> Self {
259        self.request.azure_managed_identity = {
260            let azure_managed_identity: ::core::option::Option<_> = azure_managed_identity.into();
261            buffa::MessageField::from(azure_managed_identity)
262        };
263        self
264    }
265    /// The Azure storage key configuration.
266    pub fn with_azure_storage_key(
267        mut self,
268        azure_storage_key: impl Into<Option<AzureStorageKey>>,
269    ) -> Self {
270        self.request.azure_storage_key = {
271            let azure_storage_key: ::core::option::Option<_> = azure_storage_key.into();
272            buffa::MessageField::from(azure_storage_key)
273        };
274        self
275    }
276    /// The AWS IAM role configuration.
277    pub fn with_aws_iam_role(mut self, aws_iam_role: impl Into<Option<AwsIamRoleConfig>>) -> Self {
278        self.request.aws_iam_role = {
279            let aws_iam_role: ::core::option::Option<_> = aws_iam_role.into();
280            buffa::MessageField::from(aws_iam_role)
281        };
282        self
283    }
284    /// The Databricks managed GCP service account configuration.
285    pub fn with_databricks_gcp_service_account(
286        mut self,
287        databricks_gcp_service_account: impl Into<Option<DatabricksGcpServiceAccount>>,
288    ) -> Self {
289        self.request.databricks_gcp_service_account = {
290            let databricks_gcp_service_account: ::core::option::Option<_> =
291                databricks_gcp_service_account.into();
292            buffa::MessageField::from(databricks_gcp_service_account)
293        };
294        self
295    }
296}
297impl IntoFuture for UpdateCredentialBuilder {
298    type Output = Result<Credential>;
299    type IntoFuture = BoxFut<'static, Self::Output>;
300    fn into_future(self) -> Self::IntoFuture {
301        let client = self.client;
302        let request = self.request;
303        Box::pin(async move { client.update_credential(&request).await })
304    }
305}
306/// Builder for deleting a credential
307pub struct DeleteCredentialBuilder {
308    client: CredentialServiceClient,
309    request: DeleteCredentialRequest,
310}
311impl DeleteCredentialBuilder {
312    /// Create a new builder instance.
313    /// Obtain via the corresponding method on `CredentialServiceClient`.
314    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
315        let request = DeleteCredentialRequest {
316            name: name.into(),
317            ..Default::default()
318        };
319        Self { client, request }
320    }
321}
322impl IntoFuture for DeleteCredentialBuilder {
323    type Output = Result<()>;
324    type IntoFuture = BoxFut<'static, Self::Output>;
325    fn into_future(self) -> Self::IntoFuture {
326        let client = self.client;
327        let request = self.request;
328        Box::pin(async move { client.delete_credential(&request).await })
329    }
330}