unitycatalog_client/codegen/credentials/
builders.rs1#![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::*;
12pub struct ListCredentialsBuilder {
14 client: CredentialServiceClient,
15 request: ListCredentialsRequest,
16}
17impl ListCredentialsBuilder {
18 pub(crate) fn new(client: CredentialServiceClient) -> Self {
21 let request = ListCredentialsRequest {
22 ..Default::default()
23 };
24 Self { client, request }
25 }
26 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 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 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 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}
74pub struct CreateCredentialBuilder {
76 client: CredentialServiceClient,
77 request: CreateCredentialRequest,
78}
79impl CreateCredentialBuilder {
80 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
96 self.request.comment = comment.into();
97 self
98 }
99 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 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 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 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 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 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 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}
156pub struct GetCredentialBuilder {
158 client: CredentialServiceClient,
159 request: GetCredentialRequest,
160}
161impl GetCredentialBuilder {
162 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}
178pub struct UpdateCredentialBuilder {
180 client: CredentialServiceClient,
181 request: UpdateCredentialRequest,
182}
183impl UpdateCredentialBuilder {
184 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 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 pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
200 self.request.comment = comment.into();
201 self
202 }
203 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 pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
210 self.request.owner = owner.into();
211 self
212 }
213 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 pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
221 self.request.force = force.into();
222 self
223 }
224 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 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 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 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 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}
271pub struct DeleteCredentialBuilder {
273 client: CredentialServiceClient,
274 request: DeleteCredentialRequest,
275}
276impl DeleteCredentialBuilder {
277 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}