Skip to content

Commit

Permalink
Prompt for confirmation before revoking auth token
Browse files Browse the repository at this point in the history
  • Loading branch information
Piccirello committed Jan 20, 2020
1 parent a06a6a7 commit e45d344
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
11 changes: 2 additions & 9 deletions pkg/cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,7 @@ var loginRevokeCmd = &cobra.Command{
Your auth token will be immediately revoked.
This is an alias of the "logout" command.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
localConfig := configuration.LocalConfig(cmd)
silent := utils.GetBoolFlag(cmd, "silent")
updateConfig := !utils.GetBoolFlag(cmd, "no-update-config")
verifyTLS := utils.GetBool(localConfig.VerifyTLS.Value, true)
token := localConfig.Token.Value

revokeToken(localConfig.APIHost.Value, token, silent, verifyTLS, updateConfig)
},
Run: revokeToken,
}

func init() {
Expand All @@ -223,6 +215,7 @@ func init() {
loginRevokeCmd.Flags().Bool("silent", false, "do not output any text")
loginRevokeCmd.Flags().String("scope", "*", "the directory to scope your token to")
loginRevokeCmd.Flags().Bool("no-update-config", false, "do not remove the revoked token from the config file")
loginRevokeCmd.Flags().Bool("yes", false, "proceed without confirmation")
loginCmd.AddCommand(loginRevokeCmd)

rootCmd.AddCommand(loginCmd)
Expand Down
26 changes: 15 additions & 11 deletions pkg/cmd/logout.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,29 @@ var logoutCmd = &cobra.Command{
Your auth token will be immediately revoked.
This is an alias of the "login revoke" command.`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
localConfig := configuration.LocalConfig(cmd)
silent := utils.GetBoolFlag(cmd, "silent")
updateConfig := !utils.GetBoolFlag(cmd, "no-update-config")
verifyTLS := utils.GetBool(localConfig.VerifyTLS.Value, true)
token := localConfig.Token.Value

revokeToken(localConfig.APIHost.Value, token, silent, verifyTLS, updateConfig)
},
Run: revokeToken,
}

func revokeToken(host string, token string, silent bool, verifyTLS bool, updateConfig bool) {
func revokeToken(cmd *cobra.Command, args []string) {
localConfig := configuration.LocalConfig(cmd)
silent := utils.GetBoolFlag(cmd, "silent")
updateConfig := !utils.GetBoolFlag(cmd, "no-update-config")
verifyTLS := utils.GetBool(localConfig.VerifyTLS.Value, true)
yes := utils.GetBoolFlag(cmd, "yes")
token := localConfig.Token.Value

if token == "" {
if !silent {
fmt.Println("You must provide an auth token")
}
os.Exit(1)
}

_, err := http.RevokeAuthToken(host, verifyTLS, token)
if !yes && !utils.ConfirmationPrompt(fmt.Sprintf("Revoke auth token scoped to %s?", localConfig.Token.Scope), false) {
return
}

_, err := http.RevokeAuthToken(localConfig.APIHost.Value, verifyTLS, token)
if !err.IsNil() {
utils.HandleError(err.Unwrap(), err.Message)
}
Expand All @@ -76,5 +79,6 @@ func init() {
logoutCmd.Flags().Bool("silent", false, "do not output any text")
logoutCmd.Flags().String("scope", "*", "the directory to scope your token to")
logoutCmd.Flags().Bool("no-update-config", false, "do not remove the revoked token from the config file")
logoutCmd.Flags().Bool("yes", false, "proceed without confirmation")
rootCmd.AddCommand(logoutCmd)
}

0 comments on commit e45d344

Please sign in to comment.