Skip to content

Commit 85abf0c

Browse files
authored
Add allowed signers option to CLI and Config (#11)
* Add allowed signers CLI option * Add allowed signers field to configuration * Add dummy `git_allowed_signers_path` fn * Shorten arg descriptions * Fix typo "ALLLOWED"
1 parent d14091e commit 85abf0c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/cli/main.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,25 @@ use std::{env, path::PathBuf};
88
#[derive(Parser)]
99
#[command(version, about, long_about = None)]
1010
pub struct Cli {
11-
/// The path to the configuration file.
11+
/// The configuration file.
1212
#[arg(
1313
short,
1414
long,
15-
value_name = "FILE",
15+
value_name = "PATH",
1616
env = "HANKO_CONFIG",
1717
default_value = default_config_path()
1818
)]
1919
pub config: PathBuf,
2020

21+
/// The allowed signers file used by Git.
22+
#[arg(
23+
long,
24+
value_name = "PATH",
25+
env = "HANKO_ALLOWED_SIGNERS",
26+
default_value = git_allowed_signers_path()
27+
)]
28+
pub allowed_signers: PathBuf,
29+
2130
#[command(flatten)]
2231
logging: Logging,
2332

@@ -66,6 +75,12 @@ fn default_config_path() -> Resettable<OsStr> {
6675
}
6776
}
6877

78+
/// The path to the allowed signers file as configured within Git.
79+
fn git_allowed_signers_path() -> Resettable<OsStr> {
80+
// TODO: Get value from Git config.
81+
Resettable::Value("~/.config/git/allowed_signers".into())
82+
}
83+
6984
#[cfg(test)]
7085
mod tests {
7186
use super::*;

src/config.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use figment::{
44
Figment,
55
};
66
use serde::{Deserialize, Serialize};
7-
use std::path::Path;
7+
use std::path::{Path, PathBuf};
88

99
/// The main configuration.
1010
#[derive(Debug, Deserialize, Serialize, PartialEq)]
1111
pub struct Config {
12+
allowed_signers: Option<PathBuf>,
1213
users: Option<Vec<User>>,
1314
organizations: Option<Vec<Organization>>,
1415
local: Option<Vec<String>>,
@@ -19,6 +20,7 @@ impl Default for Config {
1920
/// The default configuration containing common sources.
2021
fn default() -> Self {
2122
Config {
23+
allowed_signers: None,
2224
users: None,
2325
organizations: None,
2426
local: None,
@@ -107,6 +109,7 @@ mod tests {
107109
url = "https://git.acme.corp"
108110
"#};
109111
let expected = Config {
112+
allowed_signers: None,
110113
users: Some(vec![
111114
User {
112115
name: "torvalds".to_string(),

0 commit comments

Comments
 (0)