tweak auto-login so it does not print the standard jira login command output

This commit is contained in:
Cory Bennett
2017-09-04 19:09:38 -07:00
parent c226077320
commit 49f6cdc54e
3 changed files with 23 additions and 23 deletions
-12
View File
@@ -2,7 +2,6 @@ package main
import (
"fmt"
"net/http"
"os"
"path/filepath"
"regexp"
@@ -92,17 +91,6 @@ func main() {
}
o := oreo.New().WithCookieFile(filepath.Join(jiracli.Homedir(), fig.ConfigDir, "cookies.js"))
o = o.WithPostCallback(
func(req *http.Request, resp *http.Response) (*http.Response, error) {
authUser := resp.Header.Get("X-Ausername")
if authUser == "" || authUser == "anonymous" {
// we are not logged in, so force login now by running the "login" command
app.Parse([]string{"login"})
return o.Do(req)
}
return resp, nil
},
)
registry := []jiracli.CommandRegistry{
jiracli.CommandRegistry{
+21
View File
@@ -89,6 +89,27 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re
return nil
})
o = o.WithPostCallback(
func(req *http.Request, resp *http.Response) (*http.Response, error) {
authUser := resp.Header.Get("X-Ausername")
if authUser == "" || authUser == "anonymous" {
// preserve the --quiet value, we need to temporarily disable it so
// the normal login output is surpressed
defer func(quiet bool) {
globals.Quiet.Value = quiet
}(globals.Quiet.Value)
globals.Quiet.Value = true
// we are not logged in, so force login now by running the "login" command
app.Parse([]string{"login"})
// rerun the original request
return o.Do(req)
}
return resp, nil
},
)
for _, command := range reg {
copy := command
commandFields := strings.Fields(copy.Command)
Executable → Regular
+2 -11
View File
@@ -1,14 +1,5 @@
#!/bin/sh
cat <<EOF
config:
stop: true
password-source: pass
EOF
if [ -z "$JIRACLOUD" ]; then
echo endpoint: http://localhost:8080
echo user: gojira
else
echo endpoint: https://go-jira.atlassian.net
echo user: gojira
fi
endpoint: https://go-jira.atlassian.net
user: gojira