diff --git a/Cargo.lock b/Cargo.lock index e0741c48..13c8c393 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -588,6 +588,7 @@ dependencies = [ "serde_asn1_der", "signal-hook", "std-semaphore", + "structopt", "threadpool", "toml 0.4.10", "tss-esapi", @@ -652,6 +653,17 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b" +[[package]] +name = "proc-macro-error" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeccfe4d5d8ea175d5f0e4a2ad0637e0f4121d63bd99d356fb1f39ab2e7c6097" +dependencies = [ + "proc-macro2 1.0.6", + "quote 1.0.2", + "syn 1.0.11", +] + [[package]] name = "proc-macro2" version = "0.4.30" @@ -1079,6 +1091,29 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "structopt" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30b3a3e93f5ad553c38b3301c8a0a0cec829a36783f6a0c467fc4bf553a5f5bf" +dependencies = [ + "clap", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea692d40005b3ceba90a9fe7a78fa8d4b82b0ce627eebbffc329aab850f3410e" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.6", + "quote 1.0.2", + "syn 1.0.11", +] + [[package]] name = "syn" version = "0.15.44" diff --git a/Cargo.toml b/Cargo.toml index 1956b44b..15b55994 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ serde_asn1_der = { git = "https://github.com/Devolutions/serde_asn1_der", rev = num-bigint-dig = "0.5" tss-esapi = { git = "https://github.com/parallaxsecond/rust-tss-esapi", tag = "0.4.0", optional = true } bincode = "1.1.4" +structopt = "0.3.5" [dev-dependencies] parsec-client-test = { git = "https://github.com/parallaxsecond/parsec-client-test", tag = "0.1.8" } diff --git a/README.md b/README.md index 0d514bbc..6c41a706 100644 --- a/README.md +++ b/README.md @@ -100,6 +100,7 @@ This project uses the following third party crates: * a fork of serde\_asn1\_der at `https://github.com/Devolutions/serde_asn1_der` (BSD-3-Clause and MIT) * num-bigint-dig (MIT and Apache-2.0) * bincode (MIT) +* structopt (MIT and Apache-2.0) This project uses the following third party libraries: * [Mbed Crypto](https://github.com/ARMmbed/mbed-crypto) (Apache-2.0) diff --git a/src/bin/main.rs b/src/bin/main.rs index 6d452e8b..f19722dc 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -21,11 +21,30 @@ use std::sync::{ Arc, }; use std::time::Duration; +use structopt::StructOpt; + +/// Parsec is the Platform AbstRaction for SECurity, a new open-source initiative to provide a +/// common API to secure services in a platform-agnostic way. +/// +/// Parsec documentation is available at: +/// https://parallaxsecond.github.io/parsec-book/index.html +/// +/// Most of Parsec configuration comes from its configuration file. +/// Please check the documentation to find more about configuration: +/// https://parallaxsecond.github.io/parsec-book/user_guides/configuration.html +#[derive(StructOpt)] +struct Opts { + /// Sets the configuration file path + #[structopt(short, long, default_value = "config.toml")] + config: String, +} -const CONFIG_FILE_PATH: &str = "./config.toml"; const MAIN_LOOP_DEFAULT_SLEEP: u64 = 10; fn main() -> Result<(), Error> { + // Parsing the command line arguments. + let opts: Opts = Opts::from_args(); + // Register a boolean set to true when the SIGTERM signal is received. let kill_signal = Arc::new(AtomicBool::new(false)); // Register a boolean set to true when the SIGHUP signal is received. @@ -34,7 +53,7 @@ fn main() -> Result<(), Error> { flag::register(SIGHUP, reload_signal.clone())?; let mut config_file = - ::std::fs::read_to_string(CONFIG_FILE_PATH).expect("Failed to read configuration file"); + ::std::fs::read_to_string(opts.config.clone()).expect("Failed to read configuration file"); let mut config: ServiceConfig = toml::from_str(&config_file).expect("Failed to parse service configuration"); @@ -70,7 +89,7 @@ fn main() -> Result<(), Error> { drop(listener); drop(threadpool); - config_file = ::std::fs::read_to_string(CONFIG_FILE_PATH) + config_file = ::std::fs::read_to_string(opts.config.clone()) .expect("Failed to read configuration file"); config = toml::from_str(&config_file).expect("Failed to parse service configuration"); front_end_handler =