Skip to content
Clone

refactor(user): remove security types (inlined)

zhenyi committed
parent 640d223 commit 1452245 Browse files

1 file changed

+0 −219

Deleted lib/user/features/security/types.rs
@@ -1,219 +0,0 @@
1use serde::{Deserialize, Serialize};
2use time::format_description::well_known::Rfc3339;
3use utoipa::ToSchema;
4use uuid::Uuid;
5
6#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
7#[serde(rename_all = "lowercase")]
8pub enum AccessKeyScope {
9 Read,
10 Write,
11 Repo,
12 Admin,
13 All,
14}
15
16impl From<db::user::user_access_keys::AccessKeyScope> for AccessKeyScope {
17 fn from(s: db::user::user_access_keys::AccessKeyScope) -> Self {
18 use db::user::user_access_keys::AccessKeyScope as Db;
19 match s {
20 Db::Read => AccessKeyScope::Read,
21 Db::Write => AccessKeyScope::Write,
22 Db::Repo => AccessKeyScope::Repo,
23 Db::Admin => AccessKeyScope::Admin,
24 Db::All => AccessKeyScope::All,
25 }
26 }
27}
28
29impl From<AccessKeyScope> for db::user::user_access_keys::AccessKeyScope {
30 fn from(s: AccessKeyScope) -> Self {
31 use db::user::user_access_keys::AccessKeyScope as Db;
32 match s {
33 AccessKeyScope::Read => Db::Read,
34 AccessKeyScope::Write => Db::Write,
35 AccessKeyScope::Repo => Db::Repo,
36 AccessKeyScope::Admin => Db::Admin,
37 AccessKeyScope::All => Db::All,
38 }
39 }
40}
41
42#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
43#[serde(rename_all = "snake_case")]
44pub enum SshKeyType {
45 SshRsa,
46 SshEd25519,
47 EcdsaSha2Nistp256,
48}
49
50impl From<db::user::user_ssh_keys::SshKeyType> for SshKeyType {
51 fn from(t: db::user::user_ssh_keys::SshKeyType) -> Self {
52 use db::user::user_ssh_keys::SshKeyType as Db;
53 match t {
54 Db::SshRsa => SshKeyType::SshRsa,
55 Db::SshEd25519 => SshKeyType::SshEd25519,
56 Db::EcdsaSha2Nistp256 => SshKeyType::EcdsaSha2Nistp256,
57 }
58 }
59}
60
61impl From<SshKeyType> for db::user::user_ssh_keys::SshKeyType {
62 fn from(t: SshKeyType) -> Self {
63 use db::user::user_ssh_keys::SshKeyType as Db;
64 match t {
65 SshKeyType::SshRsa => Db::SshRsa,
66 SshKeyType::SshEd25519 => Db::SshEd25519,
67 SshKeyType::EcdsaSha2Nistp256 => Db::EcdsaSha2Nistp256,
68 }
69 }
70}
71
72#[derive(Debug, Clone, Copy, Serialize, Deserialize, ToSchema)]
73#[serde(rename_all = "snake_case")]
74pub enum PushPlatform {
75 WebPush,
76 AndroidFcm,
77 IosApns,
78}
79
80impl From<db::user::user_push_subscriptions::PushSubscriptionPlatform> for PushPlatform {
81 fn from(p: db::user::user_push_subscriptions::PushSubscriptionPlatform) -> Self {
82 use db::user::user_push_subscriptions::PushSubscriptionPlatform as Db;
83 match p {
84 Db::WebPush => PushPlatform::WebPush,
85 Db::AndroidFcm => PushPlatform::AndroidFcm,
86 Db::IosApns => PushPlatform::IosApns,
87 }
88 }
89}
90
91impl From<PushPlatform> for db::user::user_push_subscriptions::PushSubscriptionPlatform {
92 fn from(p: PushPlatform) -> Self {
93 use db::user::user_push_subscriptions::PushSubscriptionPlatform as Db;
94 match p {
95 PushPlatform::WebPush => Db::WebPush,
96 PushPlatform::AndroidFcm => Db::AndroidFcm,
97 PushPlatform::IosApns => Db::IosApns,
98 }
99 }
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
103pub struct RecoveryCodeView {
104 pub id: Uuid,
105 pub used_at: Option<String>,
106 pub expires_at: Option<String>,
107 pub created_at: String,
108}
109
110impl From<db::user::user_recovery_codes::Model> for RecoveryCodeView {
111 fn from(m: db::user::user_recovery_codes::Model) -> Self {
112 Self {
113 id: m.id,
114 used_at: m.used_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
115 expires_at: m.expires_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
116 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
117 }
118 }
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
122pub struct RegenerateRecoveryResp {
123 pub codes: Vec<String>,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
127pub struct AccessKeyView {
128 pub id: Uuid,
129 pub name: String,
130 pub token_last_eight: String,
131 pub scope: AccessKeyScope,
132 pub created_at: String,
133 pub updated_at: String,
134}
135
136impl From<db::user::user_access_keys::Model> for AccessKeyView {
137 fn from(m: db::user::user_access_keys::Model) -> Self {
138 Self {
139 id: m.id,
140 name: m.name,
141 token_last_eight: m.token_last_eight,
142 scope: m.scope.into(),
143 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
144 updated_at: m.updated_at.format(&Rfc3339).unwrap_or_default(),
145 }
146 }
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
150pub struct CreateAccessKeyCmd {
151 pub name: String,
152 pub scope: AccessKeyScope,
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
156pub struct CreateAccessKeyResp {
157 pub key: AccessKeyView,
158 pub token: String,
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
162pub struct SshKeyView {
163 pub id: Uuid,
164 pub name: String,
165 pub key_type: SshKeyType,
166 pub fingerprint: String,
167 pub last_used_at: Option<String>,
168 pub created_at: String,
169}
170
171impl From<db::user::user_ssh_keys::Model> for SshKeyView {
172 fn from(m: db::user::user_ssh_keys::Model) -> Self {
173 Self {
174 id: m.id,
175 name: m.name,
176 key_type: m.key_type.into(),
177 fingerprint: m.fingerprint,
178 last_used_at: m.last_used_at.map(|t| t.format(&Rfc3339).unwrap_or_default()),
179 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
180 }
181 }
182}
183
184#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
185pub struct AddSshKeyCmd {
186 pub name: String,
187 pub content: String,
188 pub key_type: Option<SshKeyType>,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
192pub struct PushSubscriptionView {
193 pub id: Uuid,
194 pub platform: PushPlatform,
195 pub endpoint: String,
196 pub user_agent: Option<String>,
197 pub created_at: String,
198}
199
200impl From<db::user::user_push_subscriptions::Model> for PushSubscriptionView {
201 fn from(m: db::user::user_push_subscriptions::Model) -> Self {
202 Self {
203 id: m.id,
204 platform: m.platform.into(),
205 endpoint: m.endpoint,
206 user_agent: m.user_agent,
207 created_at: m.created_at.format(&Rfc3339).unwrap_or_default(),
208 }
209 }
210}
211
212#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
213pub struct UpsertPushCmd {
214 pub endpoint: String,
215 pub p256dh_key: String,
216 pub auth_key: String,
217 pub platform: PushPlatform,
218 pub user_agent: Option<String>,
219}
No newline at end of file