From d00dfed2724cd449744fe189a6f957bdab8f508b Mon Sep 17 00:00:00 2001 From: arekkas Date: Tue, 29 May 2018 12:30:12 +0200 Subject: [PATCH] cmd: Improves cors parsing --- Gopkg.lock | 15 ++++++++++++--- Gopkg.toml | 6 +++++- cmd/helper_server.go | 21 --------------------- cmd/serve_api.go | 3 ++- cmd/serve_proxy.go | 3 ++- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index dfb8a6fa2e..ef8b88041d 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -242,6 +242,15 @@ revision = "99029e0e1bc4b1d6dfa1ca8b85a46d79cffad6e8" version = "v0.17.2" +[[projects]] + name = "github.com/ory/go-convenience" + packages = [ + "corsx", + "stringsx" + ] + revision = "42cb17c3e4dc0d7d7672cfaffbdfe8f5deb494db" + version = "v0.0.2" + [[projects]] name = "github.com/ory/graceful" packages = ["."] @@ -292,10 +301,10 @@ version = "v0.0.1" [[projects]] - branch = "master" name = "github.com/ory/sqlcon" packages = ["dockertest"] - revision = "a3e701ace784da54e7d5a96e7b08eb394f2af5e4" + revision = "08e1c6762dd59c776a735acc134889f757574f66" + version = "v0.0.2" [[projects]] name = "github.com/pborman/uuid" @@ -528,6 +537,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "3ad3f9caafabd8a73eb89c253cbe0e7c6b1a02e7e6932558659078f268f90048" + inputs-digest = "eea0599444eac5f109cb98e610c4a37f1027f3ea26d433315e9e8fa3813468d8" solver-name = "gps-cdcl" solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml index 1a87794741..f9630ade3c 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -98,9 +98,13 @@ version = "0.0.1" [[constraint]] - branch = "master" + version = "0.0.2" name = "github.com/ory/sqlcon" +[[constraint]] + name = "github.com/ory/go-convenience" + version = "0.0.2" + [[constraint]] name = "github.com/pborman/uuid" version = "1.1.0" diff --git a/cmd/helper_server.go b/cmd/helper_server.go index 878b870b67..299b1eb819 100644 --- a/cmd/helper_server.go +++ b/cmd/helper_server.go @@ -21,14 +21,12 @@ package cmd import ( - "strconv" "strings" "time" "github.com/ory/hydra/sdk/go/hydra" "github.com/ory/oathkeeper/rsakey" "github.com/ory/oathkeeper/rule" - "github.com/rs/cors" "github.com/spf13/viper" ) @@ -95,22 +93,3 @@ func refreshKeys(k rsakey.Manager, fails int) { refreshKeys(k, 1) } - -func parseCorsOptions(prefix string) cors.Options { - if prefix != "" { - prefix = prefix + "_" - } - - allowCredentials, _ := strconv.ParseBool(viper.GetString(prefix + "CORS_ALLOWED_CREDENTIALS")) - debug, _ := strconv.ParseBool(viper.GetString(prefix + "CORS_DEBUG")) - maxAge, _ := strconv.Atoi(viper.GetString(prefix + "CORS_MAX_AGE")) - return cors.Options{ - AllowedOrigins: strings.Split(viper.GetString(prefix+"CORS_ALLOWED_ORIGINS"), ","), - AllowedMethods: strings.Split(viper.GetString(prefix+"CORS_ALLOWED_METHODS"), ","), - AllowedHeaders: strings.Split(viper.GetString(prefix+"CORS_ALLOWED_HEADERS"), ","), - ExposedHeaders: strings.Split(viper.GetString(prefix+"CORS_EXPOSED_HEADERS"), ","), - AllowCredentials: allowCredentials, - MaxAge: maxAge, - Debug: debug, - } -} diff --git a/cmd/serve_api.go b/cmd/serve_api.go index 89f7d1df85..f3b2daa512 100644 --- a/cmd/serve_api.go +++ b/cmd/serve_api.go @@ -26,6 +26,7 @@ import ( "github.com/julienschmidt/httprouter" "github.com/meatballhat/negroni-logrus" + "github.com/ory/go-convenience/corsx" "github.com/ory/graceful" "github.com/ory/herodot" "github.com/ory/oathkeeper/rsakey" @@ -81,7 +82,7 @@ HTTP CONTROLS n.Use(negronilogrus.NewMiddlewareFromLogger(logger, "oathkeeper-api")) n.UseHandler(router) - ch := cors.New(parseCorsOptions("")).Handler(n) + ch := cors.New(corsx.ParseOptions()).Handler(n) go refreshKeys(keyManager, 0) diff --git a/cmd/serve_proxy.go b/cmd/serve_proxy.go index c3bb72fe77..de6c5c71cd 100644 --- a/cmd/serve_proxy.go +++ b/cmd/serve_proxy.go @@ -31,6 +31,7 @@ import ( "github.com/meatballhat/negroni-logrus" "github.com/ory/fosite" + "github.com/ory/go-convenience/corsx" "github.com/ory/graceful" "github.com/ory/keto/sdk/go/keto" "github.com/ory/metrics-middleware" @@ -216,7 +217,7 @@ OTHER CONTROLS n.Use(segmentMiddleware) n.UseHandler(handler) - ch := cors.New(parseCorsOptions("")).Handler(n) + ch := cors.New(corsx.ParseOptions()).Handler(n) var cert tls.Certificate tlsCert := viper.GetString("HTTP_TLS_CERT")