vaultrs/api/kv2/
requests.rs

1use super::responses::{
2    ListSecretsResponse, ReadConfigurationResponse, ReadSecretMetadataResponse, ReadSecretResponse,
3    SecretVersionMetadata,
4};
5use rustify_derive::Endpoint;
6use serde_json::Value;
7use std::collections::HashMap;
8use std::fmt::Debug;
9
10/// ## Configure the KV Engine
11/// This path configures backend level settings that are applied to every key in
12/// the key-value store.
13///
14/// * Path: {self.mount}/config
15/// * Method: POST
16/// * Response: N/A
17/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#configure-the-kv-engine>
18#[derive(Builder, Debug, Default, Endpoint)]
19#[endpoint(path = "{self.mount}/config", method = "POST", builder = "true")]
20#[builder(setter(into, strip_option), default)]
21pub struct SetConfigurationRequest {
22    #[endpoint(skip)]
23    pub mount: String,
24    pub delete_version_after: Option<String>,
25    pub cas_required: Option<bool>,
26    pub max_versions: Option<u64>,
27}
28
29/// ## Read KV Engine configuration
30/// This path retrieves the current configuration for the secrets backend at the
31/// given path.
32///
33/// * Path: {self.mount}/config
34/// * Method: GET
35/// * Response: ReadConfigurationResponse
36/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-kv-engine-configuration>
37#[derive(Builder, Debug, Default, Endpoint)]
38#[endpoint(
39    path = "{self.mount}/config",
40    response = "ReadConfigurationResponse",
41    builder = "true"
42)]
43#[builder(setter(into, strip_option), default)]
44pub struct ReadConfigurationRequest {
45    #[endpoint(skip)]
46    pub mount: String,
47}
48
49/// ## Read Secret Version
50/// This endpoint retrieves the secret at the specified location.
51///
52/// * Path: {self.mount}/data/{self.path}
53/// * Method: GET
54/// * Response: N/A
55/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-secret-version>
56#[derive(Builder, Debug, Endpoint)]
57#[endpoint(
58    path = "{self.mount}/data/{self.path}",
59    response = "ReadSecretResponse",
60    builder = "true"
61)]
62#[builder(setter(into))]
63pub struct ReadSecretRequest {
64    #[endpoint(skip)]
65    pub mount: String,
66    #[endpoint(skip)]
67    pub path: String,
68    #[builder(default = "None")]
69    #[endpoint(query)]
70    pub version: Option<u64>,
71}
72
73/// ## Create/Update Secret
74/// This endpoint creates a new version of a secret at the specified location.
75///
76/// * Path: {self.mount}/data/{self.path}
77/// * Method: POST
78/// * Response: N/A
79/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#create-update-secret>
80#[derive(Builder, Debug, Endpoint)]
81#[endpoint(
82    path = "{self.mount}/data/{self.path}",
83    response = "SecretVersionMetadata",
84    method = "POST",
85    builder = "true"
86)]
87#[builder(setter(into))]
88pub struct SetSecretRequest {
89    #[endpoint(skip)]
90    pub mount: String,
91    #[endpoint(skip)]
92    pub path: String,
93    pub data: Value,
94    #[builder(setter(strip_option), default)]
95    pub options: Option<SetSecretRequestOptions>,
96}
97
98#[derive(Builder, Clone, Debug, serde::Serialize)]
99#[builder(setter(into))]
100pub struct SetSecretRequestOptions {
101    pub cas: u32,
102}
103
104/// ## Delete Latest Version of Secret
105/// This endpoint issues a soft delete of the secret's latest version at the
106/// specified location.
107///
108/// * Path: {self.mount}/data/{self.path}
109/// * Method: DELETE
110/// * Response: N/A
111/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-latest-version-of-secret>
112#[derive(Builder, Debug, Endpoint)]
113#[endpoint(
114    path = "{self.mount}/data/{self.path}",
115    method = "DELETE",
116    builder = "true"
117)]
118#[builder(setter(into))]
119pub struct DeleteLatestSecretVersionRequest {
120    #[endpoint(skip)]
121    pub mount: String,
122    #[endpoint(skip)]
123    pub path: String,
124}
125
126/// ## Delete Secret Versions
127/// This endpoint issues a soft delete of the specified versions of the secret.
128///
129/// * Path: {self.mount}/delete/{self.path}
130/// * Method: POST
131/// * Response: N/A
132/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-secret-versions>
133#[derive(Builder, Debug, Endpoint)]
134#[endpoint(
135    path = "{self.mount}/delete/{self.path}",
136    method = "POST",
137    builder = "true"
138)]
139#[builder(setter(into))]
140pub struct DeleteSecretVersionsRequest {
141    #[endpoint(skip)]
142    pub mount: String,
143    #[endpoint(skip)]
144    pub path: String,
145    pub versions: Vec<u64>,
146}
147
148/// ## Undelete Secret Versions
149/// Undeletes the data for the provided version and path in the key-value store.
150///
151/// * Path: {self.mount}/undelete/{self.path}
152/// * Method: POST
153/// * Response: N/A
154/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#undelete-secret-versions>
155#[derive(Builder, Debug, Endpoint)]
156#[endpoint(
157    path = "{self.mount}/undelete/{self.path}",
158    method = "POST",
159    builder = "true"
160)]
161#[builder(setter(into))]
162pub struct UndeleteSecretVersionsRequest {
163    #[endpoint(skip)]
164    pub mount: String,
165    #[endpoint(skip)]
166    pub path: String,
167    pub versions: Vec<u64>,
168}
169
170/// ## Destroy Secret Versions
171/// Permanently removes the specified version data for the provided key and
172/// version numbers from the key-value store.
173///
174/// * Path: {self.mount}/destroy/{self.path}
175/// * Method: POST
176/// * Response: N/A
177/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#destroy-secret-versions>
178#[derive(Builder, Debug, Endpoint)]
179#[endpoint(
180    path = "{self.mount}/destroy/{self.path}",
181    method = "POST",
182    builder = "true"
183)]
184#[builder(setter(into))]
185pub struct DestroySecretVersionsRequest {
186    #[endpoint(skip)]
187    pub mount: String,
188    #[endpoint(skip)]
189    pub path: String,
190    pub versions: Vec<u64>,
191}
192
193/// ## List Secrets
194/// This endpoint returns a list of key names at the specified location.
195///
196/// * Path: {self.mount}/metadata/{self.path}
197/// * Method: LIST
198/// * Response: N/A
199/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#list-secrets>
200#[derive(Builder, Debug, Endpoint)]
201#[endpoint(
202    path = "{self.mount}/metadata/{self.path}",
203    response = "ListSecretsResponse",
204    method = "LIST",
205    builder = "true"
206)]
207#[builder(setter(into))]
208pub struct ListSecretsRequest {
209    #[endpoint(skip)]
210    pub mount: String,
211    #[endpoint(skip)]
212    pub path: String,
213}
214
215/// ## Read Secret Metadata
216/// This endpoint retrieves the metadata and versions for the secret at the
217/// specified path.
218///
219/// * Path: {self.mount}/metadata/{self.path}
220/// * Method: GET
221/// * Response: N/A
222/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-secret-metadata>
223#[derive(Builder, Debug, Endpoint)]
224#[endpoint(
225    path = "{self.mount}/metadata/{self.path}",
226    response = "ReadSecretMetadataResponse",
227    builder = "true"
228)]
229#[builder(setter(into))]
230pub struct ReadSecretMetadataRequest {
231    #[endpoint(skip)]
232    pub mount: String,
233    #[endpoint(skip)]
234    pub path: String,
235}
236
237/// ## Create/Update Metadata
238/// This endpoint creates or updates the metadata of a secret at the specified
239/// location.
240///
241/// * Path: {self.mount}/metadata/{self.path}
242/// * Method: POST
243/// * Response: N/A
244/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#create-update-metadata>
245#[derive(Builder, Debug, Default, Endpoint)]
246#[endpoint(
247    path = "{self.mount}/metadata/{self.path}",
248    method = "POST",
249    builder = "true"
250)]
251#[builder(setter(into, strip_option), default)]
252pub struct SetSecretMetadataRequest {
253    #[endpoint(skip)]
254    pub mount: String,
255    #[endpoint(skip)]
256    pub path: String,
257    pub max_versions: Option<u64>,
258    pub cas_required: Option<bool>,
259    pub delete_version_after: Option<String>,
260    pub custom_metadata: Option<HashMap<String, String>>,
261}
262
263/// ## Delete Metadata and All Versions
264/// This endpoint permanently deletes the key metadata and all version data for
265/// the specified key.
266///
267/// * Path: {self.mount}/metadata/{self.path}
268/// * Method: DELETE
269/// * Response: N/A
270/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-metadata-and-all-versions>
271#[derive(Builder, Debug, Default, Endpoint)]
272#[endpoint(
273    path = "{self.mount}/metadata/{self.path}",
274    method = "DELETE",
275    builder = "true"
276)]
277#[builder(setter(into, strip_option), default)]
278pub struct DeleteSecretMetadataRequest {
279    #[endpoint(skip)]
280    pub mount: String,
281    #[endpoint(skip)]
282    pub path: String,
283}