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 support for RESTIC_PASSWORD env variable #57

Merged
merged 1 commit into from
Jul 31, 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
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