unitycatalog_client/codegen/catalogs/
client.rs1#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::catalogs::v1::*;
6use url::Url;
7#[derive(Clone)]
9pub struct CatalogServiceClient {
10 pub(crate) client: CloudClient,
11 pub(crate) base_url: Url,
12}
13impl CatalogServiceClient {
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_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 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 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 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 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}