Skip to content

Add a command-line option to select configuration #81

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
25 changes: 22 additions & 3 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");

Expand Down Expand Up @@ -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 =
Expand Down