diff --git a/cli.go b/cli.go index 88af2c7..93c3d76 100644 --- a/cli.go +++ b/cli.go @@ -15,6 +15,7 @@ import ( "net/url" "os" "os/exec" + "path" "path/filepath" "runtime" "strings" diff --git a/commands.go b/commands.go index 3b706fc..a9103be 100644 --- a/commands.go +++ b/commands.go @@ -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) diff --git a/main/main.go b/main/main.go index d049098..0a76f00 100644 --- a/main/main.go +++ b/main/main.go @@ -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":