vault-client-rs 0.8.0

A Rust client for the HashiCorp Vault HTTP API
Documentation
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
use std::collections::HashMap;
use std::fmt;

use secrecy::{ExposeSecret, SecretString};
use serde::{Deserialize, Serialize};
use zeroize::{Zeroize, ZeroizeOnDrop};

use super::redaction::redact;

// --- Health ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct HealthResponse {
    pub initialized: bool,
    pub sealed: bool,
    pub standby: bool,
    #[serde(default)]
    pub performance_standby: bool,
    pub replication_performance_mode: Option<String>,
    pub replication_dr_mode: Option<String>,
    pub server_time_utc: Option<u64>,
    pub version: String,
    pub cluster_name: Option<String>,
    pub cluster_id: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct LeaderResponse {
    pub ha_enabled: bool,
    pub is_self: bool,
    #[serde(default)]
    pub leader_address: String,
    #[serde(default)]
    pub leader_cluster_address: String,
    #[serde(default)]
    pub performance_standby: bool,
}

// --- Seal ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct SealStatus {
    #[serde(rename = "type")]
    pub seal_type: String,
    pub initialized: bool,
    pub sealed: bool,
    pub t: u32,
    pub n: u32,
    pub progress: u32,
    pub nonce: String,
    pub version: String,
    pub build_date: Option<String>,
    pub migration: Option<bool>,
    pub cluster_name: Option<String>,
    pub cluster_id: Option<String>,
    pub recovery_seal: Option<bool>,
    pub storage_type: Option<String>,
}

#[derive(Debug, Serialize, Clone)]
pub struct InitParams {
    pub secret_shares: u32,
    pub secret_threshold: u32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pgp_keys: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub root_token_pgp_key: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub recovery_shares: Option<u32>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub recovery_threshold: Option<u32>,
}

#[derive(Deserialize, Zeroize, ZeroizeOnDrop)]
#[non_exhaustive]
pub struct InitResponse {
    #[serde(default)]
    pub keys: Vec<SecretString>,
    #[serde(default)]
    pub keys_base64: Vec<SecretString>,
    pub root_token: SecretString,
}

impl Clone for InitResponse {
    fn clone(&self) -> Self {
        Self {
            keys: self.keys.clone(),
            keys_base64: self.keys_base64.clone(),
            root_token: self.root_token.clone(),
        }
    }
}

impl fmt::Debug for InitResponse {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        let keys: Vec<String> = self
            .keys
            .iter()
            .map(|s| redact(s.expose_secret()))
            .collect();
        let keys_b64: Vec<String> = self
            .keys_base64
            .iter()
            .map(|s| redact(s.expose_secret()))
            .collect();
        f.debug_struct("InitResponse")
            .field("keys", &keys)
            .field("keys_base64", &keys_b64)
            .field("root_token", &redact(self.root_token.expose_secret()))
            .finish()
    }
}

// --- Mounts ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct MountInfo {
    #[serde(rename = "type")]
    pub mount_type: String,
    #[serde(default)]
    pub description: String,
    pub accessor: String,
    pub config: MountConfig,
    #[serde(default)]
    pub local: bool,
    #[serde(default)]
    pub seal_wrap: bool,
    #[serde(default)]
    pub external_entropy_access: bool,
    pub options: Option<HashMap<String, String>>,
    pub uuid: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct MountConfig {
    pub default_lease_ttl: u64,
    pub max_lease_ttl: u64,
    #[serde(default)]
    pub force_no_cache: bool,
}

#[derive(Debug, Serialize, Clone)]
pub struct MountParams {
    #[serde(rename = "type")]
    pub mount_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<MountTuneParams>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub options: Option<HashMap<String, String>>,
}

#[derive(Debug, Serialize, Default, Clone)]
pub struct MountTuneParams {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub default_lease_ttl: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub max_lease_ttl: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct AuthMountInfo {
    #[serde(rename = "type")]
    pub mount_type: String,
    #[serde(default)]
    pub description: String,
    pub accessor: String,
    pub config: MountConfig,
    #[serde(default)]
    pub local: bool,
    #[serde(default)]
    pub seal_wrap: bool,
    pub uuid: Option<String>,
}

#[derive(Debug, Serialize, Clone)]
pub struct AuthMountParams {
    #[serde(rename = "type")]
    pub mount_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub config: Option<MountTuneParams>,
}

// --- Policies ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct PolicyInfo {
    pub name: String,
    pub policy: String,
}

// --- Leases ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct LeaseInfo {
    pub id: String,
    pub issue_time: String,
    pub expire_time: Option<String>,
    pub last_renewal: Option<String>,
    pub renewable: bool,
    pub ttl: u64,
}

/// Lease renewal response
///
/// Vault returns renewal info at the response envelope level (not inside
/// `.data`), so this maps directly to the top-level fields
#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct LeaseRenewal {
    pub lease_id: String,
    pub lease_duration: u64,
    pub renewable: bool,
}

// --- Audit ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct AuditDevice {
    #[serde(rename = "type")]
    pub audit_type: String,
    #[serde(default)]
    pub description: String,
    #[serde(default)]
    pub options: HashMap<String, String>,
    pub path: String,
    #[serde(default)]
    pub local: bool,
}

#[derive(Debug, Serialize, Clone)]
pub struct AuditParams {
    #[serde(rename = "type")]
    pub audit_type: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
    pub options: HashMap<String, String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub local: Option<bool>,
}

// --- Key status ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct KeyStatus {
    pub term: u64,
    pub install_time: String,
    pub encryptions: Option<u64>,
}

// --- Plugins ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct PluginInfo {
    pub name: String,
    pub command: String,
    #[serde(default)]
    pub args: Vec<String>,
    pub sha256: String,
    pub version: Option<String>,
    pub builtin: bool,
}

#[derive(Debug, Serialize, Clone)]
pub struct RegisterPluginRequest {
    pub name: String,
    #[serde(rename = "type")]
    pub plugin_type: String,
    pub command: String,
    pub sha256: String,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub args: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub env: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
}

// --- Raft ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct RaftConfig {
    #[serde(default)]
    pub servers: Vec<RaftServer>,
    pub index: u64,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct RaftServer {
    pub node_id: String,
    pub address: String,
    pub leader: bool,
    pub voter: bool,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct AutopilotState {
    pub healthy: bool,
    pub failure_tolerance: u64,
    pub leader: String,
    #[serde(default)]
    pub voters: Vec<String>,
    #[serde(default)]
    pub servers: HashMap<String, AutopilotServerState>,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct AutopilotServerState {
    pub id: String,
    pub name: String,
    pub address: String,
    pub node_status: String,
    pub status: String,
    pub healthy: bool,
    pub last_contact: String,
    pub last_index: u64,
    pub last_term: u64,
    pub voter: bool,
    pub leader: bool,
}

// --- Namespaces (Enterprise) ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct NamespaceInfo {
    pub id: String,
    pub path: String,
}

// --- Quotas ---

#[derive(Debug, Serialize, Default, Clone)]
pub struct RateLimitQuotaRequest {
    pub name: String,
    pub rate: f64,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub burst: Option<u64>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub path: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub interval: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub block_interval: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub role: Option<String>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub inheritable: Option<bool>,
}

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct RateLimitQuota {
    pub name: String,
    pub rate: f64,
    pub burst: u64,
    pub path: String,
    pub interval: Option<String>,
    pub block_interval: Option<String>,
    pub role: Option<String>,
    #[serde(rename = "type")]
    pub quota_type: Option<String>,
}

// --- Rekey ---

#[derive(Debug, Serialize, Clone)]
pub struct RekeyInitRequest {
    pub secret_shares: u32,
    pub secret_threshold: u32,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pgp_keys: Option<Vec<String>>,
    #[serde(skip_serializing_if = "Option::is_none")]
    pub backup: Option<bool>,
}

#[derive(Deserialize, Zeroize, ZeroizeOnDrop)]
#[non_exhaustive]
pub struct RekeyStatus {
    pub started: bool,
    pub nonce: String,
    pub t: u32,
    pub n: u32,
    pub progress: u32,
    pub required: u32,
    pub pgp_finger_prints: Option<Vec<String>>,
    pub backup: bool,
    pub verification_required: bool,
    pub complete: bool,
    pub keys: Option<Vec<SecretString>>,
    pub keys_base64: Option<Vec<SecretString>>,
}

impl Clone for RekeyStatus {
    fn clone(&self) -> Self {
        Self {
            started: self.started,
            nonce: self.nonce.clone(),
            t: self.t,
            n: self.n,
            progress: self.progress,
            required: self.required,
            pgp_finger_prints: self.pgp_finger_prints.clone(),
            backup: self.backup,
            verification_required: self.verification_required,
            complete: self.complete,
            keys: self.keys.clone(),
            keys_base64: self.keys_base64.clone(),
        }
    }
}

impl fmt::Debug for RekeyStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("RekeyStatus")
            .field("started", &self.started)
            .field("nonce", &self.nonce)
            .field("t", &self.t)
            .field("n", &self.n)
            .field("progress", &self.progress)
            .field("required", &self.required)
            .field("pgp_finger_prints", &self.pgp_finger_prints)
            .field("backup", &self.backup)
            .field("verification_required", &self.verification_required)
            .field("complete", &self.complete)
            .field(
                "keys",
                &self.keys.as_ref().map(|v| {
                    v.iter()
                        .map(|s| redact(s.expose_secret()))
                        .collect::<Vec<_>>()
                }),
            )
            .field(
                "keys_base64",
                &self.keys_base64.as_ref().map(|v| {
                    v.iter()
                        .map(|s| redact(s.expose_secret()))
                        .collect::<Vec<_>>()
                }),
            )
            .finish()
    }
}

// --- Generate root ---

#[derive(Debug, Serialize, Default, Clone)]
pub struct GenerateRootInitRequest {
    #[serde(skip_serializing_if = "Option::is_none")]
    pub pgp_key: Option<String>,
}

#[derive(Deserialize, Zeroize, ZeroizeOnDrop)]
#[non_exhaustive]
pub struct GenerateRootStatus {
    pub started: bool,
    #[zeroize(skip)]
    pub nonce: String,
    pub progress: u32,
    pub required: u32,
    pub complete: bool,
    pub encoded_token: Option<SecretString>,
    pub encoded_root_token: Option<SecretString>,
    pub otp_length: Option<u64>,
    pub otp: Option<SecretString>,
}

impl Clone for GenerateRootStatus {
    fn clone(&self) -> Self {
        Self {
            started: self.started,
            nonce: self.nonce.clone(),
            progress: self.progress,
            required: self.required,
            complete: self.complete,
            encoded_token: self.encoded_token.clone(),
            encoded_root_token: self.encoded_root_token.clone(),
            otp_length: self.otp_length,
            otp: self.otp.clone(),
        }
    }
}

impl fmt::Debug for GenerateRootStatus {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("GenerateRootStatus")
            .field("started", &self.started)
            .field("nonce", &self.nonce)
            .field("progress", &self.progress)
            .field("required", &self.required)
            .field("complete", &self.complete)
            .field(
                "encoded_token",
                &self
                    .encoded_token
                    .as_ref()
                    .map(|s| redact(s.expose_secret())),
            )
            .field(
                "encoded_root_token",
                &self
                    .encoded_root_token
                    .as_ref()
                    .map(|s| redact(s.expose_secret())),
            )
            .field("otp_length", &self.otp_length)
            .field("otp", &self.otp.as_ref().map(|s| redact(s.expose_secret())))
            .finish()
    }
}

// --- Remount ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct RemountStatus {
    pub migration_id: String,
}

// --- Host info ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct HostInfo {
    pub cpu: Option<Vec<serde_json::Value>>,
    pub disk: Option<Vec<serde_json::Value>>,
    pub host: Option<serde_json::Value>,
    pub memory: Option<serde_json::Value>,
    pub timestamp: String,
}

// --- In-flight requests ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct InFlightRequest {
    pub request_id: String,
    pub request_path: String,
    pub client_address: String,
    pub start_time: String,
}

// --- Version history ---

#[derive(Debug, Deserialize, Clone)]
#[non_exhaustive]
pub struct VersionHistoryEntry {
    #[serde(default)]
    pub version: String,
    pub timestamp_installed: String,
    pub build_date: Option<String>,
    pub previous_version: Option<String>,
}