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 {
134            name: name.into(),
135            ..Default::default()
136        };
137        Self { client, request }
138    }
139}
140impl IntoFuture for GetExternalLocationBuilder {
141    type Output = Result<ExternalLocation>;
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_external_location(&request).await })
147    }
148}
149/// Builder for updating a external location
150pub struct UpdateExternalLocationBuilder {
151    client: ExternalLocationServiceClient,
152    request: UpdateExternalLocationRequest,
153}
154impl UpdateExternalLocationBuilder {
155    /// Create a new builder instance.
156    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
157    pub(crate) fn new(client: ExternalLocationServiceClient, name: impl Into<String>) -> Self {
158        let request = UpdateExternalLocationRequest {
159            name: name.into(),
160            ..Default::default()
161        };
162        Self { client, request }
163    }
164    /// Path URL of the external location.
165    pub fn with_url(mut self, url: impl Into<Option<String>>) -> Self {
166        self.request.url = url.into();
167        self
168    }
169    /// Name of the storage credential used with this location.
170    pub fn with_credential_name(mut self, credential_name: impl Into<Option<String>>) -> Self {
171        self.request.credential_name = credential_name.into();
172        self
173    }
174    /// Indicates whether the external location is read-only.
175    pub fn with_read_only(mut self, read_only: impl Into<Option<bool>>) -> Self {
176        self.request.read_only = read_only.into();
177        self
178    }
179    /// owner of the external location.
180    pub fn with_owner(mut self, owner: impl Into<Option<String>>) -> Self {
181        self.request.owner = owner.into();
182        self
183    }
184    /// User-provided free-form text description.
185    pub fn with_comment(mut self, comment: impl Into<Option<String>>) -> Self {
186        self.request.comment = comment.into();
187        self
188    }
189    /// new name of the external location.
190    pub fn with_new_name(mut self, new_name: impl Into<Option<String>>) -> Self {
191        self.request.new_name = new_name.into();
192        self
193    }
194    /// force update of the external location.
195    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
196        self.request.force = force.into();
197        self
198    }
199    /// Skips validation of the storage credential associated with the external location.
200    pub fn with_skip_validation(mut self, skip_validation: impl Into<Option<bool>>) -> Self {
201        self.request.skip_validation = skip_validation.into();
202        self
203    }
204}
205impl IntoFuture for UpdateExternalLocationBuilder {
206    type Output = Result<ExternalLocation>;
207    type IntoFuture = BoxFut<'static, Self::Output>;
208    fn into_future(self) -> Self::IntoFuture {
209        let client = self.client;
210        let request = self.request;
211        Box::pin(async move { client.update_external_location(&request).await })
212    }
213}
214/// Builder for deleting a external location
215pub struct DeleteExternalLocationBuilder {
216    client: ExternalLocationServiceClient,
217    request: DeleteExternalLocationRequest,
218}
219impl DeleteExternalLocationBuilder {
220    /// Create a new builder instance.
221    /// Obtain via the corresponding method on `ExternalLocationServiceClient`.
222    pub(crate) fn new(client: ExternalLocationServiceClient, name: impl Into<String>) -> Self {
223        let request = DeleteExternalLocationRequest {
224            name: name.into(),
225            ..Default::default()
226        };
227        Self { client, request }
228    }
229    /// Force deletion even if the external location is not empty.
230    pub fn with_force(mut self, force: impl Into<Option<bool>>) -> Self {
231        self.request.force = force.into();
232        self
233    }
234}
235impl IntoFuture for DeleteExternalLocationBuilder {
236    type Output = Result<()>;
237    type IntoFuture = BoxFut<'static, Self::Output>;
238    fn into_future(self) -> Self::IntoFuture {
239        let client = self.client;
240        let request = self.request;
241        Box::pin(async move { client.delete_external_location(&request).await })
242    }
243}