implement dumping and loading the full database

This commit is contained in:
Jonathan Krebs
2025-01-24 04:18:14 +01:00
committed by Mario Voigt
parent 1c15c1402f
commit 8f285370d9
4 changed files with 120 additions and 15 deletions

View File

@ -57,10 +57,18 @@ fn main() -> miette::Result<()> {
.help("Check config for validity")
.long("check"))
.arg(
Arg::new("dump")
Arg::new("dump-db")
.help("Dump all internal databases")
.long("dump")
.conflicts_with("load"))
.long("dump-db")
.alias("dump")
.conflicts_with("dump-users")
.conflicts_with("load-users")
.conflicts_with("load-db")
.takes_value(true)
.value_name("FILE")
.value_hint(ValueHint::AnyPath)
.default_missing_value("bffh-db.toml")
)
.arg(
Arg::new("dump-users")
.help("Dump the users db to the given file as TOML")
@ -69,18 +77,33 @@ fn main() -> miette::Result<()> {
.value_name("FILE")
.value_hint(ValueHint::AnyPath)
.default_missing_value("users.toml")
.conflicts_with("load"))
.conflicts_with("load-users")
.conflicts_with("load-db")
.conflicts_with("dump-db")
)
.arg(
Arg::new("force")
.help("force ops that may clobber")
.long("force")
)
.arg(
Arg::new("load")
.help("Load values into the internal databases")
.long("load")
Arg::new("load-users")
.help("Load users into the internal databases")
.long("load-users")
.alias("load")
.takes_value(true)
.conflicts_with("dump"))
.conflicts_with("dump-db")
.conflicts_with("load-db")
.conflicts_with("dump-users")
)
.arg(
Arg::new("load-db")
.help("Load values into the internal databases")
.long("load-db")
.takes_value(true)
.conflicts_with("dump-db")
.conflicts_with("load-users")
.conflicts_with("dump-users"))
.arg(Arg::new("keylog")
.help("log TLS keys into PATH. If no path is specified the value of the envvar SSLKEYLOGFILE is used.")
.long("tls-key-log")
@ -137,8 +160,16 @@ fn main() -> miette::Result<()> {
let mut config = config::read(&PathBuf::from_str(configpath).unwrap())?;
if matches.is_present("dump") {
return Err(miette::miette!("DB Dumping is currently not implemented, except for the users db, using `--dump-users`"));
if matches.is_present("dump-db") {
let mut bffh = Difluoroborane::new(config)?;
let fname = matches.value_of("dump-db").unwrap();
bffh.dump_db(fname)?;
return Ok(());
} else if matches.is_present("load-db") {
let mut bffh = Difluoroborane::new(config)?;
let fname = matches.value_of("load-db").unwrap();
bffh.load_db(fname)?;
return Ok(());
} else if matches.is_present("dump-users") {
let bffh = Difluoroborane::new(config)?;
@ -150,12 +181,12 @@ fn main() -> miette::Result<()> {
tracing::info!("successfully dumped {} users", number);
return Ok(());
} else if matches.is_present("load") {
} else if matches.is_present("load-users") {
let bffh = Difluoroborane::new(config)?;
bffh.users.load_file(matches.value_of("load").unwrap())?;
bffh.users.load_file(matches.value_of("load-users").unwrap())?;
tracing::info!("loaded users from {}", matches.value_of("load").unwrap());
tracing::info!("loaded users from {}", matches.value_of("load-users").unwrap());
return Ok(());
} else {