vault_client_rs/api/sys/
lease.rs1use reqwest::Method;
2
3use crate::client::encode_path;
4use crate::types::error::VaultError;
5use crate::types::sys::{LeaseInfo, LeaseRenewal};
6
7use super::SysHandler;
8
9impl SysHandler<'_> {
10 pub async fn read_lease(&self, lease_id: &str) -> Result<LeaseInfo, VaultError> {
11 let body = serde_json::json!({ "lease_id": lease_id });
12 self.client
13 .exec_with_data(Method::POST, "sys/leases/lookup", Some(&body))
14 .await
15 }
16
17 pub async fn renew_lease(
18 &self,
19 lease_id: &str,
20 increment: Option<&str>,
21 ) -> Result<LeaseRenewal, VaultError> {
22 let mut body = serde_json::json!({ "lease_id": lease_id });
23 if let Some(inc) = increment {
24 body["increment"] = serde_json::Value::String(inc.to_string());
25 }
26 self.client
27 .exec_direct(Method::PUT, "sys/leases/renew", Some(&body))
28 .await
29 }
30
31 pub async fn revoke_lease(&self, lease_id: &str) -> Result<(), VaultError> {
32 let body = serde_json::json!({ "lease_id": lease_id });
33 self.client
34 .exec_empty(Method::PUT, "sys/leases/revoke", Some(&body))
35 .await
36 }
37
38 pub async fn revoke_prefix(&self, prefix: &str) -> Result<(), VaultError> {
39 self.client
40 .exec_empty(
41 Method::PUT,
42 &format!("sys/leases/revoke-prefix/{}", encode_path(prefix)),
43 None,
44 )
45 .await
46 }
47}