Skip to main content

unitycatalog_client/codegen/policies/
client.rs

1// @generated — do not edit by hand.
2#![allow(unused_imports)]
3use crate::Result;
4use olai_http::CloudClient;
5use unitycatalog_common::models::policies::v1::*;
6use url::Url;
7/// HTTP client for service operations
8#[derive(Clone)]
9pub struct PolicyServiceClient {
10    pub(crate) client: CloudClient,
11    pub(crate) base_url: Url,
12}
13impl PolicyServiceClient {
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 policies
22    ///
23    /// Gets an array of policies defined on the specified securable. There is no guarantee
24    /// of a specific ordering of the elements in the array.
25    pub async fn list_policies(
26        &self,
27        request: &ListPoliciesRequest,
28    ) -> Result<ListPoliciesResponse> {
29        let formatted_path = format!(
30            "policies/{}/{}",
31            request.on_securable_type, request.on_securable_fullname
32        );
33        let mut url = self.base_url.join(&formatted_path)?;
34        if let Some(ref value) = request.include_inherited {
35            url.query_pairs_mut()
36                .append_pair("include_inherited", &value.to_string());
37        }
38        if let Some(ref value) = request.max_results {
39            url.query_pairs_mut()
40                .append_pair("max_results", &value.to_string());
41        }
42        if let Some(ref value) = request.page_token {
43            url.query_pairs_mut()
44                .append_pair("page_token", &value.to_string());
45        }
46        let response = self.client.get(url).send().await?;
47        if !response.status().is_success() {
48            return Err(crate::error::parse_error_response(response).await);
49        }
50        let result = response.bytes().await?;
51        Ok(serde_json::from_slice(&result)?)
52    }
53    /// Create a new policy
54    ///
55    /// Creates a new row-filter or column-mask policy on the specified securable.
56    pub async fn create_policy(&self, request: &CreatePolicyRequest) -> Result<PolicyInfo> {
57        let formatted_path = format!(
58            "policies/{}/{}",
59            request.on_securable_type, request.on_securable_fullname
60        );
61        let url = self.base_url.join(&formatted_path)?;
62        let response = self.client.post(url).json(request).send().await?;
63        if !response.status().is_success() {
64            return Err(crate::error::parse_error_response(response).await);
65        }
66        let result = response.bytes().await?;
67        Ok(serde_json::from_slice(&result)?)
68    }
69    /// Get a policy
70    ///
71    /// Gets the policy that matches the supplied name, defined on the specified securable.
72    pub async fn get_policy(&self, request: &GetPolicyRequest) -> Result<PolicyInfo> {
73        let formatted_path = format!(
74            "policies/{}/{}/{}",
75            request.on_securable_type, request.on_securable_fullname, request.name
76        );
77        let url = self.base_url.join(&formatted_path)?;
78        let response = self.client.get(url).send().await?;
79        if !response.status().is_success() {
80            return Err(crate::error::parse_error_response(response).await);
81        }
82        let result = response.bytes().await?;
83        Ok(serde_json::from_slice(&result)?)
84    }
85    /// Update a policy
86    ///
87    /// Updates the policy that matches the supplied name, defined on the specified securable.
88    pub async fn update_policy(&self, request: &UpdatePolicyRequest) -> Result<PolicyInfo> {
89        let formatted_path = format!(
90            "policies/{}/{}/{}",
91            request.on_securable_type, request.on_securable_fullname, request.name
92        );
93        let url = self.base_url.join(&formatted_path)?;
94        let response = self.client.patch(url).json(request).send().await?;
95        if !response.status().is_success() {
96            return Err(crate::error::parse_error_response(response).await);
97        }
98        let result = response.bytes().await?;
99        Ok(serde_json::from_slice(&result)?)
100    }
101    /// Delete a policy
102    ///
103    /// Deletes the policy that matches the supplied name, defined on the specified securable.
104    pub async fn delete_policy(&self, request: &DeletePolicyRequest) -> Result<()> {
105        let formatted_path = format!(
106            "policies/{}/{}/{}",
107            request.on_securable_type, request.on_securable_fullname, request.name
108        );
109        let url = self.base_url.join(&formatted_path)?;
110        let response = self.client.delete(url).send().await?;
111        if !response.status().is_success() {
112            return Err(crate::error::parse_error_response(response).await);
113        }
114        Ok(())
115    }
116}