Skip to main content

unitycatalog_client/codegen/external_locations/
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::external_locations::v1::*;
12/// Builder for listing external locations
13pub struct ListExternalLocationsBuilder {
14    client: ExternalLocationServiceClient,
15    request: ListExternalLocationsRequest,
16}
17impl ListExternalLocationsBuilder {
18    /// Create a new builder instance.
19    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
20    pub(crate) fn new(client: ExternalLocationServiceClient) -> Self {
21        let request = ListExternalLocationsRequest {
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    /// Whether to include schemas in the response for which the principal can only access selective metadata for
37    pub fn with_include_browse(mut self, include_browse: impl Into<Option<bool>>) -> Self {
38        self.request.include_browse = include_browse.into();
39        self
40    }
41    /// Convert paginated request into stream of results
42    pub fn into_stream(self) -> BoxStr<'static, Result<ExternalLocation>> {
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
49                    .client
50                    .list_external_locations(&builder.request)
51                    .await?;
52                if let Some(ref mut rem) = remaining {
53                    *rem -= res.external_locations.len() as i32;
54                }
55                let next_page_token = if remaining.is_some_and(|r| r <= 0) {
56                    None
57                } else {
58                    res.next_page_token.clone()
59                };
60                Ok((res, (builder, remaining), next_page_token))
61            },
62        )
63        .map_ok(|resp| futures::stream::iter(resp.external_locations.into_iter().map(Ok)))
64        .try_flatten();
65        stream.boxed()
66    }
67}
68impl IntoFuture for ListExternalLocationsBuilder {
69    type Output = Result<ListExternalLocationsResponse>;
70    type IntoFuture = BoxFut<'static, Self::Output>;
71    fn into_future(self) -> Self::IntoFuture {
72        let client = self.client;
73        let request = self.request;
74        Box::pin(async move { client.list_external_locations(&request).await })
75    }
76}
77/// Builder for creating a external location
78pub struct CreateExternalLocationBuilder {
79    client: ExternalLocationServiceClient,
80    request: CreateExternalLocationRequest,
81}
82impl CreateExternalLocationBuilder {
83    /// Create a new builder instance.
84    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
85    pub(crate) fn new(
86        client: ExternalLocationServiceClient,
87        name: impl Into<String>,
88        url: impl Into<String>,
89        credential_name: impl Into<String>,
90    ) -> Self {
91        let request = CreateExternalLocationRequest {
92            name: name.into(),
93            url: url.into(),
94            credential_name: credential_name.into(),
95            ..Default::default()
96        };
97        Self { client, request }
98    }
99    /// Indicates whether the external location is read-only.
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    /// User-provided free-form text description.
105    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
106        self.request.comment = comment.into();
107        self
108    }
109    /// Skips validation of the storage credential associated with the external location.
110    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
111        self.request.skip_validation = skip_validation.into();
112        self
113    }
114}
115impl IntoFuture for CreateExternalLocationBuilder {
116    type Output = Result<ExternalLocation>;
117    type IntoFuture = BoxFut<'static, Self::Output>;
118    fn into_future(self) -> Self::IntoFuture {
119        let client = self.client;
120        let request = self.request;
121        Box::pin(async move { client.create_external_location(&request).await })
122    }
123}
124/// Builder for getting a external location
125pub struct GetExternalLocationBuilder {
126    client: ExternalLocationServiceClient,
127    request: GetExternalLocationRequest,
128}
129impl GetExternalLocationBuilder {
130    /// Create a new builder instance.
131    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
132    pub(crate) fn new(client: ExternalLocationServiceClient, name: impl Into<String>) -> Self {
133        let request = GetExternalLocationRequest { name: name.into() };
134        Self { client, request }
135    }
136}
137impl IntoFuture for GetExternalLocationBuilder {
138    type Output = Result<ExternalLocation>;
139    type IntoFuture = BoxFut<'static, Self::Output>;
140    fn into_future(self) -> Self::IntoFuture {
141        let client = self.client;
142        let request = self.request;
143        Box::pin(async move { client.get_external_location(&request).await })
144    }
145}
146/// Builder for updating a external location
147pub struct UpdateExternalLocationBuilder {
148    client: ExternalLocationServiceClient,
149    request: UpdateExternalLocationRequest,
150}
151impl UpdateExternalLocationBuilder {
152    /// Create a new builder instance.
153    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
154    pub(crate) fn new(client: ExternalLocationServiceClient, name: impl Into<String>) -> Self {
155        let request = UpdateExternalLocationRequest {
156            name: name.into(),
157            ..Default::default()
158        };
159        Self { client, request }
160    }
161    /// Path URL of the external location.
162    pub fn with_url(mut self, url: impl Into<Option<String>>) -> Self {
163        self.request.url = url.into();
164        self
165    }
166    /// Name of the storage credential used with this location.
167    pub fn with_credential_name(mut self, credential_name: impl Into<Option<String>>) -> Self {
168        self.request.credential_name = credential_name.into();
169        self
170    }
171    /// Indicates whether the external location is read-only.
172    pub fn with_read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
173        self.request.read_only = read_only.into();
174        self
175    }
176    /// owner of the external location.
177    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
178        self.request.owner = owner.into();
179        self
180    }
181    /// User-provided free-form text description.
182    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
183        self.request.comment = comment.into();
184        self
185    }
186    /// new name of the external location.
187    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
188        self.request.new_name = new_name.into();
189        self
190    }
191    /// force update of the external location.
192    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
193        self.request.force = force.into();
194        self
195    }
196    /// Skips validation of the storage credential associated with the external location.
197    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
198        self.request.skip_validation = skip_validation.into();
199        self
200    }
201}
202impl IntoFuture for UpdateExternalLocationBuilder {
203    type Output = Result<ExternalLocation>;
204    type IntoFuture = BoxFut<'static, Self::Output>;
205    fn into_future(self) -> Self::IntoFuture {
206        let client = self.client;
207        let request = self.request;
208        Box::pin(async move { client.update_external_location(&request).await })
209    }
210}
211/// Builder for deleting a external location
212pub struct DeleteExternalLocationBuilder {
213    client: ExternalLocationServiceClient,
214    request: DeleteExternalLocationRequest,
215}
216impl DeleteExternalLocationBuilder {
217    /// Create a new builder instance.
218    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
219    pub(crate) fn new(client: ExternalLocationServiceClient, name: impl Into<String>) -> Self {
220        let request = DeleteExternalLocationRequest {
221            name: name.into(),
222            ..Default::default()
223        };
224        Self { client, request }
225    }
226    /// Force deletion even if the external location is not empty.
227    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
228        self.request.force = force.into();
229        self
230    }
231}
232impl IntoFuture for DeleteExternalLocationBuilder {
233    type Output = Result<()>;
234    type IntoFuture = BoxFut<'static, Self::Output>;
235    fn into_future(self) -> Self::IntoFuture {
236        let client = self.client;
237        let request = self.request;
238        Box::pin(async move { client.delete_external_location(&request).await })
239    }
240}