Skip to content
Clone

refactor(repo): remove deploy_key types (inlined)

zhenyi committed
parent 27eac23 commit d56dc1d Browse files

1 file changed

+0 −75

Deleted lib/repo/features/deploy_key/types.rs
@@ -1,75 +0,0 @@
1use db::repo::repo_deploy_keys as key_entity;
2use db::repo::repo_deploy_keys::DeployKeyType;
3use serde::{Deserialize, Serialize};
4use time::OffsetDateTime;
5use time::format_description::well_known::Rfc3339;
6use utoipa::{IntoParams, ToSchema};
7use uuid::Uuid;
8
9fn fmt_ts(ts: OffsetDateTime) -> String {
10 ts.format(&Rfc3339).unwrap_or_default()
11}
12
13fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
14 ts.map(fmt_ts)
15}
16
17#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
18pub struct DeployKeyView {
19 pub id: Uuid,
20 pub key_id: i64,
21 pub repo_id: Uuid,
22 pub title: String,
23 pub key_type: String,
24 pub fingerprint: String,
25 pub content: String,
26 pub url: String,
27 pub read_only: bool,
28 pub last_used_at: Option<String>,
29 pub created_at: String,
30}
31
32impl From<key_entity::Model> for DeployKeyView {
33 fn from(m: key_entity::Model) -> Self {
34 let id = m.id;
35 let repo_id = m.repo_id;
36 Self {
37 id,
38 key_id: 0,
39 repo_id,
40 title: m.title,
41 key_type: match m.key_type {
42 DeployKeyType::Rsa => "rsa".to_string(),
43 DeployKeyType::Ed25519 => "ed25519".to_string(),
44 DeployKeyType::Ecdsa => "ecdsa".to_string(),
45 },
46 fingerprint: m.fingerprint,
47 content: m.content,
48 url: format!("/repo/{repo_id}/keys/{id}"),
49 read_only: m.is_read_only,
50 last_used_at: fmt_ts_opt(m.last_used_at),
51 created_at: fmt_ts(m.created_at),
52 }
53 }
54}
55
56#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
57pub struct DeployKeyPage {
58 pub items: Vec<DeployKeyView>,
59 pub total: i64,
60}
61
62#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
63pub struct CreateDeployKeyOption {
64 pub title: String,
65 pub key: String,
66 pub read_only: Option<bool>,
67}
68
69#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
70pub struct ListDeployKeyQuery {
71 pub key_id: Option<Uuid>,
72 pub fingerprint: Option<String>,
73 pub page: Option<u64>,
74 pub limit: Option<u64>,
75}