Skip to content

Commit 348c2fc

Browse files
authored
sso_proxy: implement go-micro config (#279)
1 parent a3c8a2a commit 348c2fc

15 files changed

+1349
-528
lines changed

cmd/sso-proxy/main.go

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import (
66
"os"
77
"time"
88

9-
"github.com/kelseyhightower/envconfig"
10-
119
"github.com/buzzfeed/sso/internal/pkg/httpserver"
1210
"github.com/buzzfeed/sso/internal/pkg/logging"
1311
"github.com/buzzfeed/sso/internal/proxy"
@@ -21,45 +19,61 @@ func init() {
2119
func main() {
2220
logger := logging.NewLogEntry()
2321

24-
opts := proxy.NewOptions()
25-
err := envconfig.Process("", opts)
22+
config, err := proxy.LoadConfig()
23+
if err != nil {
24+
logger.Error(err, "error loading in config from env vars")
25+
os.Exit(1)
26+
}
27+
28+
err = config.Validate()
2629
if err != nil {
27-
logger.Error(err, "error parsing env vars into options")
30+
logger.Error(err, "error validating config")
2831
os.Exit(1)
2932
}
3033

31-
err = opts.Validate()
34+
sc := config.MetricsConfig.StatsdConfig
35+
statsdClient, err := proxy.NewStatsdClient(sc.Host, sc.Port)
3236
if err != nil {
33-
logger.Error(err, "error validating options")
37+
logger.Error(err, "error creating statsd client")
3438
os.Exit(1)
3539
}
3640

3741
// we setup a runtime collector to emit stats
3842
go func() {
39-
c := collector.New(opts.StatsdClient, 30*time.Second)
43+
c := collector.New(statsdClient, 30*time.Second)
4044
c.Run()
4145
}()
4246

43-
ssoProxy, err := proxy.New(opts)
47+
err = proxy.SetUpstreamConfigs(
48+
&config.UpstreamConfigs,
49+
config.SessionConfig.CookieConfig,
50+
&config.ServerConfig,
51+
)
52+
if err != nil {
53+
logger.Error(err, "error setting upstream configs")
54+
os.Exit(1)
55+
}
56+
57+
ssoProxy, err := proxy.New(config, statsdClient)
4458
if err != nil {
4559
logger.Error(err, "error creating sso proxy")
4660
os.Exit(1)
4761
}
4862

4963
loggingHandler := proxy.NewLoggingHandler(os.Stdout,
5064
ssoProxy,
51-
opts.RequestLogging,
52-
opts.StatsdClient,
65+
config.LoggingConfig,
66+
statsdClient,
5367
)
5468

5569
s := &http.Server{
56-
Addr: fmt.Sprintf(":%d", opts.Port),
57-
ReadTimeout: opts.TCPReadTimeout,
58-
WriteTimeout: opts.TCPWriteTimeout,
70+
Addr: fmt.Sprintf(":%d", config.ServerConfig.Port),
71+
ReadTimeout: config.ServerConfig.TimeoutConfig.Read,
72+
WriteTimeout: config.ServerConfig.TimeoutConfig.Write,
5973
Handler: loggingHandler,
6074
}
6175

62-
if err := httpserver.Run(s, opts.ShutdownTimeout, logger); err != nil {
76+
if err := httpserver.Run(s, config.ServerConfig.TimeoutConfig.Shutdown, logger); err != nil {
6377
logger.WithError(err).Fatal("error running server")
6478
}
6579
}

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ require (
99
github.com/gorilla/mux v1.7.2
1010
github.com/gorilla/websocket v1.4.0
1111
github.com/imdario/mergo v0.3.7
12-
github.com/kelseyhightower/envconfig v1.3.0
1312
github.com/mccutchen/go-httpbin v1.1.1
1413
github.com/micro/go-micro v1.5.0
1514
github.com/miscreant/miscreant-go v0.0.0-20181010193435-325cbd69228b

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,6 @@ github.com/joncalhoun/qson v0.0.0-20170526102502-8a9cab3a62b1/go.mod h1:DFXrEwSR
150150
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
151151
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
152152
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
153-
github.com/kelseyhightower/envconfig v1.3.0 h1:IvRS4f2VcIQy6j4ORGIf9145T/AsUB+oY8LyvN8BXNM=
154-
github.com/kelseyhightower/envconfig v1.3.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
155153
github.com/kevinburke/ssh_config v0.0.0-20180830205328-81db2a75821e/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM=
156154
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
157155
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=

0 commit comments

Comments
 (0)