vault_client_rs/api/sys/
seal.rs1use reqwest::Method;
2use secrecy::{ExposeSecret, SecretString};
3
4use crate::client::to_body;
5use crate::types::error::VaultError;
6use crate::types::sys::{InitParams, InitResponse, SealStatus};
7
8use super::SysHandler;
9
10impl SysHandler<'_> {
11 pub async fn seal_status(&self) -> Result<SealStatus, VaultError> {
12 self.client
13 .exec_direct(Method::GET, "sys/seal-status", None)
14 .await
15 }
16
17 pub async fn seal(&self) -> Result<(), VaultError> {
18 self.client.exec_empty(Method::PUT, "sys/seal", None).await
19 }
20
21 pub async fn unseal(&self, key: &SecretString) -> Result<SealStatus, VaultError> {
22 let body = serde_json::json!({ "key": key.expose_secret() });
23 self.client
24 .exec_direct(Method::PUT, "sys/unseal", Some(&body))
25 .await
26 }
27
28 pub async fn init(&self, params: &InitParams) -> Result<InitResponse, VaultError> {
29 let body = to_body(params)?;
30 self.client
31 .exec_direct(Method::PUT, "sys/init", Some(&body))
32 .await
33 }
34
35 pub async fn step_down(&self) -> Result<(), VaultError> {
36 self.client
37 .exec_empty(Method::PUT, "sys/step-down", None)
38 .await
39 }
40}