Compare commits
No commits in common. "53c83b8a3b4a02a1cc7532aa07f93e91afd93acf" and "9cb4f6c11ed684d762add174907acb890b665351" have entirely different histories.
53c83b8a3b
...
9cb4f6c11e
1 changed files with 17 additions and 35 deletions
44
src/main.rs
44
src/main.rs
|
@ -1,5 +1,5 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{env,fmt,fs::File};
|
use std::{env,fs::File};
|
||||||
use std::io::BufReader;
|
use std::io::BufReader;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -9,6 +9,9 @@ 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)]
|
||||||
|
@ -37,31 +40,12 @@ 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)]
|
||||||
enum PortRegistration {
|
struct PortRegistration {
|
||||||
Config {
|
|
||||||
file: PathBuf,
|
file: PathBuf,
|
||||||
job: String,
|
job: String,
|
||||||
group: String,
|
group: String,
|
||||||
task: String,
|
task: String,
|
||||||
service: Option<String>
|
service: Option<String>,
|
||||||
},
|
|
||||||
Builtin(String),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for PortRegistration {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
||||||
match self {
|
|
||||||
PortRegistration::Config { file, job, group, task, service } =>
|
|
||||||
write!(f, "in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
|
|
||||||
file.display(), job, group, task,
|
|
||||||
match &service {
|
|
||||||
None => "<noname>",
|
|
||||||
Some(s) => s
|
|
||||||
}),
|
|
||||||
PortRegistration::Builtin(reason) =>
|
|
||||||
write!(f, "{}", reason),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ctx {
|
impl Ctx {
|
||||||
|
@ -88,7 +72,7 @@ impl Ctx {
|
||||||
self.add_diplonat_tag(
|
self.add_diplonat_tag(
|
||||||
conf,
|
conf,
|
||||||
&job.datacenters,
|
&job.datacenters,
|
||||||
PortRegistration::Config {
|
PortRegistration {
|
||||||
file: PathBuf::from(file),
|
file: PathBuf::from(file),
|
||||||
job: jobname.clone(),
|
job: jobname.clone(),
|
||||||
group: groupname.clone(),
|
group: groupname.clone(),
|
||||||
|
@ -144,13 +128,6 @@ 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))?
|
||||||
}
|
}
|
||||||
|
@ -161,7 +138,12 @@ fn main() -> Result<ExitCode> {
|
||||||
have_conflicts = true;
|
have_conflicts = true;
|
||||||
println!("Conflict in site {}, port {:?}:", &datacenter, port);
|
println!("Conflict in site {}, port {:?}:", &datacenter, port);
|
||||||
for reg in ®s {
|
for reg in ®s {
|
||||||
println!("- {}", reg)
|
println!("- in {}, job \"{}\", group \"{}\", task \"{}\", service \"{}\"",
|
||||||
|
reg.file.display(), reg.job, reg.group, reg.task,
|
||||||
|
match ®.service {
|
||||||
|
None => "<noname>",
|
||||||
|
Some(s) => s
|
||||||
|
})
|
||||||
}
|
}
|
||||||
println!()
|
println!()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue