diff --git a/Cargo.toml b/Cargo.toml index f583062..ffdc7d3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,15 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] - -log = "0.4" # Apparently Rust has an entire logging setup - this is the base crate +log = "0.4" # Apparently Rust has an entire logging setup - this is the base crate pretty_env_logger = "0.4" # The logging implementation we've chosen for the above - clap = "2" # CLI argument parser +serde = { version = "1.0", features = ["derive"] } # Serialisation +serde_derive = "1.0" # Serialisation helper +toml = "0.5" # TOML serialisation module + + psk-client = { version = "0.1", features = ["vendored-openssl"] } # Pre-shared key TLS support diff --git a/src/agent/mod.rs b/src/agent/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 427c398..a03c697 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,12 @@ use std::process; use clap::{ App, AppSettings, Arg, SubCommand }; + + +mod settings; + +use settings::Settings; + fn main() { // Initialise the logging system pretty_env_logger::init(); diff --git a/src/settings/definitions.rs b/src/settings/definitions.rs new file mode 100644 index 0000000..358aed7 --- /dev/null +++ b/src/settings/definitions.rs @@ -0,0 +1,20 @@ + +use serde::{ Serialize, Deserialize }; + +#[derive(Debug, Serialize, Deserialize, Clone)] +pub struct Settings { + pub bind_address : String, + pub port : i16, + pub secret_join : String, + pub secret_query : String +} +impl Default for Settings { + fn default() -> Settings { + Settings { + bind_address: "127.0.0.1".to_string(), + port: 3015, + secret_join: "CHANGE_ME".to_string(), + secret_query: "CHANGE_ME".to_string() + } + } +} diff --git a/src/settings/mod.rs b/src/settings/mod.rs new file mode 100644 index 0000000..f58aa7c --- /dev/null +++ b/src/settings/mod.rs @@ -0,0 +1,32 @@ +use std::fs; + +// for toml::toml!, which are aren't currently using +// #[macro_use] +// use toml; + + +mod definitions; +pub use definitions::Settings; + + +impl Settings { + pub fn new() -> Settings { + Settings::default() + } + + /// Creates a new Settings object from the contents of a given (TOML) file. + pub fn from_file(filename : String) -> Settings { + let config_str = match fs::read_to_string(&filename) { + Ok(str) => str, + Err(error) => { + // println!("{}", error); + panic!("{}", error); // Oops, something went wrong while reading the config file + } + }; + + let config_obj : Settings = toml::from_str(&config_str).unwrap(); + // info!("{:?}", config_obj); + return config_obj; + } + +}