Skip to content

Commit

Permalink
Merge pull request #57 from rluetzner/main
Browse files Browse the repository at this point in the history
add support for RESTIC_PASSWORD env variable
  • Loading branch information
drdo authored Jul 31, 2024
2 parents f6c51da + 9746aaf commit 803516e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl Args {
Password::Command(command)
} else if let Some(file) = cli.password_file {
Password::File(file)
} else if let Some(str) = cli.restic_password {
Password::Plain(str)
} else {
unreachable!("Error in Config: neither password_command nor password_file found. Please open an issue if you see this.")
},
Expand Down Expand Up @@ -84,7 +86,7 @@ impl Args {
#[command(group(
ArgGroup::new("password")
.required(true)
.args(["password_command", "password_file"]),
.args(["password_command", "password_file", "restic_password"]),
))]
struct Cli {
#[arg(short = 'r', long, env = "RESTIC_REPOSITORY")]
Expand All @@ -99,6 +101,9 @@ struct Cli {
#[arg(long, value_name = "FILE", env = "RESTIC_PASSWORD_FILE")]
password_file: Option<String>,

#[arg(value_name = "RESTIC_PASSWORD", env = "RESTIC_PASSWORD")]
restic_password: Option<String>,

/// How many restic subprocesses to spawn concurrently.
///
/// If you get ssh-related errors or too much memory use try lowering this.
Expand Down
4 changes: 4 additions & 0 deletions src/restic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ pub enum Repository {

#[derive(Debug)]
pub enum Password {
/// A plain string (restic: RESTIC_PASSWORD env variable)
Plain(String),
/// A password command (restic: --password-command)
Command(String),
/// A password file (restic: --password-file)
Expand Down Expand Up @@ -216,6 +218,8 @@ impl Restic {
Password::Command(command) =>
cmd.arg("--password-command").arg(command),
Password::File(file) => cmd.arg("--password-file").arg(file),
// Nothing to do, the password is given as an env variable already.
Password::Plain(_str) => &cmd,
};
if self.no_cache {
cmd.arg("--no-cache");
Expand Down

0 comments on commit 803516e

Please sign in to comment.