This repository has been archived by the owner on Jun 18, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
106 lines (92 loc) · 2.17 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
package main
import (
"fmt"
"github.com/rancher/api-filter-proxy/manager"
"github.com/rancher/api-filter-proxy/service"
"net/http"
"os"
log "github.com/Sirupsen/logrus"
"github.com/urfave/cli"
)
var VERSION = "v0.0.0-dev"
func beforeApp(c *cli.Context) error {
if c.GlobalBool("verbose") {
log.SetLevel(log.DebugLevel)
}
return nil
}
func main() {
app := cli.NewApp()
app.Name = "api-filter-proxy"
app.Version = VERSION
app.Usage = "Rancher api-filter-proxy supporting api specific filters"
app.Author = "Rancher Labs, Inc."
app.Email = ""
app.Before = beforeApp
app.Action = StartService
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "config",
Usage: fmt.Sprintf(
"Specify path to the config.json file containg API Filter configuration",
),
},
cli.StringFlag{
Name: "default-destination",
Usage: fmt.Sprintf(
"Specify the default destination URL for proxying any request paths not specified in config.json",
),
EnvVar: "DEFAULT_DESTINATION",
},
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: ":8091",
Usage: fmt.Sprintf(
"Address to listen to (TCP)",
),
},
}
app.Run(os.Args)
}
func StartService(c *cli.Context) {
if c.GlobalBool("debug") {
log.SetLevel(log.DebugLevel)
}
textFormatter := &log.TextFormatter{
FullTimestamp: true,
}
log.SetFormatter(textFormatter)
manager.SetEnv(c)
log.Info("Starting Rancher api-filter-proxy service %v", manager.ConfigFields)
router := service.NewRouter(manager.ConfigFields)
service.Wrapper = &service.MuxWrapper{router}
log.Info("Listening on ", c.GlobalString("listen"))
log.Fatal(http.ListenAndServe(c.GlobalString("listen"), service.Wrapper))
}