mirror of
https://github.com/restic/restic.git
synced 2025-12-12 03:11:56 +00:00
Refactor password resolving.
Instead of determining the password lazily during ReadPassword(), do so now in cobra.PersistentPreRunE() so we can store the result in the globalOptions and reuse/override when applicable without having to worry about the environment or flag options interfering.
This commit is contained in:
@@ -3,7 +3,6 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/repository"
|
||||
@@ -60,14 +59,10 @@ func getNewPassword(gopts GlobalOptions) (string, error) {
|
||||
return testKeyNewPassword, nil
|
||||
}
|
||||
|
||||
// Since we already have an open repository, temporary remove the overrides
|
||||
// to prompt the user for their passwd
|
||||
oldPasswd := os.Getenv("RESTIC_PASSWORD")
|
||||
defer func() { os.Setenv("RESTIC_PASSWORD", oldPasswd) }()
|
||||
os.Unsetenv("RESTIC_PASSWORD")
|
||||
// Since we already have an open repository, temporary remove the password
|
||||
// to prompt the user for the passwd.
|
||||
newopts := gopts
|
||||
newopts.password = ""
|
||||
newopts.PasswordFile = ""
|
||||
|
||||
return ReadPasswordTwice(newopts,
|
||||
"enter password for new key: ",
|
||||
|
||||
Reference in New Issue
Block a user