-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 indices browsing - getting there
- Loading branch information
Showing
14 changed files
with
396 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package logout | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/vulncheck-oss/cli/pkg/config" | ||
"github.com/vulncheck-oss/cli/pkg/session" | ||
"github.com/vulncheck-oss/cli/pkg/ui" | ||
) | ||
|
||
func Command() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "logout", | ||
Short: "Invalidate and remove your current authentication token", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
if !config.HasConfig() { | ||
return ui.Danger("No configuration file found") | ||
} | ||
|
||
if !config.HasToken() { | ||
return ui.Danger("No valid token was found") | ||
} | ||
|
||
_, err := session.InvalidateToken(config.Token()) | ||
if err == nil { | ||
if err := config.RemoveToken(); err != nil { | ||
return ui.Danger("Failed to remove token") | ||
} | ||
return ui.Success("Token successfully invalidated") | ||
} | ||
if err.Error() == session.ErrorUnauthorized { | ||
if err := config.RemoveToken(); err != nil { | ||
return ui.Danger("Token was invalid, removing from config") | ||
} | ||
} | ||
|
||
return err | ||
}, | ||
} | ||
|
||
return cmd | ||
} |
Oops, something went wrong.