get-bridge/truss-cli

Secrets Errors After Editing Without Arguments

DrydenDev opened this issue · 0 comments

When editing secrets and you don't provide an argument on the command-line, the follow-up attempt to push secrets causes the app to panic and error-out.

Expected Behavior

Run truss secrets edit and answer which configuration when prompted. Edit your secrets. After writing the file, it will prompt you to push the secrets and you can confirm or deny.

Current Behavior

Run truss secrets edit and answer which configuration when prompted. Edit your secrets. After writing the file, it will cause an error:

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
github.com/instructure-bridge/truss-cli/cmd.glob..func5(0x34cd7c0, 0xc00027b6c0, 0x0, 0x2, 0x0, 0x0)
	/home/runner/work/truss-cli/truss-cli/cmd/secretsEdit.go:34 +0x3b0
github.com/spf13/cobra.(*Command).execute(0x34cd7c0, 0xc00027b6a0, 0x2, 0x2, 0x34cd7c0, 0xc00027b6a0)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:842 +0x453
github.com/spf13/cobra.(*Command).ExecuteC(0x34cf9e0, 0x100586f, 0xc0000480b8, 0x0)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950 +0x349
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/instructure-bridge/truss-cli/cmd.Execute()
	/home/runner/work/truss-cli/truss-cli/cmd/root.go:28 +0x31
main.main()
	/home/runner/work/truss-cli/truss-cli/main.go:6 +0x20

It appears this is because it is trying to use the environment from the command-line, but if none was provided and was instead provided from the prompt, this causes an error.

Possible Solution

Just need to use the same environment source that the editor uses.

Steps to Reproduce

  1. Run truss secrets edit
  2. Answer the prompt to select an environment
  3. :wq the file (don't need any changes)
  4. Observe the error