Skip to main content

unitycatalog_client/codegen/shares/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::shares::v1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct ShareServiceClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl ShareServiceClient {
14    /// Create a new client instance
15    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    /// List shares.
22    pub async fn list_shares(&self, request: &ListSharesRequest) -> Result<ListSharesResponse> {
23        let mut url = self.base_url.join("shares")?;
24        if let Some(ref value) = request.max_results {
25            url.query_pairs_mut()
26                .append_pair("max_results", &value.to_string());
27        }
28        if let Some(ref value) = request.page_token {
29            url.query_pairs_mut()
30                .append_pair("page_token", &value.to_string());
31        }
32        let response = self.client.get(url).send().await?;
33        if !response.status().is_success() {
34            return Err(crate::error::parse_error_response(response).await);
35        }
36        let result = response.bytes().await?;
37        Ok(serde_json::from_slice(&result)?)
38    }
39    /// Create a new share.
40    pub async fn create_share(&self, request: &CreateShareRequest) -> Result<Share> {
41        let url = self.base_url.join("shares")?;
42        let response = self.client.post(url).json(request).send().await?;
43        if !response.status().is_success() {
44            return Err(crate::error::parse_error_response(response).await);
45        }
46        let result = response.bytes().await?;
47        Ok(serde_json::from_slice(&result)?)
48    }
49    /// Get a share by name.
50    pub async fn get_share(&self, request: &GetShareRequest) -> Result<Share> {
51        let formatted_path = format!("shares/{}", request.name);
52        let mut url = self.base_url.join(&formatted_path)?;
53        if let Some(ref value) = request.include_shared_data {
54            url.query_pairs_mut()
55                .append_pair("include_shared_data", &value.to_string());
56        }
57        let response = self.client.get(url).send().await?;
58        if !response.status().is_success() {
59            return Err(crate::error::parse_error_response(response).await);
60        }
61        let result = response.bytes().await?;
62        Ok(serde_json::from_slice(&result)?)
63    }
64    /// Update a share.
65    pub async fn update_share(&self, request: &UpdateShareRequest) -> Result<Share> {
66        let formatted_path = format!("shares/{}", request.name);
67        let url = self.base_url.join(&formatted_path)?;
68        let response = self.client.patch(url).json(request).send().await?;
69        if !response.status().is_success() {
70            return Err(crate::error::parse_error_response(response).await);
71        }
72        let result = response.bytes().await?;
73        Ok(serde_json::from_slice(&result)?)
74    }
75    /// Deletes a share.
76    pub async fn delete_share(&self, request: &DeleteShareRequest) -> Result<()> {
77        let formatted_path = format!("shares/{}", request.name);
78        let url = self.base_url.join(&formatted_path)?;
79        let response = self.client.delete(url).send().await?;
80        if !response.status().is_success() {
81            return Err(crate::error::parse_error_response(response).await);
82        }
83        Ok(())
84    }
85    /// Gets the permissions for a data share from the metastore.
86    pub async fn get_permissions(
87        &self,
88        request: &GetPermissionsRequest,
89    ) -> Result<GetPermissionsResponse> {
90        let formatted_path = format!("shares/{}/permissions", request.name);
91        let mut url = self.base_url.join(&formatted_path)?;
92        if let Some(ref value) = request.max_results {
93            url.query_pairs_mut()
94                .append_pair("max_results", &value.to_string());
95        }
96        if let Some(ref value) = request.page_token {
97            url.query_pairs_mut()
98                .append_pair("page_token", &value.to_string());
99        }
100        let response = self.client.get(url).send().await?;
101        if !response.status().is_success() {
102            return Err(crate::error::parse_error_response(response).await);
103        }
104        let result = response.bytes().await?;
105        Ok(serde_json::from_slice(&result)?)
106    }
107    /// Updates the permissions for a data share in the metastore.
108    pub async fn update_permissions(
109        &self,
110        request: &UpdatePermissionsRequest,
111    ) -> Result<UpdatePermissionsResponse> {
112        let formatted_path = format!("shares/{}/permissions", request.name);
113        let url = self.base_url.join(&formatted_path)?;
114        let response = self.client.patch(url).json(request).send().await?;
115        if !response.status().is_success() {
116            return Err(crate::error::parse_error_response(response).await);
117        }
118        let result = response.bytes().await?;
119        Ok(serde_json::from_slice(&result)?)
120    }
121}