diff options
author | Daniel Mueller <deso@posteo.net> | 2019-01-09 13:41:53 -0800 |
---|---|---|
committer | Daniel Mueller <deso@posteo.net> | 2019-01-09 13:41:53 -0800 |
commit | 4842ac86c0a805c5c4a679644594252ca5ea388b (patch) | |
tree | d49fcace411df5361f7c9fd6880629e7bec0a1d3 /nitrocli/src/main.rs | |
parent | 749a5c78c2075c5d37b01ec4fd23704aa5cfdf09 (diff) | |
download | nitrocli-4842ac86c0a805c5c4a679644594252ca5ea388b.tar.gz nitrocli-4842ac86c0a805c5c4a679644594252ca5ea388b.tar.bz2 |
Introduce Admin and User PIN fields to execution context
In order to run tests fully non-interactively we need to avoid the need
for using the GPG agent's PIN entry and caching mechanism. To accomplish
that, we first need an alternate way to supply the PINs to use to the
program.
This change offers such a way by extending the execution context with
two fields representing the PINs that are populated by corresponding
environment variables, NITROCLI_ADMIN_PIN & NITROCLI_USER_PIN, if set.
While only two PINs are required right now, because the program allows
for the changing of each of the PINs, we also add two fields
representing new PINs. These latter two fields are populated by the
NITROCLI_NEW_ADMIN_PIN and NITROCLI_NEW_USER_PIN environment variables.
Diffstat (limited to 'nitrocli/src/main.rs')
-rw-r--r-- | nitrocli/src/main.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/nitrocli/src/main.rs b/nitrocli/src/main.rs index 9f56f75..9a4216a 100644 --- a/nitrocli/src/main.rs +++ b/nitrocli/src/main.rs @@ -81,6 +81,7 @@ mod pinentry; mod tests; use std::env; +use std::ffi; use std::io; use std::process; use std::result; @@ -89,12 +90,29 @@ use crate::error::Error; type Result<T> = result::Result<T, Error>; +const NITROCLI_ADMIN_PIN: &str = "NITROCLI_ADMIN_PIN"; +const NITROCLI_USER_PIN: &str = "NITROCLI_USER_PIN"; +const NITROCLI_NEW_ADMIN_PIN: &str = "NITROCLI_NEW_ADMIN_PIN"; +const NITROCLI_NEW_USER_PIN: &str = "NITROCLI_NEW_USER_PIN"; + /// The context used when running the program. pub(crate) struct RunCtx<'io> { /// The `Write` object used as standard output throughout the program. pub stdout: &'io mut dyn io::Write, /// The `Write` object used as standard error throughout the program. pub stderr: &'io mut dyn io::Write, + /// The admin PIN, if provided through an environment variable. + pub admin_pin: Option<ffi::OsString>, + /// The user PIN, if provided through an environment variable. + pub user_pin: Option<ffi::OsString>, + /// The new admin PIN to set, if provided through an environment variable. + /// + /// This variable is only used by commands that change the admin PIN. + pub new_admin_pin: Option<ffi::OsString>, + /// The new user PIN, if provided through an environment variable. + /// + /// This variable is only used by commands that change the user PIN. + pub new_user_pin: Option<ffi::OsString>, } fn run<'ctx, 'io: 'ctx>(ctx: &'ctx mut RunCtx<'io>, args: Vec<String>) -> i32 { @@ -120,6 +138,10 @@ fn main() { let ctx = &mut RunCtx { stdout: &mut io::stdout(), stderr: &mut io::stderr(), + admin_pin: env::var_os(NITROCLI_ADMIN_PIN), + user_pin: env::var_os(NITROCLI_USER_PIN), + new_admin_pin: env::var_os(NITROCLI_NEW_ADMIN_PIN), + new_user_pin: env::var_os(NITROCLI_NEW_USER_PIN), }; process::exit(run(ctx, args)); |