Skip to content

Commit 4f86396

Browse files
authored
[CDTOOL-1304] Ensure that the Fastly Auth type commands respect the --quiet Flag (#1710)
### Change summary This PR corrects a bug where the `fastly profile`, `fastly sso` and `fastly auth-token` commands were not checking the the `--quiet` flag. Fixes issue #1708. All Submissions: * [x] Have you followed the guidelines in our Contributing document? * [x] Have you checked to ensure there aren't other open [Pull Requests](https://github.com/fastly/cli/pulls) for the same update/change? <!-- You can erase any parts of this template not applicable to your Pull Request. --> ### New Feature Submissions: * [x] Does your submission pass tests? ``` make test TEST_ARGS="-run TestProfileToken ./pkg/commands/profile" ok github.com/fastly/cli/pkg/commands/profile 1.171s ``` ### Changes to Core Features: * [x] Have you written new tests for your core changes, as applicable? * [x] Have you successfully run tests with your changes locally?
1 parent 8e2e43e commit 4f86396

13 files changed

Lines changed: 96 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
### Bug Fixes:
88

9+
- fix(auth): `fastly profile`, `fastly sso` and `fastly auth-token` commands now correctly respect the `--quiet` flag [#1710](https://github.com/fastly/cli/pull/1710)
10+
11+
912
### Enhancements:
1013

1114
- feat(vcl/snippet): add support for the '--content' flag, allowing for the raw output of VCL. [#1706](https://github.com/fastly/cli/pull/1706)

pkg/commands/authtoken/create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@ type CreateCommand struct {
6363

6464
// Exec invokes the application logic for the command.
6565
func (c *CreateCommand) Exec(_ io.Reader, out io.Writer) error {
66-
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
66+
if !c.Globals.Flags.Quiet {
67+
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
68+
}
6769

6870
input := c.constructInput()
6971

pkg/commands/authtoken/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ type DeleteCommand struct {
4141

4242
// Exec invokes the application logic for the command.
4343
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
44-
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
44+
if !c.Globals.Flags.Quiet {
45+
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
46+
}
4547

4648
if !c.current && c.file == "" && c.id == "" {
4749
return fmt.Errorf("error parsing arguments: must provide either the --current, --file or --id flag")

pkg/commands/authtoken/describe.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ type DescribeCommand struct {
3535

3636
// Exec invokes the application logic for the command.
3737
func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
38-
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
38+
if !c.Globals.Flags.Quiet {
39+
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
40+
}
3941

4042
if c.Globals.Verbose() && c.JSONOutput.Enabled {
4143
return fsterr.ErrInvalidVerboseJSONCombo

pkg/commands/authtoken/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ type ListCommand struct {
4343

4444
// Exec invokes the application logic for the command.
4545
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
46-
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
46+
if !c.Globals.Flags.Quiet {
47+
text.Deprecated(out, "The 'auth-token' command tree will be removed in a future release. Use the Fastly API directly to manage API tokens.\n\n")
48+
}
4749

4850
if c.Globals.Verbose() && c.JSONOutput.Enabled {
4951
return fsterr.ErrInvalidVerboseJSONCombo

pkg/commands/profile/create.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ func NewCreateCommand(parent argparser.Registerer, g *global.Data) *CreateComman
3737

3838
// Exec implements the command interface.
3939
func (c *CreateCommand) Exec(in io.Reader, out io.Writer) (err error) {
40-
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth login' or 'fastly auth add' instead.\n\n")
40+
if !c.Globals.Flags.Quiet {
41+
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth login' or 'fastly auth add' instead.\n\n")
42+
}
4143

4244
if c.Globals.Verbose() {
4345
text.Break(out)

pkg/commands/profile/delete.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ func NewDeleteCommand(parent argparser.Registerer, g *global.Data) *DeleteComman
2727

2828
// Exec invokes the application logic for the command.
2929
func (c *DeleteCommand) Exec(_ io.Reader, out io.Writer) error {
30-
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth delete' instead.\n\n")
30+
if !c.Globals.Flags.Quiet {
31+
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth delete' instead.\n\n")
32+
}
3133

3234
if !c.Globals.Config.DeleteAuthToken(c.profile) {
3335
return fmt.Errorf("the specified profile does not exist")

pkg/commands/profile/list.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ func NewListCommand(parent argparser.Registerer, g *global.Data) *ListCommand {
2828

2929
// Exec invokes the application logic for the command.
3030
func (c *ListCommand) Exec(_ io.Reader, out io.Writer) error {
31-
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth list' instead.\n\n")
31+
if !c.Globals.Flags.Quiet {
32+
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth list' instead.\n\n")
33+
}
3234

3335
if c.Globals.Verbose() && c.JSONOutput.Enabled {
3436
return fsterr.ErrInvalidVerboseJSONCombo

pkg/commands/profile/profile_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,66 @@ func TestProfileToken(t *testing.T) {
335335
longTTLExpireAt := now.Add(60 * time.Second)
336336

337337
scenarios := []testutil.CLIScenario{
338+
{
339+
Name: "validate deprecation warning appears by default",
340+
Env: &testutil.EnvConfig{
341+
Opts: &testutil.EnvOpts{
342+
Copy: []testutil.FileIO{
343+
{
344+
Src: filepath.Join("testdata", "config.toml"),
345+
Dst: "config.toml",
346+
},
347+
},
348+
},
349+
EditScenario: func(scenario *testutil.CLIScenario, rootdir string) {
350+
scenario.ConfigPath = filepath.Join(rootdir, "config.toml")
351+
},
352+
},
353+
ConfigFile: &config.File{
354+
Auth: config.Auth{
355+
Default: "foo",
356+
Tokens: config.AuthTokens{
357+
"foo": &config.AuthToken{
358+
Type: config.AuthTokenTypeStatic,
359+
Token: "123",
360+
Email: "foo@example.com",
361+
},
362+
},
363+
},
364+
},
365+
WantOutputs: []string{"DEPRECATED", "This command will be removed", "123"},
366+
},
367+
{
368+
Name: "validate --quiet suppresses deprecation warning",
369+
Args: "--quiet",
370+
Env: &testutil.EnvConfig{
371+
Opts: &testutil.EnvOpts{
372+
Copy: []testutil.FileIO{
373+
{
374+
Src: filepath.Join("testdata", "config.toml"),
375+
Dst: "config.toml",
376+
},
377+
},
378+
},
379+
EditScenario: func(scenario *testutil.CLIScenario, rootdir string) {
380+
scenario.ConfigPath = filepath.Join(rootdir, "config.toml")
381+
},
382+
},
383+
ConfigFile: &config.File{
384+
Auth: config.Auth{
385+
Default: "foo",
386+
Tokens: config.AuthTokens{
387+
"foo": &config.AuthToken{
388+
Type: config.AuthTokenTypeStatic,
389+
Token: "123",
390+
Email: "foo@example.com",
391+
},
392+
},
393+
},
394+
},
395+
WantOutput: "123",
396+
DontWantOutputs: []string{"DEPRECATED", "This command will be removed"},
397+
},
338398
{
339399
Name: "validate the active profile non-SSO token is displayed by default",
340400
Env: &testutil.EnvConfig{

pkg/commands/profile/switch.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ func NewSwitchCommand(parent argparser.Registerer, g *global.Data) *SwitchComman
3030

3131
// Exec invokes the application logic for the command.
3232
func (c *SwitchCommand) Exec(in io.Reader, out io.Writer) error {
33-
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth use' instead.\n\n")
33+
if !c.Globals.Flags.Quiet {
34+
text.Deprecated(out, "This command will be removed in a future release. Use 'fastly auth use' instead.\n\n")
35+
}
3436

3537
at := c.Globals.Config.GetAuthToken(c.profile)
3638
if at == nil {

0 commit comments

Comments
 (0)