forked from rancher/rancher-auth-service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
137 lines (124 loc) · 2.94 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package main
import (
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/rancher/rancher-auth-service/server"
"github.com/rancher/rancher-auth-service/service"
"github.com/urfave/cli"
"net/http"
"os"
)
func beforeApp(c *cli.Context) error {
if c.GlobalBool("verbose") {
log.SetLevel(log.DebugLevel)
}
return nil
}
func main() {
app := cli.NewApp()
app.Name = "rancher-auth-service"
app.Usage = "Rancher auth service supporting external auth providers"
app.Author = "Rancher Labs, Inc."
app.Email = ""
app.Before = beforeApp
app.Action = StartService
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "rsa-public-key-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing RSA public key",
),
},
cli.StringFlag{
Name: "rsa-private-key-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing RSA private key",
),
},
cli.StringFlag{
Name: "rsa-public-key-contents",
Usage: fmt.Sprintf(
"An alternative to rsa-public-key-file. Specify the contents of the key.",
),
EnvVar: "RSA_PUBLIC_KEY_CONTENTS",
},
cli.StringFlag{
Name: "rsa-private-key-contents",
Usage: fmt.Sprintf(
"An alternative to rsa-private-key-file. Specify the contents of the key.",
),
EnvVar: "RSA_PRIVATE_KEY_CONTENTS",
},
cli.StringFlag{
Name: "cattle-url",
Usage: fmt.Sprintf(
"Specify Cattle endpoint URL",
),
EnvVar: "CATTLE_URL",
},
cli.StringFlag{
Name: "cattle-access-key",
Usage: fmt.Sprintf(
"Specify Cattle access key",
),
EnvVar: "CATTLE_ACCESS_KEY",
},
cli.StringFlag{
Name: "cattle-secret-key",
Usage: fmt.Sprintf(
"Specify Cattle secret key",
),
EnvVar: "CATTLE_SECRET_KEY",
},
cli.BoolFlag{
Name: "debug",
Usage: fmt.Sprintf(
"Set true to get debug logs",
),
},
cli.StringFlag{
Name: "listen",
Value: ":8090",
Usage: fmt.Sprintf(
"Address to listen to (TCP)",
),
},
cli.StringFlag{
Name: "self-signed-key-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing a self signed certificate's key",
),
},
cli.StringFlag{
Name: "self-signed-cert-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing a self signed certificate",
),
},
cli.StringFlag{
Name: "idp-metadata-file",
Usage: fmt.Sprintf(
"Specify the path to the file containing SAML/Shibboleth IDP Metadata file",
),
},
}
app.Run(os.Args)
}
func StartService(c *cli.Context) {
server.SetEnv(c)
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
}
textFormatter := &log.TextFormatter{
FullTimestamp: true,
}
log.SetFormatter(textFormatter)
log.Info("Starting Rancher Auth service")
err := server.Reload()
if err != nil {
log.Fatalf("Failed to reload the auth provider from db on start: %v", err)
}
router := service.NewRouter()
log.Info("Listening on ", c.GlobalString("listen"))
log.Fatal(http.ListenAndServe(c.GlobalString("listen"), router))
}