mirror of
https://github.com/Threnklyn/jira.git
synced 2026-05-18 20:23:28 +02:00
tweak auto-login so it does not print the standard jira login command output
This commit is contained in:
@@ -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{
|
||||
|
||||
@@ -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
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user