Skip to main content

unitycatalog_client/codegen/catalogs/
client.rs

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