Skip to content

Commit

Permalink
Fix context override writes
Browse files Browse the repository at this point in the history
When using context override, values for the actual current context
could be overwritten with the override context's values.
  • Loading branch information
gabrieljackson committed Jan 7, 2025
1 parent 4985691 commit 1c6d63d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions cmd/cloud/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ var rootCmd = &cobra.Command{
return
}

contextOverride, _ := cmd.Flags().GetString("context")
currentContextName := contexts.CurrentContext
currentContext := contexts.Current()

var currentContext *clicontext.CLIContext
contextOverride, _ := cmd.Flags().GetString("context")
if contextOverride != "" {
currentContextName = contextOverride
currentContext = contexts.Get(contextOverride)
if currentContext == nil {
logger.Fatalf("Context '%s' does not exist.", contextOverride)
return
}
} else {
currentContext = contexts.Current()
}

if currentContext == nil {
Expand All @@ -89,7 +89,7 @@ var rootCmd = &cobra.Command{
}

// Update disk copy of context with new auth data if any
err = contexts.UpdateContext(contexts.CurrentContext, authData, currentContext.ClientID, currentContext.OrgURL, currentContext.Alias, currentContext.ServerURL, currentContext.ConfirmationRequired)
err = contexts.UpdateContext(currentContextName, authData, currentContext.ClientID, currentContext.OrgURL, currentContext.Alias, currentContext.ServerURL, currentContext.ConfirmationRequired)
if err != nil {
logger.WithError(err).Fatal("Failed to update context with new auth data.")
}
Expand Down

0 comments on commit 1c6d63d

Please sign in to comment.