hc_vault/kv2/
configure.rs1use crate::Auth;
2use crate::Client;
3use crate::Error;
4
5use serde::{Deserialize, Serialize};
6
7#[derive(Serialize, Deserialize, Debug)]
9pub struct Configuration {
10 #[serde(skip_serializing_if = "Option::is_none")]
13 pub cas_required: Option<bool>,
14
15 #[serde(skip_serializing_if = "Option::is_none")]
18 pub delete_version_after: Option<String>,
19
20 #[serde(skip_serializing_if = "Option::is_none")]
23 pub max_versions: Option<u32>,
24}
25
26impl PartialEq for Configuration {
27 fn eq(&self, other: &Self) -> bool {
28 self.cas_required == other.cas_required
29 && self.delete_version_after == other.delete_version_after
30 && self.max_versions == other.max_versions
31 }
32}
33
34#[derive(Deserialize)]
35struct ConfigurationResponse {
36 data: Configuration,
37}
38
39pub async fn configure(
44 client: &Client<impl Auth>,
45 mount: &str,
46 config: &Configuration,
47) -> Result<(), Error> {
48 let path = format!("{}/config", mount);
49
50 match client
51 .vault_request::<Configuration>(reqwest::Method::POST, &path, Some(config))
52 .await
53 {
54 Err(e) => Err(e),
55 Ok(_) => Ok(()),
56 }
57}
58
59pub async fn get_configuration(
64 client: &Client<impl Auth>,
65 mount: &str,
66) -> Result<Configuration, Error> {
67 let path = format!("{}/config", mount);
68
69 let resp = match client
70 .vault_request::<String>(reqwest::Method::GET, &path, None)
71 .await
72 {
73 Err(e) => return Err(e),
74 Ok(r) => r,
75 };
76
77 let resp_body = match resp.json::<ConfigurationResponse>().await {
78 Err(e) => return Err(Error::from(e)),
79 Ok(res) => res,
80 };
81
82 Ok(resp_body.data)
83}