forked from TrueCloudLab/restic
wip
This commit is contained in:
parent
aaef54559a
commit
740e2d6139
3 changed files with 8 additions and 7 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -16,6 +16,7 @@ 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"`
|
||||||
|
|
Loading…
Reference in a new issue