Skip to content

Commit

Permalink
remove: obsolete profile switch settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Jun 7, 2024
1 parent a25fffc commit 54e0063
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
2 changes: 1 addition & 1 deletion pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/profile/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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
}
19 changes: 0 additions & 19 deletions pkg/commands/sso/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 54e0063

Please sign in to comment.