vaultrs/api/sys/requests.rs
1use super::responses::{
2 AuthResponse, GetConfigurationOfTheSecretEngineResponse, ListPoliciesResponse, MountResponse,
3 RandomResponse, ReadHealthResponse, ReadPolicyResponse, RemountResponse, RemountStatusResponse,
4 StartInitializationResponse, UnsealResponse, WrappingLookupResponse,
5};
6use rustify_derive::Endpoint;
7use serde::Serialize;
8use serde_json::Value;
9use std::collections::HashMap;
10
11/// ## Enable Secrets Engine
12/// This endpoint enables a new secrets engine at the given path.
13///
14/// * Path: sys/mounts/{self.path}
15/// * Method: POST
16/// * Response: N/A
17/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#enable-secrets-engine>
18
19#[derive(Builder, Debug, Default, Endpoint, Serialize)]
20#[endpoint(path = "sys/mounts/{self.path}", method = "POST", builder = "true")]
21#[builder(setter(into, strip_option), default)]
22pub struct EnableEngineRequest {
23 #[endpoint(skip)]
24 pub path: String,
25 #[serde(rename = "type")]
26 pub engine_type: Option<String>,
27 pub description: Option<String>,
28 pub config: Option<EnableEngineDataConfig>,
29 pub options: Option<HashMap<String, String>>,
30}
31
32#[derive(Clone, Builder, Debug, Default, Serialize)]
33#[builder(setter(into, strip_option), default)]
34pub struct EnableEngineDataConfig {
35 pub default_lease_ttl: Option<String>,
36 pub max_lease_ttl: Option<String>,
37 pub force_no_cache: Option<bool>,
38 pub audit_non_hmac_request_keys: Option<Vec<String>>,
39 pub audit_non_hmac_response_keys: Option<Vec<String>>,
40 pub listing_visibility: Option<String>,
41 pub passthrough_request_headers: Option<Vec<String>>,
42 pub allowed_response_headers: Option<Vec<String>>,
43}
44
45/// ## Disable Secrets Engine
46/// This endpoint disables the mount point specified in the URL.
47///
48/// * Path: sys/mounts/{self.path}
49/// * Method: DELETE
50/// * Response: N/A
51/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#disable-secrets-engine>
52
53#[derive(Builder, Debug, Default, Endpoint, Serialize)]
54#[endpoint(path = "sys/mounts/{self.path}", method = "DELETE", builder = "true")]
55#[builder(setter(into, strip_option), default)]
56pub struct DisableEngineRequest {
57 #[endpoint(skip)]
58 pub path: String,
59}
60
61/// ## Get the configuration of a secret engine
62/// This endpoint returns the configuration of a specific secret engine.
63///
64/// * Path: sys/mounts/{self.path}
65/// * Method: GET
66/// * Response: GetConfigurationOfTheSecretEngineResponse
67/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#get-the-configuration-of-a-secret-engine>
68
69#[derive(Builder, Debug, Default, Endpoint, Serialize)]
70#[endpoint(
71 path = "sys/mounts/{self.path}",
72 method = "GET",
73 builder = "true",
74 response = "GetConfigurationOfTheSecretEngineResponse"
75)]
76#[builder(setter(into, strip_option), default)]
77pub struct GetConfigurationOfTheSecretEngineRequest {
78 #[endpoint(skip)]
79 pub path: String,
80}
81
82/// ## List Mounted Secrets Engines
83/// This endpoints lists all the mounted secrets engines.
84///
85/// * Path: sys/mounts
86/// * Method: GET
87/// * Response: [HashMap<String, MountResponse>]
88/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/mounts#list-mounted-secrets-engines>
89
90#[derive(Builder, Debug, Default, Endpoint)]
91#[endpoint(
92 path = "sys/mounts",
93 response = "HashMap<String, MountResponse>",
94 builder = "true"
95)]
96#[builder(setter(into, strip_option), default)]
97pub struct ListMountsRequest {}
98
99/// ## Enable Auth Method
100/// This endpoint enables a new auth method.
101///
102/// * Path: sys/auth/{self.path}
103/// * Method: POST
104/// * Response: N/A
105/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/auth#enable-auth-method>
106
107#[derive(Builder, Debug, Default, Endpoint, Serialize)]
108#[endpoint(path = "sys/auth/{self.path}", method = "POST", builder = "true")]
109#[builder(setter(into, strip_option), default)]
110pub struct EnableAuthRequest {
111 #[endpoint(skip)]
112 pub path: String,
113 #[serde(rename = "type")]
114 pub engine_type: Option<String>,
115 pub description: Option<String>,
116 pub config: Option<EnableAuthDataConfig>,
117}
118
119/// ## Disable Auth Method
120/// This endpoint disables the auth method at the given auth path.
121///
122/// * Path: sys/auth/{self.path}
123/// * Method: DELETE
124/// * Response: N/A
125/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/auth#disable-auth-method>
126
127#[derive(Builder, Debug, Default, Endpoint, Serialize)]
128#[endpoint(path = "sys/auth/{self.path}", method = "DELETE", builder = "true")]
129#[builder(setter(into, strip_option), default)]
130pub struct DisableAuthRequest {
131 #[endpoint(skip)]
132 pub path: String,
133}
134
135#[derive(Clone, Builder, Debug, Default, Serialize)]
136#[builder(setter(into, strip_option), default)]
137pub struct EnableAuthDataConfig {
138 pub default_lease_ttl: Option<String>,
139 pub max_lease_ttl: Option<String>,
140 pub force_no_cache: Option<bool>,
141 pub audit_non_hmac_request_keys: Option<Vec<String>>,
142 pub audit_non_hmac_response_keys: Option<Vec<String>>,
143 pub listing_visibility: Option<String>,
144 pub passthrough_request_headers: Option<Vec<String>>,
145 pub allowed_response_headers: Option<Vec<String>>,
146}
147
148/// ## List Auth Methods
149/// This endpoint lists all enabled auth methods.
150///
151/// * Path: sys/auth
152/// * Method: GET
153/// * Response: [HashMap<String, MountResponse>]
154/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/auth#list-auth-methods>
155
156#[derive(Builder, Debug, Default, Endpoint)]
157#[endpoint(
158 path = "sys/auth",
159 response = "HashMap<String, AuthResponse>",
160 builder = "true"
161)]
162#[builder(setter(into, strip_option), default)]
163pub struct ListAuthsRequest {}
164
165/// ## Move backend
166///
167/// The `/sys/remount` endpoint moves an already-mounted backend to a new mount point.
168/// Remounting works for both secret engines and auth methods.
169///
170/// * Path: sys/remount
171/// * Method: POST
172/// * Response: RemountResponse
173/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/remount#move-backend>
174
175#[derive(Builder, Debug, Default, Endpoint, Serialize)]
176#[endpoint(
177 path = "sys/remount",
178 response = "RemountResponse",
179 method = "POST",
180 builder = "true"
181)]
182#[builder(setter(into, strip_option), default)]
183pub struct RemountRequest {
184 pub from: String,
185 pub to: String,
186}
187
188/// ## Get the configuration of a secret engine
189/// This endpoint returns the configuration of a specific secret engine.
190///
191/// * Path: sys/remount/status/{self.migration_id}
192/// * Method: GET
193/// * Response: RemountStatusResponse
194/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/remount#monitor-migration-status>
195
196#[derive(Builder, Debug, Default, Endpoint, Serialize)]
197#[endpoint(
198 path = "sys/remount/status/{self.migration_id}",
199 method = "GET",
200 builder = "true",
201 response = "RemountStatusResponse"
202)]
203#[builder(setter(into, strip_option), default)]
204pub struct RemountStatusRequest {
205 #[endpoint(skip)]
206 pub migration_id: String,
207}
208
209/// ## Wrapping Unwrap
210/// This endpoint returns the original response inside the given wrapping token.
211///
212/// * Path: /sys/wrapping/unwrap
213/// * Method: POST
214/// * Response: T
215/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/wrapping-unwrap#wrapping-unwrap>
216
217#[derive(Builder, Endpoint)]
218#[endpoint(path = "/sys/wrapping/unwrap", method = "POST", response = "Value")]
219#[builder(setter(into))]
220pub struct UnwrapRequest {
221 pub token: Option<String>,
222}
223
224/// ## Wrapping Lookup
225/// This endpoint returns the wrapping token properties.
226///
227/// * Path: /sys/wrapping/lookup
228/// * Method: POST
229/// * Response: WrappingLookupResponse
230/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/wrapping-unwrap#wrapping-unwrap>
231
232#[derive(Builder, Default, Endpoint)]
233#[endpoint(
234 path = "/sys/wrapping/lookup",
235 method = "POST",
236 response = "WrappingLookupResponse",
237 builder = "true"
238)]
239#[builder(setter(into), default)]
240pub struct WrappingLookupRequest {
241 pub token: String,
242}
243
244/// ## Read Health Information
245/// This endpoint is used to check the health status of Vault.
246///
247/// * Path: /sys/health
248/// * Method: GET
249/// * Response: [ReadHealthResponse]
250/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/health#read-health-information>
251
252#[derive(Builder, Default, Endpoint)]
253#[endpoint(
254 path = "/sys/health",
255 response = "ReadHealthResponse",
256 builder = "true"
257)]
258#[builder(setter(into), default)]
259pub struct ReadHealthRequest {}
260
261/// ## Start Initialization
262///
263/// This endpoint initializes a new Vault. The Vault must not have been previously initialized.
264/// The recovery options, as well as the stored shares option, are only available when using Auto Unseal.
265///
266/// * Path: /sys/init
267/// * Method: POST
268/// * Response: [StartInitializationResponse]
269/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/init#start-initialization>
270#[derive(Builder, Default, Endpoint)]
271#[endpoint(
272 path = "/sys/init",
273 method = "POST",
274 response = "StartInitializationResponse",
275 builder = "true"
276)]
277#[builder(setter(into), default)]
278pub struct StartInitializationRequest {
279 /// Specifies an array of PGP public keys used to encrypt the output unseal keys. Ordering is preserved.
280 /// The keys must be base64-encoded from their original binary representation. The size of this array must be the same as secret_shares.
281 pgp_keys: Option<Vec<String>>,
282 /// Specifies a PGP public key used to encrypt the initial root token. The key must be base64-encoded from its original binary representation.
283 root_token_pgp_key: Option<String>,
284 /// Specifies the number of shares to split the root key into.
285 secret_shares: u64,
286 /// Specifies the number of shares required to reconstruct the root key. This must be less than or equal secret_shares.
287 secret_threshold: u64,
288
289 /// Additionally, the following options are only supported using Auto Unseal:
290 /// Specifies the number of shares that should be encrypted by the HSM and stored for auto-unsealing. Currently must be the same as secret_shares.
291 stored_shares: Option<u64>,
292 /// Specifies the number of shares to split the recovery key into. This is only available when using Auto Unseal.
293 recovery_shares: Option<u64>,
294 /// Specifies the number of shares required to reconstruct the recovery key. This must be less than or equal to recovery_shares.
295 /// This is only available when using Auto Unseal.
296 recovery_threshold: Option<u64>,
297 /// Specifies an array of PGP public keys used to encrypt the output recovery keys. Ordering is preserved.
298 /// The keys must be base64-encoded from their original binary representation. The size of this array must be the same as recovery_shares. This is only available when using Auto Unseal.
299 recovery_pgp_keys: Option<Vec<String>>,
300}
301
302/// ## Seal
303/// This endpoint seals the Vault.
304///
305/// * Path: /sys/seal
306/// * Method: PUT
307/// * Response: N/A
308/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/seal#seal>
309
310#[derive(Builder, Default, Endpoint)]
311#[endpoint(path = "/sys/seal", method = "PUT", builder = "true")]
312#[builder(setter(into), default)]
313pub struct SealRequest {}
314
315/// ## Unseal
316/// This endpoint unseals the Vault.
317///
318/// * Path: /sys/unseal
319/// * Method: PUT
320/// * Response: [UnsealResponse]
321/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/unseal>
322
323#[derive(Builder, Default, Endpoint)]
324#[endpoint(
325 path = "/sys/unseal",
326 method = "PUT",
327 response = "UnsealResponse",
328 builder = "true"
329)]
330#[builder(setter(into), default)]
331pub struct UnsealRequest {
332 pub key: Option<String>,
333 pub reset: Option<bool>,
334 pub migrate: Option<bool>,
335}
336
337/// ## List Policies
338/// This endpoint lists all configured policies.
339///
340/// * Path: /sys/policy
341/// * Method: GET
342/// * Response: [ListPoliciesResponse]
343/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/policy#list-policies>
344
345#[derive(Builder, Default, Endpoint)]
346#[endpoint(
347 path = "/sys/policy",
348 response = "ListPoliciesResponse",
349 builder = "true"
350)]
351#[builder(setter(into), default)]
352pub struct ListPoliciesRequest {}
353
354/// ## Read Policy
355/// This endpoint retrieve the policy body for the named policy.
356///
357/// * Path: /sys/policy/{self.name}
358/// * Method: GET
359/// * Response: [ReadPolicyResponse]
360/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/policy#read-policy>
361
362#[derive(Builder, Default, Endpoint)]
363#[endpoint(
364 path = "/sys/policy/{self.name}",
365 response = "ReadPolicyResponse",
366 builder = "true"
367)]
368#[builder(setter(into), default)]
369pub struct ReadPolicyRequest {
370 pub name: String,
371}
372
373/// ## Create/Update Policy
374/// This endpoint adds a new or updates an existing policy.
375///
376/// * Path: /sys/policy/{self.name}
377/// * Method: PUT
378/// * Response: N/A
379/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/policy#create-update-policy>
380
381#[derive(Builder, Default, Endpoint)]
382#[endpoint(path = "/sys/policy/{self.name}", method = "PUT", builder = "true")]
383#[builder(setter(into), default)]
384pub struct CreatePolicyRequest {
385 pub name: String,
386 pub policy: String,
387}
388
389/// ## Delete Policy
390/// This endpoint deletes the policy with the given name.
391///
392/// * Path: /sys/policy/{self.name}
393/// * Method: DELETE
394/// * Response: N/A
395/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/policy#delete-policy>
396
397#[derive(Builder, Default, Endpoint)]
398#[endpoint(path = "/sys/policy/{self.name}", method = "DELETE", builder = "true")]
399#[builder(setter(into), default)]
400pub struct DeletePolicyRequest {
401 pub name: String,
402}
403
404/// ## Generate random bytes
405/// This endpoint returns high-quality random bytes of the specified length.
406///
407/// * Path: /sys/tools/random
408/// * Method: POST
409/// * Response: [RandomResponse]
410/// * Reference: <https://developer.hashicorp.com/vault/api-docs/system/tools#generate-random-bytes>
411
412#[derive(Builder, Default, Endpoint)]
413#[endpoint(
414 path = "/sys/tools/random",
415 method = "POST",
416 response = "RandomResponse",
417 builder = "true"
418)]
419#[builder(setter(into, strip_option), default)]
420pub struct RandomRequest {
421 pub bytes: Option<u64>,
422 pub format: Option<String>,
423 pub source: Option<String>,
424}