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