//! Push and pull mirrors: the direction enum and the mirror shape. The stored shape is in //! migrations/0017_mirrors.sql; the store functions live in store/mirrors.rs. //! //! A mirror never carries its secret. `has_secret` says whether one is stored; the plaintext is //! read back only through `Store::mirror_secret`, for the sync worker. use crate::model::Id; /// Which way refs flow. Stored as the `as_str` name. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum MirrorDirection { /// The repo's refs come from the remote URL. Pull, /// Our refs are pushed to the remote URL. Push, } impl MirrorDirection { pub fn as_str(self) -> &'static str { match self { MirrorDirection::Pull => "pull", MirrorDirection::Push => "push", } } } impl std::str::FromStr for MirrorDirection { type Err = crate::error::Error; fn from_str(s: &str) -> Result { match s { "pull" => Ok(MirrorDirection::Pull), "push" => Ok(MirrorDirection::Push), other => Err(crate::error::Error::Database(format!( "unknown mirror direction {other:?}" ))), } } } /// A repo mirror. Has no secret field; see `Store::mirror_secret`. #[derive(Debug, Clone, PartialEq, Eq)] pub struct Mirror { pub id: Id, pub repo_id: Id, pub direction: MirrorDirection, pub url: String, pub username: String, pub has_secret: bool, pub interval_minutes: u32, pub enabled: bool, pub next_sync_at: String, pub last_sync_at: Option, pub last_ok: Option, pub last_error: Option, pub created_at: String, } /// Input for `Store::create_mirror`. `secret` is plaintext; the store seals it. #[derive(Debug, Clone, Copy)] pub struct NewMirror<'a> { pub repo_id: &'a str, pub direction: MirrorDirection, pub url: &'a str, pub username: &'a str, pub secret: Option<&'a [u8]>, pub interval_minutes: u32, } /// What `Store::update_mirror` does with the stored secret. #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum SecretUpdate<'a> { /// Leave the stored secret as it is. Keep, /// Remove the stored secret. Clear, /// Replace the stored secret with this plaintext, which the store seals. Set(&'a [u8]), } /// Most push mirrors one repo may have. pub const MAX_PUSH_MIRRORS: u32 = 10; /// Shortest allowed sync interval, in minutes. `0` means manual only. pub const MIN_INTERVAL_MINUTES: u32 = 10; /// Default sync interval, in minutes. pub const DEFAULT_INTERVAL_MINUTES: u32 = 480;