unitycatalog_client/codegen/shares/
client.rs1#![allow(unused_imports)]
3use crate::Result;
4#[cfg(not(target_arch = "wasm32"))]
5use ::olai_http::CloudClient as Transport;
6#[cfg(target_arch = "wasm32")]
7use ::olai_http_wasm::WasmClient as Transport;
8use unitycatalog_common::models::shares::v1::*;
9use url::Url;
10#[derive(Clone)]
12pub struct ShareServiceClient {
13 pub(crate) client: Transport,
14 pub(crate) base_url: Url,
15}
16impl ShareServiceClient {
17 pub fn new(client: Transport, mut base_url: Url) -> Self {
19 if !base_url.path().ends_with('/') {
20 base_url.set_path(&format!("{}/", base_url.path()));
21 }
22 Self { client, base_url }
23 }
24 pub async fn list_shares(&self, request: &ListSharesRequest) -> Result<ListSharesResponse> {
26 let mut url = self.base_url.join("shares")?;
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 let response = self.client.get(url).send().await?;
36 if !response.status().is_success() {
37 return Err(crate::error::parse_error_response(response).await);
38 }
39 let result = response.bytes().await?;
40 Ok(serde_json::from_slice(&result)?)
41 }
42 pub async fn create_share(&self, request: &CreateShareRequest) -> Result<Share> {
44 let url = self.base_url.join("shares")?;
45 let response = self.client.post(url).json(request).send().await?;
46 if !response.status().is_success() {
47 return Err(crate::error::parse_error_response(response).await);
48 }
49 let result = response.bytes().await?;
50 Ok(serde_json::from_slice(&result)?)
51 }
52 pub async fn get_share(&self, request: &GetShareRequest) -> Result<Share> {
54 let formatted_path = format!("shares/{}", request.name);
55 let mut url = self.base_url.join(&formatted_path)?;
56 if let Some(ref value) = request.include_shared_data {
57 url.query_pairs_mut()
58 .append_pair("include_shared_data", &value.to_string());
59 }
60 let response = self.client.get(url).send().await?;
61 if !response.status().is_success() {
62 return Err(crate::error::parse_error_response(response).await);
63 }
64 let result = response.bytes().await?;
65 Ok(serde_json::from_slice(&result)?)
66 }
67 pub async fn update_share(&self, request: &UpdateShareRequest) -> Result<Share> {
69 let formatted_path = format!("shares/{}", request.name);
70 let url = self.base_url.join(&formatted_path)?;
71 let response = self.client.patch(url).json(request).send().await?;
72 if !response.status().is_success() {
73 return Err(crate::error::parse_error_response(response).await);
74 }
75 let result = response.bytes().await?;
76 Ok(serde_json::from_slice(&result)?)
77 }
78 pub async fn delete_share(&self, request: &DeleteShareRequest) -> Result<()> {
80 let formatted_path = format!("shares/{}", request.name);
81 let url = self.base_url.join(&formatted_path)?;
82 let response = self.client.delete(url).send().await?;
83 if !response.status().is_success() {
84 return Err(crate::error::parse_error_response(response).await);
85 }
86 Ok(())
87 }
88 pub async fn get_permissions(
90 &self,
91 request: &GetPermissionsRequest,
92 ) -> Result<GetPermissionsResponse> {
93 let formatted_path = format!("shares/{}/permissions", request.name);
94 let mut url = self.base_url.join(&formatted_path)?;
95 if let Some(ref value) = request.max_results {
96 url.query_pairs_mut()
97 .append_pair("max_results", &value.to_string());
98 }
99 if let Some(ref value) = request.page_token {
100 url.query_pairs_mut()
101 .append_pair("page_token", &value.to_string());
102 }
103 let response = self.client.get(url).send().await?;
104 if !response.status().is_success() {
105 return Err(crate::error::parse_error_response(response).await);
106 }
107 let result = response.bytes().await?;
108 Ok(serde_json::from_slice(&result)?)
109 }
110 pub async fn update_permissions(
112 &self,
113 request: &UpdatePermissionsRequest,
114 ) -> Result<UpdatePermissionsResponse> {
115 let formatted_path = format!("shares/{}/permissions", request.name);
116 let url = self.base_url.join(&formatted_path)?;
117 let response = self.client.patch(url).json(request).send().await?;
118 if !response.status().is_success() {
119 return Err(crate::error::parse_error_response(response).await);
120 }
121 let result = response.bytes().await?;
122 Ok(serde_json::from_slice(&result)?)
123 }
124}