Skip to main content

vault_client_rs/api/sys/
mounts.rs

1use std::collections::HashMap;
2
3use reqwest::Method;
4
5use crate::client::{encode_path, to_body};
6use crate::types::error::VaultError;
7use crate::types::sys::{
8    AuthMountInfo, AuthMountParams, MountConfig, MountInfo, MountParams, MountTuneParams,
9};
10
11use super::SysHandler;
12
13impl SysHandler<'_> {
14    pub async fn list_mounts(&self) -> Result<HashMap<String, MountInfo>, VaultError> {
15        self.client
16            .exec_with_data(Method::GET, "sys/mounts", None)
17            .await
18    }
19
20    pub async fn mount(&self, path: &str, params: &MountParams) -> Result<(), VaultError> {
21        let body = to_body(params)?;
22        self.client
23            .exec_empty(
24                Method::POST,
25                &format!("sys/mounts/{}", encode_path(path)),
26                Some(&body),
27            )
28            .await
29    }
30
31    pub async fn unmount(&self, path: &str) -> Result<(), VaultError> {
32        self.client
33            .exec_empty(
34                Method::DELETE,
35                &format!("sys/mounts/{}", encode_path(path)),
36                None,
37            )
38            .await
39    }
40
41    pub async fn tune_mount(&self, path: &str, params: &MountTuneParams) -> Result<(), VaultError> {
42        let body = to_body(params)?;
43        self.client
44            .exec_empty(
45                Method::POST,
46                &format!("sys/mounts/{}/tune", encode_path(path)),
47                Some(&body),
48            )
49            .await
50    }
51
52    pub async fn read_mount_tune(&self, path: &str) -> Result<MountConfig, VaultError> {
53        self.client
54            .exec_with_data(
55                Method::GET,
56                &format!("sys/mounts/{}/tune", encode_path(path)),
57                None,
58            )
59            .await
60    }
61
62    // --- Auth mounts ---
63
64    pub async fn list_auth_mounts(&self) -> Result<HashMap<String, AuthMountInfo>, VaultError> {
65        self.client
66            .exec_with_data(Method::GET, "sys/auth", None)
67            .await
68    }
69
70    pub async fn enable_auth(
71        &self,
72        path: &str,
73        params: &AuthMountParams,
74    ) -> Result<(), VaultError> {
75        let body = to_body(params)?;
76        self.client
77            .exec_empty(
78                Method::POST,
79                &format!("sys/auth/{}", encode_path(path)),
80                Some(&body),
81            )
82            .await
83    }
84
85    pub async fn disable_auth(&self, path: &str) -> Result<(), VaultError> {
86        self.client
87            .exec_empty(
88                Method::DELETE,
89                &format!("sys/auth/{}", encode_path(path)),
90                None,
91            )
92            .await
93    }
94
95    pub async fn read_auth_tune(&self, path: &str) -> Result<MountConfig, VaultError> {
96        self.client
97            .exec_with_data(
98                Method::GET,
99                &format!("sys/auth/{}/tune", encode_path(path)),
100                None,
101            )
102            .await
103    }
104}