Skip to content

Commit 6238a99

Browse files
authored
feat(cli)!: enable keyring usage by default (#20851)
Make keyring usage for session token storage on by default for supported platforms (Windows and macOS), with the ability to opt-out via --use-keyring=false. This change will be a breaking change for any users depending on the session token being stored on disk, though users can restore file usage via the flag above. This change will also require CLI users to authenticate after updating.
1 parent c266bb8 commit 6238a99

File tree

10 files changed

+249
-158
lines changed

10 files changed

+249
-158
lines changed

cli/clitest/clitest.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ import (
2828
)
2929

3030
// New creates a CLI instance with a configuration pointed to a
31-
// temporary testing directory.
31+
// temporary testing directory. The invocation is set up to use a
32+
// global config directory for the given testing.TB, and keyring
33+
// usage disabled.
3234
func New(t testing.TB, args ...string) (*serpent.Invocation, config.Root) {
3335
var root cli.RootCmd
3436

@@ -59,23 +61,37 @@ func NewWithCommand(
5961
t testing.TB, cmd *serpent.Command, args ...string,
6062
) (*serpent.Invocation, config.Root) {
6163
configDir := config.Root(t.TempDir())
64+
// Keyring usage is disabled here because many existing tests expect the session token
65+
// to be stored on disk and is not properly instrumented for parallel testing against
66+
// the actual operating system keyring.
67+
invArgs := append([]string{"--global-config", string(configDir), "--use-keyring=false"}, args...)
68+
return setupInvocation(t, cmd, invArgs...), configDir
69+
}
70+
71+
func setupInvocation(t testing.TB, cmd *serpent.Command, args ...string,
72+
) *serpent.Invocation {
6273
// I really would like to fail test on error logs, but realistically, turning on by default
6374
// in all our CLI tests is going to create a lot of flaky noise.
6475
logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).
6576
Leveled(slog.LevelDebug).
6677
Named("cli")
6778
i := &serpent.Invocation{
6879
Command: cmd,
69-
Args: append([]string{"--global-config", string(configDir)}, args...),
80+
Args: args,
7081
Stdin: io.LimitReader(nil, 0),
7182
Stdout: (&logWriter{prefix: "stdout", log: logger}),
7283
Stderr: (&logWriter{prefix: "stderr", log: logger}),
7384
Logger: logger,
7485
}
7586
t.Logf("invoking command: %s %s", cmd.Name(), strings.Join(i.Args, " "))
87+
return i
88+
}
7689

77-
// These can be overridden by the test.
78-
return i, configDir
90+
func NewWithDefaultKeyringCommand(t testing.TB, cmd *serpent.Command, args ...string,
91+
) (*serpent.Invocation, config.Root) {
92+
configDir := config.Root(t.TempDir())
93+
invArgs := append([]string{"--global-config", string(configDir)}, args...)
94+
return setupInvocation(t, cmd, invArgs...), configDir
7995
}
8096

8197
// SetupConfig applies the URL and SessionToken of the client to the config.

0 commit comments

Comments
 (0)