This repository has been archived by the owner on Jan 6, 2024. It is now read-only.
/
main.go
61 lines (51 loc) · 1.5 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"log"
"os"
"github.com/juju/loggo"
)
type flags struct {
Username string
Password string
Path string
LogLevel string
}
func main() {
flags := parseFlags()
makeRequest := flags.Username != ""
if flags.LogLevel != "" {
loggo.ConfigureLoggers("<root>=" + flags.LogLevel)
}
logger := log.New(os.Stdout, "", log.Ldate|log.Ltime)
logSetup(logger)
s := setupAuthService(logger)
t := setupTargetService(logger, s, makeRequest)
if makeRequest {
creds := Credentials{Username: flags.Username, Password: flags.Password}
makeTestRequest(logger, creds, t.Endpoint())
}
}
func parseFlags() (f flags) {
flag.StringVar(&f.Username, "auth-username", "", "authentication username")
flag.StringVar(&f.Password, "auth-password", "", "authentication password")
flag.StringVar(&f.Path, "path", "/", "request path")
flag.StringVar(&f.LogLevel, "loglevel", "", "log level")
flag.Parse()
return
}
func logSetup(logger *log.Logger) {
logger.Printf("valid credentials: %q", sampleCredentials)
logger.Printf("user/group mapping: %q", sampleGroups)
logger.Printf("required groups: %q", requiredGroups)
logger.Printf("macaroon validity: %q", macaroonValidity)
}
func makeTestRequest(logger *log.Logger, creds Credentials, path string) {
logger.Printf("cli - req: GET %s %q", path, creds)
statusCode, content, err := clientRequest("GET", path, creds)
if err == nil {
logger.Printf("cli - resp: %d - %s", statusCode, content)
} else {
logger.Printf("cli - err: %v", err)
}
}