Skip to content

Commit

Permalink
cmd: Improves cors parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed May 29, 2018
1 parent 9dca7c0 commit d00dfed
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 27 deletions.
15 changes: 12 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Gopkg.toml
Expand Up @@ -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"
Expand Down
21 changes: 0 additions & 21 deletions cmd/helper_server.go
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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,
}
}
3 changes: 2 additions & 1 deletion cmd/serve_api.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion cmd/serve_proxy.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit d00dfed

Please sign in to comment.