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
52 changes: 38 additions & 14 deletions internal/cli/auth/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package auth

import (
"context"
"fmt"
"io"
"net/http"

Expand All @@ -34,6 +35,7 @@ import (

type ConfigDeleter interface {
Delete() error
Name() string
SetAccessToken(string)
SetRefreshToken(string)
SetProjectID(string)
Expand All @@ -51,6 +53,7 @@ type Revoker interface {

type logoutOpts struct {
*cli.DeleteOpts
cli.DefaultSetterOpts
OutWriter io.Writer
config ConfigDeleter
flow Revoker
Expand All @@ -66,34 +69,40 @@ func (opts *logoutOpts) initFlow() error {
}

func (opts *logoutOpts) Run(ctx context.Context) error {
if !opts.Confirm {
return nil
}

switch opts.config.AuthType() {
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.ServiceAccount, config.UserAccount:
if _, err := opts.flow.RevokeToken(ctx, config.RefreshToken(), "refresh_token"); err != nil {
return err
}

opts.config.SetAccessToken("")
opts.config.SetRefreshToken("")
case config.APIKeys:
opts.config.SetPublicAPIKey("")
opts.config.SetPrivateAPIKey("")
case config.NoAuth, "": // Just clear any potential leftover credentials
opts.config.SetPublicAPIKey("")
opts.config.SetPrivateAPIKey("")
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 @@ -103,18 +112,30 @@ func LogoutBuilder() *cobra.Command {
atlas auth logout
`,
PreRunE: func(cmd *cobra.Command, _ []string) error {
// Check if profile was provided and if it exists
profile := cmd.Flag(flag.Profile).Value.String()
if profile != "" && !config.Exists(profile) {
return fmt.Errorf("profile %v does not exist", profile)
}
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 +146,9 @@ func LogoutBuilder() *cobra.Command {
}

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

opts.Entry = entry
Expand Down
Loading
Loading