|
@@ -1,4 +1,4 @@
|
|
|
-use clap::{Parser,Subcommand};
|
|
|
+use clap::{Parser, Subcommand};
|
|
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
#[clap(author, version, about, long_about = None)]
|
|
@@ -13,54 +13,68 @@ struct RootArgs {
|
|
|
command: Command,
|
|
|
}
|
|
|
|
|
|
-#[derive(Debug,Subcommand)]
|
|
|
+#[derive(Debug, Subcommand)]
|
|
|
enum Command {
|
|
|
Init,
|
|
|
Cert(CertArgs),
|
|
|
- Server(ServerArgs)
|
|
|
+ Server(ServerArgs),
|
|
|
}
|
|
|
|
|
|
impl RootArgs {
|
|
|
async fn run(&self) {
|
|
|
-
|
|
|
if let Command::Init = self.command {
|
|
|
return self.init().await;
|
|
|
}
|
|
|
|
|
|
- let storage = crate::DB::new(crate::schema::schema(), &self.db, false);
|
|
|
+ let storage = microrm::DB::new(
|
|
|
+ crate::schema::schema(),
|
|
|
+ &self.db,
|
|
|
+ microrm::CreateMode::MustExist,
|
|
|
+ );
|
|
|
|
|
|
if let Err(e) = storage {
|
|
|
println!("Error occured while loading database: {}", e);
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
let storage = storage.unwrap();
|
|
|
|
|
|
match &self.command {
|
|
|
Command::Init => unreachable!(),
|
|
|
Command::Cert(v) => v.run(&self, &storage).await,
|
|
|
- Command::Server(v) => v.run(&self, &storage).await,
|
|
|
+ Command::Server(v) => v.run(&self, storage).await,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
async fn init(&self) {
|
|
|
// first check to see if the database is already vaguely set up
|
|
|
- let maybedb = crate::DB::new(crate::schema::schema(), &self.db, false);
|
|
|
+ let maybedb = microrm::DB::new(
|
|
|
+ crate::schema::schema(),
|
|
|
+ &self.db,
|
|
|
+ microrm::CreateMode::MustExist,
|
|
|
+ );
|
|
|
|
|
|
if maybedb.is_ok() {
|
|
|
println!("Database already initialized, not overwriting!");
|
|
|
- return
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
println!("Initializing!");
|
|
|
|
|
|
- let db = crate::DB::new(crate::schema::schema(), &self.db, true).expect("Unable to initialize database!");
|
|
|
+ let db = microrm::DB::new(
|
|
|
+ crate::schema::schema(),
|
|
|
+ &self.db,
|
|
|
+ microrm::CreateMode::AllowNewDatabase,
|
|
|
+ )
|
|
|
+ .expect("Unable to initialize database!");
|
|
|
|
|
|
// create primary realm
|
|
|
- microrm::query::add(&db, &crate::schema::Realm { shortname: "primary".to_string() });
|
|
|
+ db.query_interface().add(&crate::schema::Realm {
|
|
|
+ shortname: "primary".to_string(),
|
|
|
+ });
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-#[derive(Debug,Subcommand)]
|
|
|
+#[derive(Debug, Subcommand)]
|
|
|
enum CertCommand {
|
|
|
Inspect,
|
|
|
Generate,
|
|
@@ -69,11 +83,11 @@ enum CertCommand {
|
|
|
#[derive(Debug, Parser)]
|
|
|
struct CertArgs {
|
|
|
#[clap(subcommand)]
|
|
|
- command: CertCommand
|
|
|
+ command: CertCommand,
|
|
|
}
|
|
|
|
|
|
impl CertArgs {
|
|
|
- async fn run(&self, root: &RootArgs, si: &crate::DB) {
|
|
|
+ async fn run(&self, root: &RootArgs, si: µrm::DB) {
|
|
|
match &self.command {
|
|
|
CertCommand::Inspect => {
|
|
|
crate::cert::inspect(si, &root.realm);
|
|
@@ -86,13 +100,11 @@ impl CertArgs {
|
|
|
}
|
|
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
-struct ServerArgs {
|
|
|
-
|
|
|
-}
|
|
|
+struct ServerArgs {}
|
|
|
|
|
|
impl ServerArgs {
|
|
|
- async fn run(&self, root: &RootArgs, _si: &crate::DB) {
|
|
|
-
|
|
|
+ async fn run(&self, root: &RootArgs, db: microrm::DB) {
|
|
|
+ crate::server::run_server(db).await;
|
|
|
}
|
|
|
}
|
|
|
|