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(|e| e as i32);
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: purpose as i32,
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 = azure_service_principal.into();
115        self
116    }
117    /// The Azure managed identity configuration.
118    pub fn with_azure_managed_identity(
119        mut self,
120        azure_managed_identity: impl Into<Option<AzureManagedIdentity>>,
121    ) -> Self {
122        self.request.azure_managed_identity = azure_managed_identity.into();
123        self
124    }
125    /// The Azure storage key configuration.
126    pub fn with_azure_storage_key(
127        mut self,
128        azure_storage_key: impl Into<Option<AzureStorageKey>>,
129    ) -> Self {
130        self.request.azure_storage_key = azure_storage_key.into();
131        self
132    }
133    /// The AWS IAM role configuration.
134    pub fn with_aws_iam_role(mut self, aws_iam_role: impl Into<Option<AwsIamRoleConfig>>) -> Self {
135        self.request.aws_iam_role = aws_iam_role.into();
136        self
137    }
138    /// The Databricks managed GCP service account configuration.
139    pub fn with_databricks_gcp_service_account(
140        mut self,
141        databricks_gcp_service_account: impl Into<Option<DatabricksGcpServiceAccount>>,
142    ) -> Self {
143        self.request.databricks_gcp_service_account = databricks_gcp_service_account.into();
144        self
145    }
146}
147impl IntoFuture for CreateCredentialBuilder {
148    type Output = Result<Credential>;
149    type IntoFuture = BoxFut<'static, Self::Output>;
150    fn into_future(self) -> Self::IntoFuture {
151        let client = self.client;
152        let request = self.request;
153        Box::pin(async move { client.create_credential(&request).await })
154    }
155}
156/// Builder for getting a credential
157pub struct GetCredentialBuilder {
158    client: CredentialServiceClient,
159    request: GetCredentialRequest,
160}
161impl GetCredentialBuilder {
162    /// Create a new builder instance.
163    /// Obtain via the corresponding method on `CredentialServiceClient`.
164    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
165        let request = GetCredentialRequest { name: name.into() };
166        Self { client, request }
167    }
168}
169impl IntoFuture for GetCredentialBuilder {
170    type Output = Result<Credential>;
171    type IntoFuture = BoxFut<'static, Self::Output>;
172    fn into_future(self) -> Self::IntoFuture {
173        let client = self.client;
174        let request = self.request;
175        Box::pin(async move { client.get_credential(&request).await })
176    }
177}
178/// Builder for updating a credential
179pub struct UpdateCredentialBuilder {
180    client: CredentialServiceClient,
181    request: UpdateCredentialRequest,
182}
183impl UpdateCredentialBuilder {
184    /// Create a new builder instance.
185    /// Obtain via the corresponding method on `CredentialServiceClient`.
186    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
187        let request = UpdateCredentialRequest {
188            name: name.into(),
189            ..Default::default()
190        };
191        Self { client, request }
192    }
193    /// New name of the credential.
194    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
195        self.request.new_name = new_name.into();
196        self
197    }
198    /// Comment associated with the credential.
199    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
200        self.request.comment = comment.into();
201        self
202    }
203    /// Whether the credential is usable only for read operations. Only applicable when purpose is STORAGE.
204    pub fn with_read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
205        self.request.read_only = read_only.into();
206        self
207    }
208    /// Username of current owner of credential.
209    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
210        self.request.owner = owner.into();
211        self
212    }
213    /// Supply true to this argument to skip validation of the updated credential.
214    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
215        self.request.skip_validation = skip_validation.into();
216        self
217    }
218    /** Force an update even if there are dependent services (when purpose is SERVICE)
219    or dependent external locations and external tables (when purpose is STORAGE).*/
220    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
221        self.request.force = force.into();
222        self
223    }
224    /// The Azure service principal configuration.
225    pub fn with_azure_service_principal(
226        mut self,
227        azure_service_principal: impl Into<Option<AzureServicePrincipal>>,
228    ) -> Self {
229        self.request.azure_service_principal = azure_service_principal.into();
230        self
231    }
232    /// The Azure managed identity configuration.
233    pub fn with_azure_managed_identity(
234        mut self,
235        azure_managed_identity: impl Into<Option<AzureManagedIdentity>>,
236    ) -> Self {
237        self.request.azure_managed_identity = azure_managed_identity.into();
238        self
239    }
240    /// The Azure storage key configuration.
241    pub fn with_azure_storage_key(
242        mut self,
243        azure_storage_key: impl Into<Option<AzureStorageKey>>,
244    ) -> Self {
245        self.request.azure_storage_key = azure_storage_key.into();
246        self
247    }
248    /// The AWS IAM role configuration.
249    pub fn with_aws_iam_role(mut self, aws_iam_role: impl Into<Option<AwsIamRoleConfig>>) -> Self {
250        self.request.aws_iam_role = aws_iam_role.into();
251        self
252    }
253    /// The Databricks managed GCP service account configuration.
254    pub fn with_databricks_gcp_service_account(
255        mut self,
256        databricks_gcp_service_account: impl Into<Option<DatabricksGcpServiceAccount>>,
257    ) -> Self {
258        self.request.databricks_gcp_service_account = databricks_gcp_service_account.into();
259        self
260    }
261}
262impl IntoFuture for UpdateCredentialBuilder {
263    type Output = Result<Credential>;
264    type IntoFuture = BoxFut<'static, Self::Output>;
265    fn into_future(self) -> Self::IntoFuture {
266        let client = self.client;
267        let request = self.request;
268        Box::pin(async move { client.update_credential(&request).await })
269    }
270}
271/// Builder for deleting a credential
272pub struct DeleteCredentialBuilder {
273    client: CredentialServiceClient,
274    request: DeleteCredentialRequest,
275}
276impl DeleteCredentialBuilder {
277    /// Create a new builder instance.
278    /// Obtain via the corresponding method on `CredentialServiceClient`.
279    pub(crate) fn new(client: CredentialServiceClient, name: impl Into<String>) -> Self {
280        let request = DeleteCredentialRequest { name: name.into() };
281        Self { client, request }
282    }
283}
284impl IntoFuture for DeleteCredentialBuilder {
285    type Output = Result<()>;
286    type IntoFuture = BoxFut<'static, Self::Output>;
287    fn into_future(self) -> Self::IntoFuture {
288        let client = self.client;
289        let request = self.request;
290        Box::pin(async move { client.delete_credential(&request).await })
291    }
292}