Skip to content

Commit

Permalink
rpk profile: change MoveProfileToFront to **config.RpkProfile
Browse files Browse the repository at this point in the history
For the same reasons as the prior commit.

Only `rpk profile create` actually modify the profile fields after
the move, and only in `rpk profile create --from-cloud`.
  • Loading branch information
twmb committed Mar 18, 2024
1 parent 9dc5354 commit f56c688
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/profile/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func CreateFlow(
// * The user's prior profile was NOT the rpk-cloud profile
// * We are switching to the existing rpk-cloud profile and updating the values
fmt.Printf("Switched to existing %q profile and updated it to talk to cluster %q.\n", RpkCloudProfileName, o.FullName())
priorAuth, currentAuth := yAct.MoveProfileToFront(p)
priorAuth, currentAuth := yAct.MoveProfileToFront(&p)
config.MaybePrintAuthSwitchMessage(priorAuth, currentAuth)

case fromCloud != "" && name == RpkCloudProfileName:
Expand Down
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/profile/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func newRenameToCommand(fs afero.Fs, p *config.Params) *cobra.Command {
}
p.Name = to
y.CurrentProfile = to
priorAuth, currentAuth := y.MoveProfileToFront(p)
priorAuth, currentAuth := y.MoveProfileToFront(&p)
err = y.Write(fs)
out.MaybeDieErr(err)
fmt.Printf("Renamed current profile to %q.\n", to)
Expand Down
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/profile/use.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func newUseCommand(fs afero.Fs, p *config.Params) *cobra.Command {
if p == nil {
out.Die("profile %q does not exist", name)
}
priorAuth, currentAuth := y.MoveProfileToFront(p)
priorAuth, currentAuth := y.MoveProfileToFront(&p)

err = y.Write(fs)
out.MaybeDieErr(err)
Expand Down
15 changes: 8 additions & 7 deletions src/go/rpk/pkg/config/rpk_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,22 +200,23 @@ func (y *RpkYaml) PushProfile(p RpkProfile) (priorAuth, currentAuth *RpkCloudAut
}

// MoveProfileToFront moves the given profile to the front of the list.
func (y *RpkYaml) MoveProfileToFront(p *RpkProfile) (priorAuth, currentAuth *RpkCloudAuth) {
func (y *RpkYaml) MoveProfileToFront(p **RpkProfile) (priorAuth, currentAuth *RpkCloudAuth) {
priorAuth = y.CurrentAuth()
reordered := []RpkProfile{*p}
reordered := []RpkProfile{**p}
for i := range y.Profiles {
if &y.Profiles[i] == p {
if &y.Profiles[i] == *p {
continue
}
reordered = append(reordered, y.Profiles[i])
}
y.Profiles = reordered
y.CurrentProfile = p.Name
*p = &reordered[0]
y.CurrentProfile = (*p).Name

// If this is a cloud profile, we switch the auth as well.
if p.FromCloud {
y.CurrentCloudAuthOrgID = p.CloudCluster.AuthOrgID
y.CurrentCloudAuthKind = p.CloudCluster.AuthKind
if (*p).FromCloud {
y.CurrentCloudAuthOrgID = (*p).CloudCluster.AuthOrgID
y.CurrentCloudAuthKind = (*p).CloudCluster.AuthKind
}
currentAuth = y.CurrentAuth()
return priorAuth, currentAuth
Expand Down

0 comments on commit f56c688

Please sign in to comment.