mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-19 04:33:28 +02:00
add logout command
modify password prompt to echo masked password
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"net/url"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
+25
-5
@@ -4,9 +4,8 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"github.com/howeyc/gopass"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
"os"
|
||||
"strings"
|
||||
@@ -19,9 +18,12 @@ func (c *Cli) CmdLogin() error {
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
user, _ := c.opts["user"].(string)
|
||||
|
||||
fmt.Printf("Enter Password for %s: ", user)
|
||||
pwbytes, _ := terminal.ReadPassword(int(os.Stdin.Fd()))
|
||||
passwd := string(pwbytes)
|
||||
fmt.Printf("Jira Password [%s]: ", user)
|
||||
pw, err := gopass.GetPasswdMasked()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
passwd := string(pw)
|
||||
|
||||
req.SetBasicAuth(user, passwd)
|
||||
log.Infof("%s %s", req.Method, req.URL.String())
|
||||
@@ -57,6 +59,24 @@ func (c *Cli) CmdLogin() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cli) CmdLogout() error {
|
||||
uri := fmt.Sprintf("%s/rest/auth/1/session", c.endpoint)
|
||||
req, _ := http.NewRequest("DELETE", uri, nil)
|
||||
if resp, err := c.makeRequest(req); err != nil {
|
||||
return err
|
||||
} else {
|
||||
if resp.StatusCode == 401 || resp.StatusCode == 204 {
|
||||
// 401 == no active session
|
||||
// 204 == successfully logged out
|
||||
} else {
|
||||
err := fmt.Errorf("Failed to Logout: %s", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
log.Notice("OK")
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cli) CmdFields() error {
|
||||
log.Debugf("fields called")
|
||||
uri := fmt.Sprintf("%s/rest/api/2/field", c.endpoint)
|
||||
|
||||
@@ -84,6 +84,7 @@ Usage:
|
||||
jira export-templates [-d DIR] [-t template]
|
||||
jira (b|browse) ISSUE
|
||||
jira login
|
||||
jira logout
|
||||
jira request [-M METHOD] URI [DATA]
|
||||
jira ISSUE
|
||||
|
||||
@@ -166,6 +167,7 @@ Command Options:
|
||||
"export-templates": "export-templates",
|
||||
"browse": "browse",
|
||||
"login": "login",
|
||||
"logout": "logout",
|
||||
"req": "request",
|
||||
"request": "request",
|
||||
"vote": "vote",
|
||||
@@ -313,6 +315,8 @@ Command Options:
|
||||
switch command {
|
||||
case "login":
|
||||
err = c.CmdLogin()
|
||||
case "logout":
|
||||
err = c.CmdLogout()
|
||||
case "fields":
|
||||
err = c.CmdFields()
|
||||
case "list":
|
||||
|
||||
Reference in New Issue
Block a user