vaultrs/api/kv1/requests.rs
1use super::responses::{GetSecretResponse, ListSecretResponse};
2
3use rustify_derive::Endpoint;
4use std::fmt::Debug;
5
6/// ## Read Secret
7/// This endpoint retrieves the secret at the specified location.
8///
9/// * Path: {self.mount}/{self.path}
10/// * Method: GET
11/// * Response: GetSecretResponse
12/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v1#read-secret>
13#[derive(Builder, Debug, Endpoint)]
14#[endpoint(
15 path = "{self.mount}/{self.path}",
16 response = "GetSecretResponse",
17 builder = "true"
18)]
19#[builder(setter(into))]
20pub struct GetSecretRequest {
21 #[endpoint(skip)]
22 pub mount: String,
23 #[endpoint(skip)]
24 pub path: String,
25}
26
27/// ## Set Secret
28/// This endpoint set or update a secret at the specified location.
29///
30/// * Path: {self.mount}/{self.path}
31/// * Method: POST
32/// * Response: N/A
33/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v1#create-update-secret>
34#[derive(Builder, Debug, Endpoint)]
35#[endpoint(path = "{self.mount}/{self.path}", method = "POST", builder = "true")]
36#[builder(setter(into))]
37pub struct SetSecretRequest {
38 #[endpoint(skip)]
39 pub mount: String,
40 #[endpoint(skip)]
41 pub path: String,
42
43 // key/value pairs to pass Vault
44 // Must be as raw, otherwise payload would be sent as
45 // { data: { key: value, key2: value2 } } rather than plain { key: value, key2: value2 }
46 // Result in a secret with key "data" and erroneous valué
47 #[endpoint(raw)]
48 pub data: Vec<u8>,
49}
50
51/// ## List secret keys
52/// This endpoint list secrets at given location
53///
54/// * Path: {self.mount}/{self.path}
55/// * Method: LIST
56/// * Response: ListSecretResponse
57/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v1#list-secrets>
58#[derive(Builder, Debug, Endpoint)]
59#[endpoint(
60 path = "{self.mount}/{self.path}",
61 method = "LIST",
62 builder = "true",
63 response = "ListSecretResponse"
64)]
65#[builder(setter(into))]
66pub struct ListSecretRequest {
67 #[endpoint(skip)]
68 pub mount: String,
69 #[endpoint(skip)]
70 pub path: String,
71}
72
73/// ## Delete secret
74/// This endpoint delete a secret at given location
75///
76/// * Path: {self.mount}/{self.path}
77/// * Method: DELETE
78/// * Response: N/A
79/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v1#delete-secret>
80#[derive(Builder, Debug, Endpoint)]
81#[endpoint(path = "{self.mount}/{self.path}", method = "DELETE", builder = "true")]
82#[builder(setter(into))]
83pub struct DeleteSecretRequest {
84 #[endpoint(skip)]
85 pub mount: String,
86 #[endpoint(skip)]
87 pub path: String,
88}