From 6286a6503048d2fc535112094c2aa9e47a36148f Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sat, 27 Apr 2024 11:27:19 +0000 Subject: [PATCH 1/5] Add allowed signers CLI option --- src/cli/main.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index c8ff64c..5ec1854 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -8,7 +8,7 @@ use std::{env, path::PathBuf}; #[derive(Parser)] #[command(version, about, long_about = None)] pub struct Cli { - /// The path to the configuration file. + /// The path to the hanko configuration file. #[arg( short, long, @@ -18,6 +18,15 @@ pub struct Cli { )] pub config: PathBuf, + /// The path to the allowed signers file used by Git. + #[arg( + long, + value_name = "FILE", + env = "HANKO_ALLLOWED_SIGNERS", + // TODO: Get default value from Git config. + )] + pub allowed_signers: PathBuf, + #[command(flatten)] logging: Logging, From 369a4e5277d31d9fde061f63c92b293b8ca350e8 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sat, 27 Apr 2024 11:32:39 +0000 Subject: [PATCH 2/5] Add allowed signers field to configuration --- src/config.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index fdace70..dc9c833 100644 --- a/src/config.rs +++ b/src/config.rs @@ -4,11 +4,12 @@ use figment::{ Figment, }; use serde::{Deserialize, Serialize}; -use std::path::Path; +use std::path::{Path, PathBuf}; /// The main configuration. #[derive(Debug, Deserialize, Serialize, PartialEq)] pub struct Config { + allowed_signers: Option, users: Option>, organizations: Option>, local: Option>, @@ -19,6 +20,7 @@ impl Default for Config { /// The default configuration containing common sources. fn default() -> Self { Config { + allowed_signers: None, users: None, organizations: None, local: None, @@ -107,6 +109,7 @@ mod tests { url = "https://git.acme.corp" "#}; let expected = Config { + allowed_signers: None, users: Some(vec![ User { name: "torvalds".to_string(), From 22e10ad66dae343dd071df39e6ec1c2961c35504 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sat, 27 Apr 2024 18:22:53 +0000 Subject: [PATCH 3/5] Add dummy `git_allowed_signers_path` fn --- src/cli/main.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index 5ec1854..ab9cbe5 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -23,7 +23,7 @@ pub struct Cli { long, value_name = "FILE", env = "HANKO_ALLLOWED_SIGNERS", - // TODO: Get default value from Git config. + default_value = git_allowed_signers_path() )] pub allowed_signers: PathBuf, @@ -75,6 +75,12 @@ fn default_config_path() -> Resettable { } } +/// The path to the allowed signers file as configured within Git. +fn git_allowed_signers_path() -> Resettable { + // TODO: Get value from Git config. + Resettable::Value("~/.config/git/allowed_signers".into()) +} + #[cfg(test)] mod tests { use super::*; From 04938d033701bfbad2d21df4d2ccda45d98bee0c Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sat, 27 Apr 2024 18:28:44 +0000 Subject: [PATCH 4/5] Shorten arg descriptions --- src/cli/main.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index ab9cbe5..7aded72 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -8,20 +8,20 @@ use std::{env, path::PathBuf}; #[derive(Parser)] #[command(version, about, long_about = None)] pub struct Cli { - /// The path to the hanko configuration file. + /// The configuration file. #[arg( short, long, - value_name = "FILE", + value_name = "PATH", env = "HANKO_CONFIG", default_value = default_config_path() )] pub config: PathBuf, - /// The path to the allowed signers file used by Git. + /// The allowed signers file used by Git. #[arg( long, - value_name = "FILE", + value_name = "PATH", env = "HANKO_ALLLOWED_SIGNERS", default_value = git_allowed_signers_path() )] From f610de76fedbb61214d833e372468e8f579b1af8 Mon Sep 17 00:00:00 2001 From: Marvin Vogt Date: Sat, 27 Apr 2024 18:43:03 +0000 Subject: [PATCH 5/5] Fix typo "ALLLOWED" --- src/cli/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/main.rs b/src/cli/main.rs index 7aded72..b28786e 100644 --- a/src/cli/main.rs +++ b/src/cli/main.rs @@ -22,7 +22,7 @@ pub struct Cli { #[arg( long, value_name = "PATH", - env = "HANKO_ALLLOWED_SIGNERS", + env = "HANKO_ALLOWED_SIGNERS", default_value = git_allowed_signers_path() )] pub allowed_signers: PathBuf,