Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allowed signers option to CLI and Config #11

Merged
merged 5 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,25 @@ use std::{env, path::PathBuf};
#[derive(Parser)]
#[command(version, about, long_about = None)]
pub struct Cli {
/// The path to the 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 allowed signers file used by Git.
#[arg(
long,
value_name = "PATH",
env = "HANKO_ALLOWED_SIGNERS",
default_value = git_allowed_signers_path()
)]
pub allowed_signers: PathBuf,

#[command(flatten)]
logging: Logging,

Expand Down Expand Up @@ -66,6 +75,12 @@ fn default_config_path() -> Resettable<OsStr> {
}
}

/// The path to the allowed signers file as configured within Git.
fn git_allowed_signers_path() -> Resettable<OsStr> {
// TODO: Get value from Git config.
Resettable::Value("~/.config/git/allowed_signers".into())
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
5 changes: 4 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathBuf>,
users: Option<Vec<User>>,
organizations: Option<Vec<Organization>>,
local: Option<Vec<String>>,
Expand All @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down