Skip to content

Commit

Permalink
signing: pass &UserSettings in to backends
Browse files Browse the repository at this point in the history
If we add our own config storage implementation, .get_<type>() functions will
be moved to UserSettings object.
  • Loading branch information
yuja committed Nov 21, 2024
1 parent 58f3a30 commit 12cfba6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 6 additions & 3 deletions lib/src/gpg_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use std::str;
use thiserror::Error;

use crate::settings::ConfigResultExt as _;
use crate::settings::UserSettings;
use crate::signing::SigStatus;
use crate::signing::SignError;
use crate::signing::SigningBackend;
Expand Down Expand Up @@ -144,12 +145,14 @@ impl GpgBackend {
self
}

pub fn from_config(config: &config::Config) -> Result<Self, config::ConfigError> {
let program = config
pub fn from_settings(settings: &UserSettings) -> Result<Self, config::ConfigError> {
let program = settings
.config()
.get_string("signing.backends.gpg.program")
.optional()?
.unwrap_or_else(|| "gpg".into());
let allow_expired_keys = config
let allow_expired_keys = settings
.config()
.get_bool("signing.backends.gpg.allow-expired-keys")
.optional()?
.unwrap_or(false);
Expand Down
8 changes: 2 additions & 6 deletions lib/src/signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,8 @@ impl Signer {
/// chooses one of them to be used for signing depending on the config.
pub fn from_settings(settings: &UserSettings) -> Result<Self, SignInitError> {
let mut backends: Vec<Box<dyn SigningBackend>> = vec![
Box::new(
GpgBackend::from_config(settings.config()).map_err(SignInitError::BackendConfig)?,
),
Box::new(
SshBackend::from_config(settings.config()).map_err(SignInitError::BackendConfig)?,
),
Box::new(GpgBackend::from_settings(settings).map_err(SignInitError::BackendConfig)?),
Box::new(SshBackend::from_settings(settings).map_err(SignInitError::BackendConfig)?),
// Box::new(X509Backend::from_settings(settings).map_err(..)?),
];

Expand Down
9 changes: 6 additions & 3 deletions lib/src/ssh_signing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use either::Either;
use thiserror::Error;

use crate::settings::ConfigResultExt as _;
use crate::settings::UserSettings;
use crate::signing::SigStatus;
use crate::signing::SignError;
use crate::signing::SigningBackend;
Expand Down Expand Up @@ -117,12 +118,14 @@ impl SshBackend {
}
}

pub fn from_config(config: &config::Config) -> Result<Self, config::ConfigError> {
let program = config
pub fn from_settings(settings: &UserSettings) -> Result<Self, config::ConfigError> {
let program = settings
.config()
.get_string("signing.backends.ssh.program")
.optional()?
.unwrap_or_else(|| "ssh-keygen".into());
let allowed_signers = config
let allowed_signers = settings
.config()
.get_string("signing.backends.ssh.allowed-signers")
.optional()?;
Ok(Self::new(program.into(), allowed_signers.map(|v| v.into())))
Expand Down

0 comments on commit 12cfba6

Please sign in to comment.