Add support for "external" port reservation and add ones for forgejo
This commit is contained in:
parent
734d97e191
commit
53c83b8a3b
1 changed files with 28 additions and 16 deletions
44
src/main.rs
44
src/main.rs
|
@ -9,9 +9,6 @@ use anyhow::{anyhow, Result};
|
||||||
mod parsing;
|
mod parsing;
|
||||||
use 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...)
|
// parses a diplonat port parameter: ({tcp,udp}_port XX YY...)
|
||||||
// matches `DiplonatParameter` in diplonat (`src/consul_actor.rs`)
|
// matches `DiplonatParameter` in diplonat (`src/consul_actor.rs`)
|
||||||
#[derive(Deserialize, Debug)]
|
#[derive(Deserialize, Debug)]
|
||||||
|
@ -40,22 +37,30 @@ struct Ctx {
|
||||||
enum Port { Udp(u16), Tcp(u16) }
|
enum Port { Udp(u16), Tcp(u16) }
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
struct PortRegistration {
|
enum PortRegistration {
|
||||||
file: PathBuf,
|
Config {
|
||||||
job: String,
|
file: PathBuf,
|
||||||
group: String,
|
job: String,
|
||||||
task: String,
|
group: String,
|
||||||
service: Option<String>,
|
task: String,
|
||||||
|
service: Option<String>
|
||||||
|
},
|
||||||
|
Builtin(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for PortRegistration {
|
impl fmt::Display for PortRegistration {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
|
match self {
|
||||||
self.file.display(), self.job, self.group, self.task,
|
PortRegistration::Config { file, job, group, task, service } =>
|
||||||
match &self.service {
|
write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
|
||||||
None => "<noname>",
|
file.display(), job, group, task,
|
||||||
Some(s) => s
|
match &service {
|
||||||
})
|
None => "<noname>",
|
||||||
|
Some(s) => s
|
||||||
|
}),
|
||||||
|
PortRegistration::Builtin(reason) =>
|
||||||
|
write!(f, "{}", reason),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,7 +88,7 @@ impl Ctx {
|
||||||
self.add_diplonat_tag(
|
self.add_diplonat_tag(
|
||||||
conf,
|
conf,
|
||||||
&job.datacenters,
|
&job.datacenters,
|
||||||
PortRegistration {
|
PortRegistration::Config {
|
||||||
file: PathBuf::from(file),
|
file: PathBuf::from(file),
|
||||||
job: jobname.clone(),
|
job: jobname.clone(),
|
||||||
group: groupname.clone(),
|
group: groupname.clone(),
|
||||||
|
@ -139,6 +144,13 @@ fn main() -> Result<ExitCode> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut ctx = Ctx::new();
|
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..] {
|
for file in &args[1..] {
|
||||||
ctx.add_file(Path::new(file))?
|
ctx.add_file(Path::new(file))?
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue