2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-03 09:30:50 +00:00
This commit is contained in:
Alexander Neumann 2018-05-04 00:21:25 +02:00
parent aaef54559a
commit 740e2d6139
3 changed files with 8 additions and 7 deletions

View File

@ -238,7 +238,11 @@ func Exitf(exitcode int, format string, args ...interface{}) {
} }
// resolvePassword determines the password to be used for opening the repository. // resolvePassword determines the password to be used for opening the repository.
func resolvePassword(opts GlobalOptions, env string) (string, error) { func resolvePassword(opts GlobalOptions) (string, error) {
if opts.Password != "" {
return opts.Password, nil
}
if opts.PasswordFile != "" { if opts.PasswordFile != "" {
s, err := textfile.Read(opts.PasswordFile) s, err := textfile.Read(opts.PasswordFile)
if os.IsNotExist(errors.Cause(err)) { if os.IsNotExist(errors.Cause(err)) {
@ -247,10 +251,6 @@ func resolvePassword(opts GlobalOptions, env string) (string, error) {
return strings.TrimSpace(string(s)), errors.Wrap(err, "Readfile") return strings.TrimSpace(string(s)), errors.Wrap(err, "Readfile")
} }
if pwd := os.Getenv(env); pwd != "" {
return pwd, nil
}
return "", nil return "", nil
} }

View File

@ -70,7 +70,7 @@ directories in an encrypted repository stored on different backends.
if c.Name() == "version" { if c.Name() == "version" {
return nil return nil
} }
pwd, err := resolvePassword(globalOptions, "RESTIC_PASSWORD") pwd, err := resolvePassword(globalOptions)
if err != nil { if err != nil {
fmt.Fprintf(os.Stderr, "Resolving password failed: %v\n", err) fmt.Fprintf(os.Stderr, "Resolving password failed: %v\n", err)
Exit(1) Exit(1)

View File

@ -15,7 +15,8 @@ import (
// Config contains configuration items read from a file. // Config contains configuration items read from a file.
type Config struct { type Config struct {
Repo string `hcl:"repo" flag:"repo" env:"RESTIC_REPOSITORY"` Repo string `hcl:"repo" flag:"repo" env:"RESTIC_REPOSITORY"`
Password string `hcl:"password" env:"RESTIC_PASSWORD"`
Backends map[string]Backend `hcl:"backend"` Backends map[string]Backend `hcl:"backend"`
Backup *Backup `hcl:"backup"` Backup *Backup `hcl:"backup"`