From 54e00635d1eaa1b69c0220f72b26ce7dafc6f40d Mon Sep 17 00:00:00 2001 From: Integralist Date: Fri, 7 Jun 2024 10:28:30 +0100 Subject: [PATCH] remove: obsolete profile switch settings --- pkg/commands/commands.go | 2 +- pkg/commands/profile/switch.go | 8 ++++---- pkg/commands/sso/root.go | 19 ------------------- 3 files changed, 5 insertions(+), 24 deletions(-) diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index 2514e9437..ab305f5c9 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -354,7 +354,7 @@ func Define( profileCreate := profile.NewCreateCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot) profileDelete := profile.NewDeleteCommand(profileCmdRoot.CmdClause, data) profileList := profile.NewListCommand(profileCmdRoot.CmdClause, data) - profileSwitch := profile.NewSwitchCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot) + profileSwitch := profile.NewSwitchCommand(profileCmdRoot.CmdClause, data) profileToken := profile.NewTokenCommand(profileCmdRoot.CmdClause, data) profileUpdate := profile.NewUpdateCommand(profileCmdRoot.CmdClause, data, ssoCmdRoot) purgeCmdRoot := purge.NewRootCommand(app, data) diff --git a/pkg/commands/profile/switch.go b/pkg/commands/profile/switch.go index 60bf79aef..903f14efd 100644 --- a/pkg/commands/profile/switch.go +++ b/pkg/commands/profile/switch.go @@ -6,7 +6,6 @@ import ( "io" "github.com/fastly/cli/pkg/argparser" - "github.com/fastly/cli/pkg/commands/sso" "github.com/fastly/cli/pkg/global" "github.com/fastly/cli/pkg/profile" "github.com/fastly/cli/pkg/text" @@ -17,14 +16,12 @@ type SwitchCommand struct { argparser.Base profile string - ssoCmd *sso.RootCommand } // NewSwitchCommand returns a usable command registered under the parent. -func NewSwitchCommand(parent argparser.Registerer, g *global.Data, ssoCmd *sso.RootCommand) *SwitchCommand { +func NewSwitchCommand(parent argparser.Registerer, g *global.Data) *SwitchCommand { var c SwitchCommand c.Globals = g - c.ssoCmd = ssoCmd c.CmdClause = parent.Command("switch", "Switch user profile") c.CmdClause.Arg("profile", "Profile to switch to").Short('p').Required().StringVar(&c.profile) return &c @@ -51,6 +48,9 @@ func (c *SwitchCommand) Exec(_ io.Reader, out io.Writer) error { return fmt.Errorf("error saving config file: %w", err) } + if c.Globals.Verbose() { + text.Break(out) + } text.Success(out, "Profile switched to '%s'", c.profile) return nil } diff --git a/pkg/commands/sso/root.go b/pkg/commands/sso/root.go index aa6bbab93..77b30e2c3 100644 --- a/pkg/commands/sso/root.go +++ b/pkg/commands/sso/root.go @@ -154,10 +154,6 @@ const ( // ProfileUpdate indicates we need to update a profile using details passed in // either from the `sso` or `profile update` command. ProfileUpdate - - // ProfileSwitch indicates we need to re-authenticate and switch profiles. - // Triggered by user invoking `fastly profile switch` with an SSO-based profile. - ProfileSwitch ) // identifyProfileAndFlow identifies the profile and the specific workflow. @@ -212,11 +208,6 @@ func (c *RootCommand) processProfiles(ar auth.AuthorizationResult) error { if err != nil { return fmt.Errorf("failed to update profile: %w", err) } - case ProfileSwitch: - err := c.processSwitchProfile(ar, profileName) - if err != nil { - return fmt.Errorf("failed to switch profile: %w", err) - } } if err := c.Globals.Config.Write(c.Globals.ConfigPath); err != nil { @@ -261,16 +252,6 @@ func (c *RootCommand) processUpdateProfile(ar auth.AuthorizationResult, profileN return nil } -// processSwitchProfile handles updating a profile. -func (c *RootCommand) processSwitchProfile(ar auth.AuthorizationResult, profileName string) error { - ps, err := editProfile(profileName, c.ProfileDefault, c.Globals.Config.Profiles, ar) - if err != nil { - return err - } - c.Globals.Config.Profiles = ps - return nil -} - // IMPORTANT: Mutates the config.Profiles map type. // We need to return the modified type so it can be safely reassigned. func createNewProfile(profileName string, makeDefault bool, p config.Profiles, ar auth.AuthorizationResult) config.Profiles {