Skip to main content

unitycatalog_client/codegen/catalogs/
client.rs

1// @generated — do not edit by hand.
2#![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::catalogs::v1::*;
9use url::Url;
10/// HTTP client for service operations
11#[derive(Clone)]
12pub struct CatalogServiceClient {
13    pub(crate) client: Transport,
14    pub(crate) base_url: Url,
15}
16impl CatalogServiceClient {
17    /// Create a new client instance
18    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    /// List catalogs
25    ///
26    /// Gets an array of catalogs in the metastore. If the caller is the metastore admin,
27    /// all catalogs will be retrieved. Otherwise, only catalogs owned by the caller
28    /// (or for which the caller has the USE_CATALOG privilege) will be retrieved.
29    /// There is no guarantee of a specific ordering of the elements in the array.
30    pub async fn list_catalogs(
31        &self,
32        request: &ListCatalogsRequest,
33    ) -> Result<ListCatalogsResponse> {
34        let mut url = self.base_url.join("catalogs")?;
35        if let Some(ref value) = request.max_results {
36            url.query_pairs_mut()
37                .append_pair("max_results", &value.to_string());
38        }
39        if let Some(ref value) = request.page_token {
40            url.query_pairs_mut()
41                .append_pair("page_token", &value.to_string());
42        }
43        let response = self.client.get(url).send().await?;
44        if !response.status().is_success() {
45            return Err(crate::error::parse_error_response(response).await);
46        }
47        let result = response.bytes().await?;
48        Ok(serde_json::from_slice(&result)?)
49    }
50    /// Create a new catalog
51    ///
52    /// Creates a new catalog instance in the parent metastore if the caller
53    /// is a metastore admin or has the CREATE_CATALOG privilege.
54    pub async fn create_catalog(&self, request: &CreateCatalogRequest) -> Result<Catalog> {
55        let url = self.base_url.join("catalogs")?;
56        let response = self.client.post(url).json(request).send().await?;
57        if !response.status().is_success() {
58            return Err(crate::error::parse_error_response(response).await);
59        }
60        let result = response.bytes().await?;
61        Ok(serde_json::from_slice(&result)?)
62    }
63    /// Get a catalog
64    ///
65    /// Gets the specified catalog in a metastore. The caller must be a metastore admin,
66    /// the owner of the catalog, or a user that has the USE_CATALOG privilege set for their account.
67    pub async fn get_catalog(&self, request: &GetCatalogRequest) -> Result<Catalog> {
68        let formatted_path = format!("catalogs/{}", request.name);
69        let mut url = self.base_url.join(&formatted_path)?;
70        if let Some(ref value) = request.include_browse {
71            url.query_pairs_mut()
72                .append_pair("include_browse", &value.to_string());
73        }
74        let response = self.client.get(url).send().await?;
75        if !response.status().is_success() {
76            return Err(crate::error::parse_error_response(response).await);
77        }
78        let result = response.bytes().await?;
79        Ok(serde_json::from_slice(&result)?)
80    }
81    /// Update a catalog
82    ///
83    /// Updates the catalog that matches the supplied name. The caller must be either
84    /// the owner of the catalog, or a metastore admin (when changing the owner field of the catalog).
85    pub async fn update_catalog(&self, request: &UpdateCatalogRequest) -> Result<Catalog> {
86        let formatted_path = format!("catalogs/{}", request.name);
87        let url = self.base_url.join(&formatted_path)?;
88        let response = self.client.patch(url).json(request).send().await?;
89        if !response.status().is_success() {
90            return Err(crate::error::parse_error_response(response).await);
91        }
92        let result = response.bytes().await?;
93        Ok(serde_json::from_slice(&result)?)
94    }
95    /// Delete a catalog
96    ///
97    /// Deletes the catalog that matches the supplied name. The caller must
98    /// be a metastore admin or the owner of the catalog.
99    pub async fn delete_catalog(&self, request: &DeleteCatalogRequest) -> Result<()> {
100        let formatted_path = format!("catalogs/{}", request.name);
101        let mut url = self.base_url.join(&formatted_path)?;
102        if let Some(ref value) = request.force {
103            url.query_pairs_mut()
104                .append_pair("force", &value.to_string());
105        }
106        let response = self.client.delete(url).send().await?;
107        if !response.status().is_success() {
108            return Err(crate::error::parse_error_response(response).await);
109        }
110        Ok(())
111    }
112}