From 588c40aaef17da1e420adbce7f2936ec8c2f2518 Mon Sep 17 00:00:00 2001 From: Michael Eischer Date: Sun, 28 Sep 2025 22:22:22 +0200 Subject: [PATCH] global: unexport ReadPassword and ReadRepo --- internal/global/global.go | 10 +++++----- internal/global/global_test.go | 4 ++-- internal/global/secondary_repo.go | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/global/global.go b/internal/global/global.go index e5f172b59..215ef1f9c 100644 --- a/internal/global/global.go +++ b/internal/global/global.go @@ -205,10 +205,10 @@ func LoadPasswordFromFile(pwdFile string) (string, error) { return strings.TrimSpace(string(s)), errors.Wrap(err, "Readfile") } -// ReadPassword reads the password from a password file, the environment +// readPassword reads the password from a password file, the environment // variable RESTIC_PASSWORD or prompts the user. If the context is canceled, // the function leaks the password reading goroutine. -func ReadPassword(ctx context.Context, gopts Options, prompt string) (string, error) { +func readPassword(ctx context.Context, gopts Options, prompt string) (string, error) { if gopts.InsecureNoPassword { if gopts.Password != "" { return "", errors.Fatal("--insecure-no-password must not be specified together with providing a password via a cli option or environment variable") @@ -236,12 +236,12 @@ func ReadPassword(ctx context.Context, gopts Options, prompt string) (string, er // passwords don't match. If the context is canceled, the function leaks the // password reading goroutine. func ReadPasswordTwice(ctx context.Context, gopts Options, prompt1, prompt2 string) (string, error) { - pw1, err := ReadPassword(ctx, gopts, prompt1) + pw1, err := readPassword(ctx, gopts, prompt1) if err != nil { return "", err } if gopts.Term.InputIsTerminal() { - pw2, err := ReadPassword(ctx, gopts, prompt2) + pw2, err := readPassword(ctx, gopts, prompt2) if err != nil { return "", err } @@ -322,7 +322,7 @@ func OpenRepository(ctx context.Context, gopts Options, printer progress.Printer } for ; passwordTriesLeft > 0; passwordTriesLeft-- { - gopts.Password, err = ReadPassword(ctx, gopts, "enter password for repository: ") + gopts.Password, err = readPassword(ctx, gopts, "enter password for repository: ") if ctx.Err() != nil { return nil, ctx.Err() } diff --git a/internal/global/global_test.go b/internal/global/global_test.go index 2982d81c1..7d5ead722 100644 --- a/internal/global/global_test.go +++ b/internal/global/global_test.go @@ -41,11 +41,11 @@ func TestReadRepo(t *testing.T) { func TestReadEmptyPassword(t *testing.T) { opts := Options{InsecureNoPassword: true} - password, err := ReadPassword(context.TODO(), opts, "test") + password, err := readPassword(context.TODO(), opts, "test") rtest.OK(t, err) rtest.Equals(t, "", password, "got unexpected password") opts.Password = "invalid" - _, err = ReadPassword(context.TODO(), opts, "test") + _, err = readPassword(context.TODO(), opts, "test") rtest.Assert(t, strings.Contains(err.Error(), "must not be specified together with providing a password via a cli option or environment variable"), "unexpected error message, got %v", err) } diff --git a/internal/global/secondary_repo.go b/internal/global/secondary_repo.go index fb08131be..1224495df 100644 --- a/internal/global/secondary_repo.go +++ b/internal/global/secondary_repo.go @@ -115,7 +115,7 @@ func (opts *SecondaryRepoOptions) FillGlobalOpts(ctx context.Context, gopts Opti return Options{}, false, err } } - dstGopts.Password, err = ReadPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ") + dstGopts.Password, err = readPassword(ctx, dstGopts, "enter password for "+repoPrefix+" repository: ") if err != nil { return Options{}, false, err }