forge
ExploreLog in

Tahinli/forge

public
0 watching
★ 0
2.6 KiB
1//! Push and pull mirrors: the direction enum and the mirror shape. The stored shape is in
2//! migrations/0017_mirrors.sql; the store functions live in store/mirrors.rs.
3//!
4//! A mirror never carries its secret. `has_secret` says whether one is stored; the plaintext is
5//! read back only through `Store::mirror_secret`, for the sync worker.
6
7use crate::model::Id;
8
9/// Which way refs flow. Stored as the `as_str` name.
10#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum MirrorDirection {
12 /// The repo's refs come from the remote URL.
13 Pull,
14 /// Our refs are pushed to the remote URL.
15 Push,
16}
17
18impl MirrorDirection {
19 pub fn as_str(self) -> &'static str {
20 match self {
21 MirrorDirection::Pull => "pull",
22 MirrorDirection::Push => "push",
23 }
24 }
25}
26
27impl std::str::FromStr for MirrorDirection {
28 type Err = crate::error::Error;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 match s {
32 "pull" => Ok(MirrorDirection::Pull),
33 "push" => Ok(MirrorDirection::Push),
34 other => Err(crate::error::Error::Database(format!(
35 "unknown mirror direction {other:?}"
36 ))),
37 }
38 }
39}
40
41/// A repo mirror. Has no secret field; see `Store::mirror_secret`.
42#[derive(Debug, Clone, PartialEq, Eq)]
43pub struct Mirror {
44 pub id: Id,
45 pub repo_id: Id,
46 pub direction: MirrorDirection,
47 pub url: String,
48 pub username: String,
49 pub has_secret: bool,
50 pub interval_minutes: u32,
51 pub enabled: bool,
52 pub next_sync_at: String,
53 pub last_sync_at: Option<String>,
54 pub last_ok: Option<bool>,
55 pub last_error: Option<String>,
56 pub created_at: String,
57}
58
59/// Input for `Store::create_mirror`. `secret` is plaintext; the store seals it.
60#[derive(Debug, Clone, Copy)]
61pub struct NewMirror<'a> {
62 pub repo_id: &'a str,
63 pub direction: MirrorDirection,
64 pub url: &'a str,
65 pub username: &'a str,
66 pub secret: Option<&'a [u8]>,
67 pub interval_minutes: u32,
68}
69
70/// What `Store::update_mirror` does with the stored secret.
71#[derive(Debug, Clone, Copy, PartialEq, Eq)]
72pub enum SecretUpdate<'a> {
73 /// Leave the stored secret as it is.
74 Keep,
75 /// Remove the stored secret.
76 Clear,
77 /// Replace the stored secret with this plaintext, which the store seals.
78 Set(&'a [u8]),
79}
80
81/// Most push mirrors one repo may have.
82pub const MAX_PUSH_MIRRORS: u32 = 10;
83/// Shortest allowed sync interval, in minutes. `0` means manual only.
84pub const MIN_INTERVAL_MINUTES: u32 = 10;
85/// Default sync interval, in minutes.
86pub const DEFAULT_INTERVAL_MINUTES: u32 = 480;