Skip to content
Merged
103 changes: 0 additions & 103 deletions docs/command/atlas-config-delete.txt

This file was deleted.

2 changes: 0 additions & 2 deletions docs/command/atlas-config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Inherited Options
Related Commands
----------------

* :ref:`atlas-config-delete` - Delete a profile.
* :ref:`atlas-config-describe` - Return the profile you specify.
* :ref:`atlas-config-edit` - Opens the config file with the default text editor.
* :ref:`atlas-config-list` - Return a list of available profiles by name.
Expand All @@ -67,7 +66,6 @@ Related Commands
.. toctree::
:titlesonly:

delete </command/atlas-config-delete>
describe </command/atlas-config-describe>
edit </command/atlas-config-edit>
list </command/atlas-config-list>
Expand Down
34 changes: 23 additions & 11 deletions internal/cli/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,34 @@ func (opts *logoutOpts) Run(ctx context.Context) error {
case config.APIKeys:
opts.config.SetPublicAPIKey("")
opts.config.SetPrivateAPIKey("")
case config.ServiceAccount:
fallthrough
case config.UserAccount:
// revoking a refresh token revokes the access token
case config.NoAuth:
// Handle profiles with no authentication configured
// Just clear any potential leftover credentials
opts.config.SetPublicAPIKey("")
opts.config.SetPrivateAPIKey("")
opts.config.SetAccessToken("")
opts.config.SetRefreshToken("")
case config.ServiceAccount, config.UserAccount:
if _, err := opts.flow.RevokeToken(ctx, config.RefreshToken(), "refresh_token"); err != nil {
return err
}

opts.config.SetAccessToken("")
opts.config.SetRefreshToken("")
}

opts.config.SetProjectID("")
opts.config.SetOrgID("")

if !opts.keepConfig {
return opts.Delete(opts.config.Delete)
}

opts.config.SetProjectID("")
opts.config.SetOrgID("")
return opts.config.Save()
}

func LogoutBuilder() *cobra.Command {
opts := &logoutOpts{
DeleteOpts: cli.NewDeleteOpts("Successfully logged out of account %s\n", " "),
DeleteOpts: cli.NewDeleteOpts("Successfully logged out of '%s'\n", " "),
}

cmd := &cobra.Command{
Expand All @@ -105,16 +109,21 @@ func LogoutBuilder() *cobra.Command {
PreRunE: func(cmd *cobra.Command, _ []string) error {
opts.OutWriter = cmd.OutOrStdout()
opts.config = config.Default()
return opts.initFlow()
// Only initialize OAuth flow if we have OAuth-based auth
if opts.config.AuthType() == config.UserAccount || opts.config.AuthType() == config.ServiceAccount {
return opts.initFlow()
}
return nil
},
RunE: func(cmd *cobra.Command, _ []string) error {
var message, entry string
var err error

if opts.config.AuthType() == config.APIKeys {
switch opts.config.AuthType() {
case config.APIKeys:
entry = opts.config.PublicAPIKey()
message = "Are you sure you want to log out of account with public API key %s?"
} else {
case config.ServiceAccount, config.UserAccount:
entry, err = config.AccessTokenSubject()
if err != nil {
return err
Expand All @@ -125,6 +134,9 @@ func LogoutBuilder() *cobra.Command {
}

message = "Are you sure you want to log out of account %s?"
case config.NoAuth:
entry = config.Name()
message = "Are you sure you want to clear profile %s?"
}

opts.Entry = entry
Expand Down
Loading
Loading