Skip to content

Commit 47ee83b

Browse files
author
Maximilian Csuk
committed
Added option to fetch access token only
1 parent ccbe8d6 commit 47ee83b

2 files changed

Lines changed: 28 additions & 18 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ EOF
5656
Run query from file:
5757
~~~bash
5858
okql -o https://10.0.0.43:45455 --stdin < file.graphql
59+
~~~
60+
61+
Only fetch token:
62+
~~~bash
63+
okql -o https://10.0.0.43:45455 -u username -p password -k -i
5964
~~~

cmd/main.go

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ func main() {
3232
flag.StringVarP(&omnikeeperURL, "omnikeeper-url", "o", "", "Omnikeeper Base URL")
3333
flag.StringVarP(&graphqlQuery, "query", "q", "", "GraphQL Query")
3434
flag.BoolP("stdin", "s", false, "Read query from stdin")
35-
flag.BoolP("suppress-log-output", "i", false, "Suppress log-output, only output response from omnikeeper")
35+
flag.BoolP("get-token-only", "k", false, "Only login and return access token")
36+
flag.BoolP("suppress-log-output", "i", false, "Suppress log-output, only output response from omnikeeper (or token, if -k is set)")
3637
flag.Parse()
3738

3839
if !isFlagPassed("omnikeeper-url") {
@@ -91,26 +92,30 @@ func main() {
9192
log.Printf("Successfully logged in to %s", omnikeeperURL)
9293
}
9394

94-
var query string
95-
if isFlagPassed("query") {
96-
query = graphqlQuery
97-
} else if isFlagPassed("stdin") {
98-
// read from stdin
99-
bytes, err := ioutil.ReadAll(os.Stdin)
100-
if err != nil {
101-
log.Fatal("Error reading query from stdin", err)
95+
if isFlagPassed("get-token-only") {
96+
fmt.Print(token)
97+
} else {
98+
var query string
99+
if isFlagPassed("query") {
100+
query = graphqlQuery
101+
} else if isFlagPassed("stdin") {
102+
// read from stdin
103+
bytes, err := ioutil.ReadAll(os.Stdin)
104+
if err != nil {
105+
log.Fatal("Error reading query from stdin", err)
106+
}
107+
query = string(bytes)
102108
}
103-
query = string(bytes)
104-
}
105109

106-
if query != "" {
107-
graphqlURL := fmt.Sprintf("%s/graphql", omnikeeperURL)
108-
resp, err := executeGraphql(graphqlURL, token, query)
109-
if err != nil {
110-
log.Fatalf("Error executing graphql: %v", err)
111-
}
110+
if query != "" {
111+
graphqlURL := fmt.Sprintf("%s/graphql", omnikeeperURL)
112+
resp, err := executeGraphql(graphqlURL, token, query)
113+
if err != nil {
114+
log.Fatalf("Error executing graphql: %v", err)
115+
}
112116

113-
fmt.Print(resp)
117+
fmt.Print(resp)
118+
}
114119
}
115120
}
116121

0 commit comments

Comments
 (0)