From 53c83b8a3b4a02a1cc7532aa07f93e91afd93acf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arma=C3=ABl=20Gu=C3=A9neau?= Date: Fri, 25 Oct 2024 22:18:55 +0200 Subject: [PATCH] Add support for "external" port reservation and add ones for forgejo --- src/main.rs | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 3088ce7..753a3c1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,6 @@ use anyhow::{anyhow, Result}; mod parsing; use parsing::*; -// TODO: add support for (builtin?) "external" port reservations -// -> bespin, 80+443 pour forgejo - // parses a diplonat port parameter: ({tcp,udp}_port XX YY...) // matches `DiplonatParameter` in diplonat (`src/consul_actor.rs`) #[derive(Deserialize, Debug)] @@ -40,22 +37,30 @@ struct Ctx { enum Port { Udp(u16), Tcp(u16) } #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)] -struct PortRegistration { - file: PathBuf, - job: String, - group: String, - task: String, - service: Option, +enum PortRegistration { + Config { + file: PathBuf, + job: String, + group: String, + task: String, + service: Option + }, + Builtin(String), } impl fmt::Display for PortRegistration { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"", - self.file.display(), self.job, self.group, self.task, - match &self.service { - None => "", - Some(s) => s - }) + match self { + PortRegistration::Config { file, job, group, task, service } => + write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"", + file.display(), job, group, task, + match &service { + None => "", + Some(s) => s + }), + PortRegistration::Builtin(reason) => + write!(f, "{}", reason), + } } } @@ -83,7 +88,7 @@ impl Ctx { self.add_diplonat_tag( conf, &job.datacenters, - PortRegistration { + PortRegistration::Config { file: PathBuf::from(file), job: jobname.clone(), group: groupname.clone(), @@ -139,6 +144,13 @@ fn main() -> Result { } let mut ctx = Ctx::new(); + + // port registrations managed externally and not described in .hcl files + ctx.ports.insert((String::from("bespin"), Port::Tcp(80)), + vec![PortRegistration::Builtin(String::from("forjego"))]); + ctx.ports.insert((String::from("bespin"), Port::Tcp(443)), + vec![PortRegistration::Builtin(String::from("forjego"))]); + for file in &args[1..] { ctx.add_file(Path::new(file))? }