summaryrefslogtreecommitdiff
path: root/src/config
diff options
context:
space:
mode:
authorStuart Stock <stuart@int08h.com>2018-09-30 20:50:24 -0500
committerStuart Stock <stuart@int08h.com>2018-09-30 20:50:24 -0500
commita1af24e764250cc4abda5c1c5670ca243ee4ad7f (patch)
treeeac04856bf24ce7748ae5e785eea98afca16ed11 /src/config
parentd1a76e00fc92d1550e748fd1b393eaf0f10f7112 (diff)
downloadroughenough-a1af24e764250cc4abda5c1c5670ca243ee4ad7f.zip
Work-in-progress; still working to clean up config
Diffstat (limited to 'src/config')
-rw-r--r--src/config/environment.rs4
-rw-r--r--src/config/file.rs2
-rw-r--r--src/config/mod.rs36
3 files changed, 39 insertions, 3 deletions
diff --git a/src/config/environment.rs b/src/config/environment.rs
index c4d2c06..7ebe588 100644
--- a/src/config/environment.rs
+++ b/src/config/environment.rs
@@ -49,7 +49,7 @@ const ROUGHENOUGH_BATCH_SIZE: &str = "ROUGHENOUGH_BATCH_SIZE";
const ROUGHENOUGH_STATUS_INTERVAL: &str = "ROUGHENOUGH_STATUS_INTERVAL";
impl EnvironmentConfig {
- pub fn new() -> Self {
+ pub fn new() -> Result<Self, Error> {
let mut cfg = EnvironmentConfig {
port: 0,
interface: "".to_string(),
@@ -91,7 +91,7 @@ impl EnvironmentConfig {
cfg.status_interval = Duration::from_secs(val as u64);
};
- cfg
+ Ok(cfg)
}
}
diff --git a/src/config/file.rs b/src/config/file.rs
index 24011bb..8aa8ca2 100644
--- a/src/config/file.rs
+++ b/src/config/file.rs
@@ -45,7 +45,7 @@ pub struct FileConfig {
}
impl FileConfig {
- pub fn from_file(config_file: &str) -> Result<Self, Error> {
+ pub fn new(config_file: &str) -> Result<Self, Error> {
let mut infile = File::open(config_file).expect("failed to open config file");
let mut contents = String::new();
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 0cd8742..02ab941 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -22,6 +22,7 @@
//!
extern crate hex;
+extern crate log;
use std::net::SocketAddr;
use std::time::Duration;
@@ -88,3 +89,38 @@ pub trait ServerConfig {
/// Convenience function to create a `SocketAddr` from the provided `interface` and `port`
fn socket_addr(&self) -> Result<SocketAddr, Error>;
}
+
+pub fn is_valid_config(cfg: &Box<ServerConfig>) -> bool {
+ let mut is_valid = true;
+
+ if cfg.port() == 0 {
+ error!("unset port: {}", cfg.port());
+ is_valid = false;
+ }
+ if cfg.interface().is_empty() {
+ error!("interface is missing");
+ is_valid = false;
+ }
+ match cfg.socket_addr() {
+ Err(e) => {
+ error!("{}:{}: {:?}", cfg.interface(), cfg.port(), e);
+ is_valid = false;
+ }
+ _ => ()
+ }
+ if cfg.seed().is_empty() {
+ error!("seed value is missing");
+ is_valid = false;
+ }
+ if !cfg.seed().is_empty() && cfg.seed().len() != 32 {
+ error!("seed value must be 32 characters long");
+ is_valid = false;
+ }
+ if cfg.batch_size() < 1 || cfg.batch_size() > 64 {
+ error!("batch_size {} is invalid; valid range 1-64", cfg.batch_size());
+ is_valid = false;
+ }
+
+ is_valid
+}
+