vaultrs/api/kv2/
requests.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
use super::responses::{
    ListSecretsResponse, ReadConfigurationResponse, ReadSecretMetadataResponse, ReadSecretResponse,
    SecretVersionMetadata,
};
use rustify_derive::Endpoint;
use serde_json::Value;
use std::collections::HashMap;
use std::fmt::Debug;

/// ## Configure the KV Engine
/// This path configures backend level settings that are applied to every key in
/// the key-value store.
///
/// * Path: {self.mount}/config
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#configure-the-kv-engine>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(path = "{self.mount}/config", method = "POST", builder = "true")]
#[builder(setter(into, strip_option), default)]
pub struct SetConfigurationRequest {
    #[endpoint(skip)]
    pub mount: String,
    pub delete_version_after: Option<String>,
    pub cas_required: Option<bool>,
    pub max_versions: Option<u64>,
}

/// ## Read KV Engine configuration
/// This path retrieves the current configuration for the secrets backend at the
/// given path.
///
/// * Path: {self.mount}/config
/// * Method: GET
/// * Response: ReadConfigurationResponse
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-kv-engine-configuration>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
    path = "{self.mount}/config",
    response = "ReadConfigurationResponse",
    builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct ReadConfigurationRequest {
    #[endpoint(skip)]
    pub mount: String,
}

/// ## Read Secret Version
/// This endpoint retrieves the secret at the specified location.
///
/// * Path: {self.mount}/data/{self.path}
/// * Method: GET
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-secret-version>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/data/{self.path}",
    response = "ReadSecretResponse",
    builder = "true"
)]
#[builder(setter(into))]
pub struct ReadSecretRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    #[builder(default = "None")]
    #[endpoint(query)]
    pub version: Option<u64>,
}

/// ## Create/Update Secret
/// This endpoint creates a new version of a secret at the specified location.
///
/// * Path: {self.mount}/data/{self.path}
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#create-update-secret>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/data/{self.path}",
    response = "SecretVersionMetadata",
    method = "POST",
    builder = "true"
)]
#[builder(setter(into))]
pub struct SetSecretRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    pub data: Value,
    #[builder(setter(strip_option), default)]
    pub options: Option<SetSecretRequestOptions>,
}

#[derive(Builder, Clone, Debug, serde::Serialize)]
#[builder(setter(into))]
pub struct SetSecretRequestOptions {
    pub cas: u32,
}

/// ## Delete Latest Version of Secret
/// This endpoint issues a soft delete of the secret's latest version at the
/// specified location.
///
/// * Path: {self.mount}/data/{self.path}
/// * Method: DELETE
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-latest-version-of-secret>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/data/{self.path}",
    method = "DELETE",
    builder = "true"
)]
#[builder(setter(into))]
pub struct DeleteLatestSecretVersionRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
}

/// ## Delete Secret Versions
/// This endpoint issues a soft delete of the specified versions of the secret.
///
/// * Path: {self.mount}/delete/{self.path}
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-secret-versions>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/delete/{self.path}",
    method = "POST",
    builder = "true"
)]
#[builder(setter(into))]
pub struct DeleteSecretVersionsRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    pub versions: Vec<u64>,
}

/// ## Undelete Secret Versions
/// Undeletes the data for the provided version and path in the key-value store.
///
/// * Path: {self.mount}/undelete/{self.path}
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#undelete-secret-versions>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/undelete/{self.path}",
    method = "POST",
    builder = "true"
)]
#[builder(setter(into))]
pub struct UndeleteSecretVersionsRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    pub versions: Vec<u64>,
}

/// ## Destroy Secret Versions
/// Permanently removes the specified version data for the provided key and
/// version numbers from the key-value store.
///
/// * Path: {self.mount}/destroy/{self.path}
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#destroy-secret-versions>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/destroy/{self.path}",
    method = "POST",
    builder = "true"
)]
#[builder(setter(into))]
pub struct DestroySecretVersionsRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    pub versions: Vec<u64>,
}

/// ## List Secrets
/// This endpoint returns a list of key names at the specified location.
///
/// * Path: {self.mount}/metadata/{self.path}
/// * Method: LIST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#list-secrets>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/metadata/{self.path}",
    response = "ListSecretsResponse",
    method = "LIST",
    builder = "true"
)]
#[builder(setter(into))]
pub struct ListSecretsRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
}

/// ## Read Secret Metadata
/// This endpoint retrieves the metadata and versions for the secret at the
/// specified path.
///
/// * Path: {self.mount}/metadata/{self.path}
/// * Method: GET
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#read-secret-metadata>
#[derive(Builder, Debug, Endpoint)]
#[endpoint(
    path = "{self.mount}/metadata/{self.path}",
    response = "ReadSecretMetadataResponse",
    builder = "true"
)]
#[builder(setter(into))]
pub struct ReadSecretMetadataRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
}

/// ## Create/Update Metadata
/// This endpoint creates or updates the metadata of a secret at the specified
/// location.
///
/// * Path: {self.mount}/metadata/{self.path}
/// * Method: POST
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#create-update-metadata>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
    path = "{self.mount}/metadata/{self.path}",
    method = "POST",
    builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct SetSecretMetadataRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
    pub max_versions: Option<u64>,
    pub cas_required: Option<bool>,
    pub delete_version_after: Option<String>,
    pub custom_metadata: Option<HashMap<String, String>>,
}

/// ## Delete Metadata and All Versions
/// This endpoint permanently deletes the key metadata and all version data for
/// the specified key.
///
/// * Path: {self.mount}/metadata/{self.path}
/// * Method: DELETE
/// * Response: N/A
/// * Reference: <https://developer.hashicorp.com/vault/api-docs/secret/kv/kv-v2#delete-metadata-and-all-versions>
#[derive(Builder, Debug, Default, Endpoint)]
#[endpoint(
    path = "{self.mount}/metadata/{self.path}",
    method = "DELETE",
    builder = "true"
)]
#[builder(setter(into, strip_option), default)]
pub struct DeleteSecretMetadataRequest {
    #[endpoint(skip)]
    pub mount: String,
    #[endpoint(skip)]
    pub path: String,
}