Skip to content

Commit

Permalink
rpk profile: detect profiles to delete before the auth is deleted
Browse files Browse the repository at this point in the history
If we're going to delete an auth, we WILL delete the profile on the next
run. Do it all in one run.
  • Loading branch information
twmb committed Mar 15, 2024
1 parent 8f4c23b commit d07a4c5
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/go/rpk/pkg/config/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,14 @@ func (c *Config) promptDeleteOldRpkYaml(fs afero.Fs) error {
}
var deleteAuthNames []string
var deleteProfileNames []string
containsAuth := func(name string) bool {
for _, a := range deleteAuthNames {
if a.Name == name {
return true
}
}
return false
}
for _, a := range c.rpkYamlActual.CloudAuths {
if a.Organization == "" || a.OrgID == "" {
deleteAuthNames = append(deleteAuthNames, a.Name)
Expand All @@ -1170,7 +1178,11 @@ func (c *Config) promptDeleteOldRpkYaml(fs afero.Fs) error {
}
for _, p := range c.rpkYamlActual.Profiles {
cc := &p.CloudCluster
if p.FromCloud && c.rpkYamlActual.LookupAuth(cc.AuthOrgID, cc.AuthKind) == nil {
if !p.FromCloud {
continue
}
a := c.rpkYamlActual.LookupAuth(cc.AuthOrgID, cc.AuthKind)
if a == nil || containsAuth(a.Name) {
deleteProfileNames = append(deleteProfileNames, p.Name)
continue
}
Expand Down

0 comments on commit d07a4c5

Please sign in to comment.