Skip to main content

vault_client_rs/api/sys/
policy.rs

1use reqwest::Method;
2
3use crate::client::encode_path;
4use crate::types::error::VaultError;
5use crate::types::sys::PolicyInfo;
6
7use super::SysHandler;
8
9impl SysHandler<'_> {
10    pub async fn list_policies(&self) -> Result<Vec<String>, VaultError> {
11        self.client.exec_list("sys/policies/acl").await
12    }
13
14    pub async fn read_policy(&self, name: &str) -> Result<PolicyInfo, VaultError> {
15        self.client
16            .exec_with_data(
17                Method::GET,
18                &format!("sys/policies/acl/{}", encode_path(name)),
19                None,
20            )
21            .await
22    }
23
24    pub async fn write_policy(&self, name: &str, rules: &str) -> Result<(), VaultError> {
25        let body = serde_json::json!({ "policy": rules });
26        self.client
27            .exec_empty(
28                Method::PUT,
29                &format!("sys/policies/acl/{}", encode_path(name)),
30                Some(&body),
31            )
32            .await
33    }
34
35    pub async fn delete_policy(&self, name: &str) -> Result<(), VaultError> {
36        self.client
37            .exec_empty(
38                Method::DELETE,
39                &format!("sys/policies/acl/{}", encode_path(name)),
40                None,
41            )
42            .await
43    }
44}