unitycatalog_client/codegen/policies/
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::policies::v1::*;
9use url::Url;
10#[derive(Clone)]
12pub struct PolicyServiceClient {
13 pub(crate) client: Transport,
14 pub(crate) base_url: Url,
15}
16impl PolicyServiceClient {
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_policies(
29 &self,
30 request: &ListPoliciesRequest,
31 ) -> Result<ListPoliciesResponse> {
32 let formatted_path = format!(
33 "policies/{}/{}",
34 request.on_securable_type, request.on_securable_fullname
35 );
36 let mut url = self.base_url.join(&formatted_path)?;
37 if let Some(ref value) = request.include_inherited {
38 url.query_pairs_mut()
39 .append_pair("include_inherited", &value.to_string());
40 }
41 if let Some(ref value) = request.max_results {
42 url.query_pairs_mut()
43 .append_pair("max_results", &value.to_string());
44 }
45 if let Some(ref value) = request.page_token {
46 url.query_pairs_mut()
47 .append_pair("page_token", &value.to_string());
48 }
49 let response = self.client.get(url).send().await?;
50 if !response.status().is_success() {
51 return Err(crate::error::parse_error_response(response).await);
52 }
53 let result = response.bytes().await?;
54 Ok(serde_json::from_slice(&result)?)
55 }
56 pub async fn create_policy(&self, request: &CreatePolicyRequest) -> Result<PolicyInfo> {
60 let formatted_path = format!(
61 "policies/{}/{}",
62 request.on_securable_type, request.on_securable_fullname
63 );
64 let url = self.base_url.join(&formatted_path)?;
65 let response = self.client.post(url).json(request).send().await?;
66 if !response.status().is_success() {
67 return Err(crate::error::parse_error_response(response).await);
68 }
69 let result = response.bytes().await?;
70 Ok(serde_json::from_slice(&result)?)
71 }
72 pub async fn get_policy(&self, request: &GetPolicyRequest) -> Result<PolicyInfo> {
76 let formatted_path = format!(
77 "policies/{}/{}/{}",
78 request.on_securable_type, request.on_securable_fullname, request.name
79 );
80 let url = self.base_url.join(&formatted_path)?;
81 let response = self.client.get(url).send().await?;
82 if !response.status().is_success() {
83 return Err(crate::error::parse_error_response(response).await);
84 }
85 let result = response.bytes().await?;
86 Ok(serde_json::from_slice(&result)?)
87 }
88 pub async fn update_policy(&self, request: &UpdatePolicyRequest) -> Result<PolicyInfo> {
92 let formatted_path = format!(
93 "policies/{}/{}/{}",
94 request.on_securable_type, request.on_securable_fullname, request.name
95 );
96 let url = self.base_url.join(&formatted_path)?;
97 let response = self.client.patch(url).json(request).send().await?;
98 if !response.status().is_success() {
99 return Err(crate::error::parse_error_response(response).await);
100 }
101 let result = response.bytes().await?;
102 Ok(serde_json::from_slice(&result)?)
103 }
104 pub async fn delete_policy(&self, request: &DeletePolicyRequest) -> Result<()> {
108 let formatted_path = format!(
109 "policies/{}/{}/{}",
110 request.on_securable_type, request.on_securable_fullname, request.name
111 );
112 let url = self.base_url.join(&formatted_path)?;
113 let response = self.client.delete(url).send().await?;
114 if !response.status().is_success() {
115 return Err(crate::error::parse_error_response(response).await);
116 }
117 Ok(())
118 }
119}