Skip to content

Commit

Permalink
cmd: Properly parses cors options
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed May 29, 2018
1 parent a1d0dcc commit edb5a60
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
version = "0.0.1"

[[constraint]]
version = "0.0.1"
version = "0.0.2"
name = "github.com/ory/sqlcon"

[[constraint]]
Expand All @@ -101,6 +101,10 @@
name = "github.com/pkg/profile"
version = "1.2.1"

[[constraint]]
name = "github.com/ory/go-convenience"
version = "0.0.2"

[[constraint]]
name = "github.com/rs/cors"
version = "1.3.0"
Expand Down
1 change: 1 addition & 0 deletions cmd/client/handler_warden.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (h *WardenHandler) IsOAuth2AccessTokenAuthorized(cmd *cobra.Command, args [
checkResponse(response, err, http.StatusOK)
fmt.Printf("%s\n", response.Payload)
}

func (h *WardenHandler) IsSubjectAuthorized(cmd *cobra.Command, args []string) {
subject, _ := cmd.Flags().GetString("subject")
action, _ := cmd.Flags().GetString("action")
Expand Down
19 changes: 2 additions & 17 deletions cmd/server/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ package server
import (
"fmt"
"net/http"
"strconv"
"strings"

"github.com/gorilla/context"
"github.com/julienschmidt/httprouter"
"github.com/meatballhat/negroni-logrus"
"github.com/ory/fosite"
"github.com/ory/go-convenience/corsx"
"github.com/ory/graceful"
"github.com/ory/herodot"
"github.com/ory/keto/authentication"
Expand All @@ -46,21 +46,6 @@ import (
"github.com/urfave/negroni"
)

func parseCorsOptions() cors.Options {
allowCredentials, _ := strconv.ParseBool(viper.GetString("CORS_ALLOWED_CREDENTIALS"))
debug, _ := strconv.ParseBool(viper.GetString("CORS_DEBUG"))
maxAge, _ := strconv.Atoi(viper.GetString("CORS_MAX_AGE"))
return cors.Options{
AllowedOrigins: strings.Split(viper.GetString("CORS_ALLOWED_ORIGINS"), ","),
AllowedMethods: strings.Split(viper.GetString("CORS_ALLOWED_METHODS"), ","),
AllowedHeaders: strings.Split(viper.GetString("CORS_ALLOWED_HEADERS"), ","),
ExposedHeaders: strings.Split(viper.GetString("CORS_EXPOSED_HEADERS"), ","),
AllowCredentials: allowCredentials,
MaxAge: maxAge,
Debug: debug,
}
}

func RunServe(
logger *logrus.Logger,
buildVersion, buildHash string, buildTime string,
Expand Down Expand Up @@ -122,7 +107,7 @@ func RunServe(
n := negroni.New()
n.Use(negronilogrus.NewMiddlewareFromLogger(logger, "keto"))
n.UseHandler(router)
corsHandler := cors.New(parseCorsOptions()).Handler(n)
corsHandler := cors.New(corsx.ParseOptions()).Handler(n)

if ok, _ := cmd.Flags().GetBool("disable-telemetry"); !ok {
m := metrics.NewMetricsManager(
Expand Down

0 comments on commit edb5a60

Please sign in to comment.