Implement shared authentication leases
This commit is contained in:
@@ -12,6 +12,7 @@ use std::{
|
||||
use serde::Deserialize;
|
||||
use url::Url;
|
||||
|
||||
use crate::authentication::{AuthenticationTimeout, DEFAULT_AUTHENTICATION_TIMEOUT};
|
||||
use crate::presentation::{ClipboardTimeout, DEFAULT_CLIPBOARD_TIMEOUT};
|
||||
|
||||
const APPLICATION_DIRECTORY: &str = "ironstorage";
|
||||
@@ -27,6 +28,7 @@ pub struct Config {
|
||||
key_material: PathBuf,
|
||||
editor: Option<EditorCommand>,
|
||||
clipboard_timeout: ClipboardTimeout,
|
||||
authentication_timeout: AuthenticationTimeout,
|
||||
git_remotes: Vec<GitRemote>,
|
||||
}
|
||||
|
||||
@@ -60,6 +62,11 @@ impl Config {
|
||||
self.clipboard_timeout
|
||||
}
|
||||
|
||||
/// Shared inactivity lease used by every interactive frontend.
|
||||
pub fn authentication_timeout(&self) -> AuthenticationTimeout {
|
||||
self.authentication_timeout
|
||||
}
|
||||
|
||||
pub fn git_remotes(&self) -> &[GitRemote] {
|
||||
&self.git_remotes
|
||||
}
|
||||
@@ -410,9 +417,17 @@ struct RawConfig {
|
||||
editor: Option<RawEditor>,
|
||||
clipboard_timeout_seconds: Option<u64>,
|
||||
#[serde(default)]
|
||||
security: RawSecurity,
|
||||
#[serde(default)]
|
||||
git: RawGit,
|
||||
}
|
||||
|
||||
#[derive(Default, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
struct RawSecurity {
|
||||
inactivity_timeout_seconds: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
#[serde(untagged)]
|
||||
enum RawEditor {
|
||||
@@ -473,6 +488,14 @@ fn validate_config(source: PathBuf, raw: RawConfig) -> Result<Config, ConfigErro
|
||||
.map_err(|_| ConfigError::InvalidField {
|
||||
field: "clipboard_timeout_seconds",
|
||||
})?;
|
||||
let authentication_timeout = AuthenticationTimeout::new(Duration::from_secs(
|
||||
raw.security
|
||||
.inactivity_timeout_seconds
|
||||
.unwrap_or(DEFAULT_AUTHENTICATION_TIMEOUT.as_secs()),
|
||||
))
|
||||
.map_err(|_| ConfigError::InvalidField {
|
||||
field: "security.inactivity_timeout_seconds",
|
||||
})?;
|
||||
let git_remotes = validate_remotes(raw.git.remotes)?;
|
||||
|
||||
Ok(Config {
|
||||
@@ -482,6 +505,7 @@ fn validate_config(source: PathBuf, raw: RawConfig) -> Result<Config, ConfigErro
|
||||
key_material,
|
||||
editor,
|
||||
clipboard_timeout,
|
||||
authentication_timeout,
|
||||
git_remotes,
|
||||
})
|
||||
}
|
||||
@@ -624,9 +648,16 @@ fn validate_known_fields(value: &toml::Value, source: &Path) -> Result<(), Confi
|
||||
"key_material",
|
||||
"editor",
|
||||
"clipboard_timeout_seconds",
|
||||
"security",
|
||||
"git",
|
||||
],
|
||||
)?;
|
||||
if let Some(security) = root.get("security") {
|
||||
let security = security.as_table().ok_or_else(|| ConfigError::Malformed {
|
||||
path: source.to_owned(),
|
||||
})?;
|
||||
validate_table(security, "security", &["inactivity_timeout_seconds"])?;
|
||||
}
|
||||
let Some(git) = root.get("git") else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user