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
mod entity;
mod policy;

use std::time::Duration;

use serde::{Deserialize, Serialize};
use uuid::Uuid;

use crate::{
    backend::{BackendCategory, BackendType},
    mount::MountConfig,
    state::StorageState,
    token::Token,
};
pub use entity::*;
pub use policy::*;

#[derive(Debug, Serialize, Deserialize)]
pub struct InitializeParams {
    pub shares: u8,
    pub threshold: u8,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum InitializeResponse {
    NewKeyShares(InitializedKeyShares),
    ExistingKey(InitializedWithExistingKey),
}

#[derive(Debug, Serialize, Deserialize)]
pub struct InitializedKeyShares {
    pub shares: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct InitializedWithExistingKey {
    pub message: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct UnsealParams {
    pub shares: Vec<String>,
}

#[derive(Debug, Serialize, Deserialize)]
#[serde(tag = "unseal_status", content = "data")]
pub enum UnsealResponse {
    #[serde(rename = "complete")]
    Complete { root_token: Token },
    #[serde(rename = "in progress")]
    InProgress {
        threshold: u8,
        key_shares_total: u8,
        key_shares_provided: usize,
    },
}

#[derive(Debug, Serialize, Deserialize)]
pub struct SealResponse {
    pub message: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct StatusResponse {
    pub state: StorageState,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct CreateMountParams {
    #[serde(rename = "type")]
    pub variant: BackendType,
    #[serde(default)]
    pub config: MountConfig,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct CreateMountResponse {
    #[serde(rename = "type")]
    pub variant: BackendType,
    #[serde(default)]
    pub config: MountConfig,
    pub id: Uuid,
    pub path: String,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct UpdateMountParams {
    pub config: MountConfig,
}

#[derive(Debug, Deserialize, Serialize)]
pub struct UpdateMountResponse {
    #[serde(rename = "type")]
    pub variant: BackendType,
    #[serde(default)]
    pub config: MountConfig,
    pub id: Uuid,
    pub path: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MountsListResponse {
    pub auth: Vec<MountsListItemResponse>,
    pub secret: Vec<MountsListItemResponse>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct DisableMountResponse {
    pub mount: MountsListItemResponse,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct MountsListItemResponse {
    pub id: Uuid,
    pub path: String,
    pub category: BackendCategory,
    #[serde(rename = "type")]
    pub variant: BackendType,
    pub config: MountConfig,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct LeaseEntry {
    pub id: String,
    pub issued_mount_path: String,
    pub issue_time: String,
    pub expire_time: String,
    pub last_renewal_time: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RevokedLeasesResponse {
    pub leases: Vec<LeaseEntry>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RevokedLeaseResponse {
    pub lease: LeaseEntry,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct LookupLeaseResponse {
    pub lease: LeaseEntry,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct ListLeasesResponse {
    pub leases: Vec<LeaseEntry>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RenewLeaseParams {
    #[serde(with = "humantime_serde")]
    pub ttl: Option<Duration>,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct RenewLeaseResponse {
    pub lease: LeaseEntry,
}