pulumi/cmd/logout.go
Joe Duffy 36ab8f0087
Make config a little less error prone
As articulated in #714, the way config defaults to workspace-local
configuration is a bit error prone, especially now with the cloud
workflow being the default.  This change implements several improvements:

* First, --save defaults to true, so that configuration changes will
  persist into your project file.  If you want the old local workspace
  behavior, you can specify --save=false.

* Second, the order in which we applied configuration was a little
  strange, because workspace settings overwrote project settings.
  The order is changed now so that we take most specific over least
  specific configuration.  Per-stack is considered more specific
  than global and project settings are considered more specific
  than workspace.

* We now warn anytime workspace local configuration is used.  This
  is a developer scenario and can have subtle effects.  It is simply
  not safe to use in a team environment.  In fact, I lost an arm
  this morning due to workspace config... and that's why you always
  issue warnings for unsafe things.
2017-12-13 10:46:54 -08:00

46 lines
1.3 KiB
Go

// Copyright 2016-2017, Pulumi Corporation. All rights reserved.
package cmd
import (
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/pulumi/pulumi/pkg/backend/cloud"
"github.com/pulumi/pulumi/pkg/util/cmdutil"
)
func newLogoutCmd() *cobra.Command {
var all bool
var cloudURL string
cmd := &cobra.Command{
Use: "logout",
Short: "Log out of the Pulumi Cloud",
Long: "Log out of the Pulumi Cloud. Deletes stored credentials on the local machine.",
Args: cmdutil.NoArgs,
Run: cmdutil.RunFunc(func(cmd *cobra.Command, args []string) error {
// If --all is passed, log out of all clouds.
if all {
bes, err := cloud.CurrentBackends(cmdutil.Diag())
if err != nil {
return errors.Wrap(err, "could not read list of current clouds")
}
var result error
for _, be := range bes {
if err = cloud.Logout(be.CloudURL()); err != nil {
result = multierror.Append(result, err)
}
}
return result
}
// Otherwise, just log out of a single cloud (either the one specified, or the default).
return cloud.Logout(cloud.ValueOrDefaultURL(cloudURL))
}),
}
cmd.PersistentFlags().BoolVarP(&all, "all", "a", false, "Log out of all clouds")
cmd.PersistentFlags().StringVarP(&cloudURL, "cloud-url", "c", "", "A cloud URL to log out of")
return cmd
}