unitycatalog_client/codegen/external_locations/
client.rs1#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::external_locations::v1::*;
6use url::Url;
7#[derive(Clone)]
9pub struct ExternalLocationServiceClient {
10 pub(crate) client: CloudClient,
11 pub(crate) base_url: Url,
12}
13impl ExternalLocationServiceClient {
14 pub fn new(client: CloudClient, mut base_url: Url) -> Self {
16 if !base_url.path().ends_with('/') {
17 base_url.set_path(&format!("{}/", base_url.path()));
18 }
19 Self { client, base_url }
20 }
21 pub async fn list_external_locations(
23 &self,
24 request: &ListExternalLocationsRequest,
25 ) -> Result<ListExternalLocationsResponse> {
26 let mut url = self.base_url.join("external-locations")?;
27 if let Some(ref value) = request.max_results {
28 url.query_pairs_mut()
29 .append_pair("max_results", &value.to_string());
30 }
31 if let Some(ref value) = request.page_token {
32 url.query_pairs_mut()
33 .append_pair("page_token", &value.to_string());
34 }
35 if let Some(ref value) = request.include_browse {
36 url.query_pairs_mut()
37 .append_pair("include_browse", &value.to_string());
38 }
39 let response = self.client.get(url).send().await?;
40 if !response.status().is_success() {
41 return Err(crate::error::parse_error_response(response).await);
42 }
43 let result = response.bytes().await?;
44 Ok(serde_json::from_slice(&result)?)
45 }
46 pub async fn create_external_location(
48 &self,
49 request: &CreateExternalLocationRequest,
50 ) -> Result<ExternalLocation> {
51 let url = self.base_url.join("external-locations")?;
52 let response = self.client.post(url).json(request).send().await?;
53 if !response.status().is_success() {
54 return Err(crate::error::parse_error_response(response).await);
55 }
56 let result = response.bytes().await?;
57 Ok(serde_json::from_slice(&result)?)
58 }
59 pub async fn get_external_location(
61 &self,
62 request: &GetExternalLocationRequest,
63 ) -> Result<ExternalLocation> {
64 let formatted_path = format!("external-locations/{}", request.name);
65 let url = self.base_url.join(&formatted_path)?;
66 let response = self.client.get(url).send().await?;
67 if !response.status().is_success() {
68 return Err(crate::error::parse_error_response(response).await);
69 }
70 let result = response.bytes().await?;
71 Ok(serde_json::from_slice(&result)?)
72 }
73 pub async fn update_external_location(
75 &self,
76 request: &UpdateExternalLocationRequest,
77 ) -> Result<ExternalLocation> {
78 let formatted_path = format!("external-locations/{}", request.name);
79 let url = self.base_url.join(&formatted_path)?;
80 let response = self.client.patch(url).json(request).send().await?;
81 if !response.status().is_success() {
82 return Err(crate::error::parse_error_response(response).await);
83 }
84 let result = response.bytes().await?;
85 Ok(serde_json::from_slice(&result)?)
86 }
87 pub async fn delete_external_location(
89 &self,
90 request: &DeleteExternalLocationRequest,
91 ) -> Result<()> {
92 let formatted_path = format!("external-locations/{}", request.name);
93 let mut url = self.base_url.join(&formatted_path)?;
94 if let Some(ref value) = request.force {
95 url.query_pairs_mut()
96 .append_pair("force", &value.to_string());
97 }
98 let response = self.client.delete(url).send().await?;
99 if !response.status().is_success() {
100 return Err(crate::error::parse_error_response(response).await);
101 }
102 Ok(())
103 }
104}