From 763789f029b3be8e32efc49e9a94f61bf139ec3e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sat, 11 Apr 2020 04:37:17 -0400 Subject: read lock timeout from config --- src/bin/agent.rs | 3 ++- src/bin/rbw.rs | 1 + src/config.rs | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/bin/agent.rs b/src/bin/agent.rs index b233403..9d4f7c5 100644 --- a/src/bin/agent.rs +++ b/src/bin/agent.rs @@ -163,9 +163,10 @@ struct State { impl Agent { fn new() -> Self { + let config = rbw::config::Config::load().unwrap(); Self { timeout: tokio::time::delay_for( - tokio::time::Duration::from_secs(600), // read from config + tokio::time::Duration::from_secs(config.lock_timeout), ), state: std::sync::Arc::new(tokio::sync::RwLock::new(State { priv_key: None, diff --git a/src/bin/rbw.rs b/src/bin/rbw.rs index e23d005..9a968ff 100644 --- a/src/bin/rbw.rs +++ b/src/bin/rbw.rs @@ -95,6 +95,7 @@ fn config_set(key: &str, value: &str) { "email" => config.email = Some(value.to_string()), "base_url" => config.base_url = Some(value.to_string()), "identity_url" => config.identity_url = Some(value.to_string()), + "lock_timeout" => config.lock_timeout = value.parse().unwrap(), _ => unimplemented!(), } config.save().unwrap(); diff --git a/src/config.rs b/src/config.rs index d02bc11..0e79893 100644 --- a/src/config.rs +++ b/src/config.rs @@ -8,6 +8,12 @@ pub struct Config { pub email: Option, pub base_url: Option, pub identity_url: Option, + #[serde(default = "default_lock_timeout")] + pub lock_timeout: u64, +} + +fn default_lock_timeout() -> u64 { + 3600 } impl Config { -- cgit v1.2.3-54-g00ecf