Skip to content

Commit

Permalink
Tidy up fastly configure text output and ensure secrets aren't rend…
Browse files Browse the repository at this point in the history
…ered. (#30)
  • Loading branch information
phamann authored Apr 22, 2020
1 parent c77616b commit 6de55d0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
18 changes: 12 additions & 6 deletions pkg/configure/configure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ func TestConfigure(t *testing.T) {
},
wantOutput: []string{
"Fastly API endpoint (via --endpoint): http://local.dev",
"Fastly API token (via --token): abcdef",
"Fastly API token provided via --token",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -77,8 +78,9 @@ func TestConfigure(t *testing.T) {
},
wantOutput: []string{
"Fastly API endpoint (via --endpoint): http://staging.dev",
"Fastly API token (via --token): abcdef",
"Fastly API token provided via --token",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -97,8 +99,9 @@ func TestConfigure(t *testing.T) {
GetUserFn: goodUser,
},
wantOutput: []string{
"Fastly API token (via --token): abcdef",
"Fastly API token provided via --token",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -122,6 +125,7 @@ func TestConfigure(t *testing.T) {
"https://manage.fastly.com/account/personal/tokens",
"Fastly API token: ",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -133,16 +137,17 @@ func TestConfigure(t *testing.T) {
},
},
{
name: "token from flag",
name: "token from environment",
args: []string{"configure"},
env: config.Environment{Token: "hello"},
api: mock.API{
GetTokenSelfFn: goodToken,
GetUserFn: goodUser,
},
wantOutput: []string{
"Fastly API token (via FASTLY_API_TOKEN): hello",
"Fastly API token provided via FASTLY_API_TOKEN",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -167,6 +172,7 @@ func TestConfigure(t *testing.T) {
"https://manage.fastly.com/account/personal/tokens",
"Fastly API token: ",
"Validating token...",
"Persisting configuration...",
"Configured the Fastly CLI",
"You can find your configuration file at",
},
Expand All @@ -185,7 +191,7 @@ func TestConfigure(t *testing.T) {
GetUserFn: badUser,
},
wantOutput: []string{
"Fastly API token (via --token): abcdef",
"Fastly API token provided via --token",
"Validating token...",
},
wantError: "error validating token: bad token",
Expand Down
18 changes: 13 additions & 5 deletions pkg/configure/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
token, source := c.Globals.Token()
switch source { // TODO(pb): this can be duplicate output if --verbose is passed
case config.SourceFlag:
text.Output(out, "Fastly API token (via --token): %s", token)
text.Output(out, "Fastly API token provided via --token")
case config.SourceEnvironment:
text.Output(out, "Fastly API token (via %s): %s", config.EnvVarToken, token)
text.Output(out, "Fastly API token provided via %s", config.EnvVarToken)
default:
text.Output(out, `
An API token is used to authenticate requests to the Fastly API.
Expand All @@ -70,10 +70,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
if err != nil {
return err
}
text.Break(out)
}
text.Break(out)

text.Output(out, "Validating token...")
text.Break(out)
progress := text.NewQuietProgress(out)
progress.Step("Validating token...")

client, err := c.clientFactory(token, endpoint)
if err != nil {
Expand All @@ -90,6 +92,8 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
return fmt.Errorf("error fetching token user: %w", err)
}

progress.Step("Persisting configuration...")

// Set everything in the File struct based on provided user input.
c.Globals.File.Token = token
c.Globals.File.Email = user.Login
Expand Down Expand Up @@ -117,8 +121,12 @@ func (c *RootCommand) Exec(in io.Reader, out io.Writer) error {
// Escape any spaces in filepath before output.
filePath := strings.ReplaceAll(c.configFilePath, " ", `\ `)

progress.Done()
text.Break(out)
text.Description(out, "You can find your configuration file at", filePath)

text.Success(out, "Configured the Fastly CLI")
fmt.Fprintf(out, "\nYou can find your configuration file at\n\n %s\n\n", filePath)

return nil
}

Expand Down

0 comments on commit 6de55d0

Please sign in to comment.