Skip to content

Commit

Permalink
fix: resolve build issues and bump herodot
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed May 28, 2020
1 parent 43386b0 commit f15e38d
Show file tree
Hide file tree
Showing 24 changed files with 106 additions and 93 deletions.
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@ import (
"os"

"github.com/gobuffalo/packr/v2"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/ory/x/logrusx"

_ "github.com/ory/jsonschema/v3/fileloader"
_ "github.com/ory/jsonschema/v3/httploader"

"github.com/ory/x/viperx"
)

var logger logrus.FieldLogger
var logger *logrusx.Logger

var schemas = packr.New("schemas", "../.schema")

Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ on configuration options, open the configuration documentation:
func init() {
RootCmd.AddCommand(serveCmd)

disableTelemetryEnv := viperx.GetBool(logrusx.New(), "sqa.opt_out", false, "DISABLE_TELEMETRY")
disableTelemetryEnv := viperx.GetBool(logrusx.New("ORY Oathkeeper", x.Version), "sqa.opt_out", false, "DISABLE_TELEMETRY")
serveCmd.PersistentFlags().Bool("disable-telemetry", disableTelemetryEnv, "Disable anonymized telemetry reports - for more information please visit https://www.ory.sh/docs/ecosystem/sqa")
serveCmd.PersistentFlags().Bool("sqa-opt-out", disableTelemetryEnv, "Disable anonymized telemetry reports - for more information please visit https://www.ory.sh/docs/ecosystem/sqa")
}
13 changes: 6 additions & 7 deletions cmd/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/urfave/negroni"

Expand All @@ -34,7 +33,7 @@ import (
"github.com/ory/oathkeeper/x"
)

func runProxy(d driver.Driver, n *negroni.Negroni, logger *logrus.Logger, prom *metrics.PrometheusRepository) func() {
func runProxy(d driver.Driver, n *negroni.Negroni, logger *logrusx.Logger, prom *metrics.PrometheusRepository) func() {
return func() {
proxy := d.Registry().Proxy()

Expand Down Expand Up @@ -75,7 +74,7 @@ func runProxy(d driver.Driver, n *negroni.Negroni, logger *logrus.Logger, prom *
}
}

func runAPI(d driver.Driver, n *negroni.Negroni, logger *logrus.Logger, prom *metrics.PrometheusRepository) func() {
func runAPI(d driver.Driver, n *negroni.Negroni, logger *logrusx.Logger, prom *metrics.PrometheusRepository) func() {
return func() {
router := x.NewAPIRouter()
d.Registry().RuleHandler().SetRoutes(router)
Expand Down Expand Up @@ -115,7 +114,7 @@ func runAPI(d driver.Driver, n *negroni.Negroni, logger *logrus.Logger, prom *me
}
}

func runPrometheus(d driver.Driver, logger *logrus.Logger, prom *metrics.PrometheusRepository) func() {
func runPrometheus(d driver.Driver, logger *logrusx.Logger, prom *metrics.PrometheusRepository) func() {
return func() {
promPath := d.Configuration().PrometheusMetricsPath()
promAddr := d.Configuration().PrometheusServeAddress()
Expand All @@ -138,7 +137,7 @@ func runPrometheus(d driver.Driver, logger *logrus.Logger, prom *metrics.Prometh
}
}

func cert(daemon string, logger logrus.FieldLogger) []tls.Certificate {
func cert(daemon string, logger *logrusx.Logger) []tls.Certificate {
cert, err := tlsx.Certificate(
viper.GetString("serve."+daemon+".tls.cert.base64"),
viper.GetString("serve."+daemon+".tls.key.base64"),
Expand Down Expand Up @@ -181,8 +180,8 @@ func RunServe(version, build, date string) func(cmd *cobra.Command, args []strin
return func(cmd *cobra.Command, args []string) {
fmt.Println(banner(version))

logger := logrusx.New()
d := driver.NewDefaultDriver(logger, version, build, date, true)
logger := logrusx.New("ORY Oathkeeper", version)
d := driver.NewDefaultDriver(logger, version, build, date)
d.Registry().Init()

adminmw := negroni.New()
Expand Down
7 changes: 4 additions & 3 deletions credentials/fetcher_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (
"time"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"gopkg.in/square/go-jose.v2"

"github.com/ory/x/logrusx"

"github.com/ory/herodot"
"github.com/ory/x/httpx"
)
Expand All @@ -54,15 +55,15 @@ type FetcherDefault struct {
client *http.Client
keys map[string]jose.JSONWebKeySet
fetchedAt map[string]time.Time
l logrus.FieldLogger
l *logrusx.Logger
}

// NewFetcherDefault returns a new JWKS Fetcher with:
//
// - cancelAfter: If reached, the fetcher will stop waiting for responses and return an error.
// - waitForResponse: While the fetcher might stop waiting for responses, we will give the server more time to respond
// and add the keys to the registry unless waitForResponse is reached in which case we'll terminate the request.
func NewFetcherDefault(l logrus.FieldLogger, cancelAfter time.Duration, ttl time.Duration) *FetcherDefault {
func NewFetcherDefault(l *logrusx.Logger, cancelAfter time.Duration, ttl time.Duration) *FetcherDefault {
return &FetcherDefault{
cancelAfter: cancelAfter,
l: l,
Expand Down
8 changes: 4 additions & 4 deletions credentials/fetcher_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/x/logrusx"

"github.com/ory/herodot"
"github.com/ory/x/urlx"
)
Expand All @@ -27,10 +29,8 @@ var sets = [...]json.RawMessage{
func TestFetcherDefault(t *testing.T) {
const maxWait = time.Millisecond * 100

l := logrus.New()
l.Level = logrus.DebugLevel

w := herodot.NewJSONWriter(l)
l := logrusx.New("", "", logrusx.ForceLevel(logrus.DebugLevel))
w := herodot.NewJSONWriter(l.Logger)
s := NewFetcherDefault(l, maxWait, maxWait*7)

timeOutServer := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
Expand Down
7 changes: 4 additions & 3 deletions credentials/signer_default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import (

"github.com/dgrijalva/jwt-go"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"

"github.com/ory/x/logrusx"

"github.com/ory/x/urlx"
)

Expand All @@ -20,7 +21,7 @@ type defaultSignerMockRegistry struct {
}

func newDefaultSignerMockRegistry() *defaultSignerMockRegistry {
return &defaultSignerMockRegistry{f: NewFetcherDefault(logrus.New(), time.Millisecond*100, time.Millisecond*500)}
return &defaultSignerMockRegistry{f: NewFetcherDefault(logrusx.New("", ""), time.Millisecond*100, time.Millisecond*500)}
}

func (m *defaultSignerMockRegistry) CredentialsFetcher() Fetcher {
Expand All @@ -39,7 +40,7 @@ func TestSignerDefault(t *testing.T) {
token, err := signer.Sign(context.Background(), urlx.ParseOrPanic(src), jwt.MapClaims{"sub": "foo"})
require.NoError(t, err)

fetcher := NewFetcherDefault(logrus.New(), time.Second, time.Second)
fetcher := NewFetcherDefault(logrusx.New("", ""), time.Second, time.Second)

_, err = verify(t, token, fetcher, src)
require.NoError(t, err)
Expand Down
4 changes: 0 additions & 4 deletions driver/configuration/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"time"

"github.com/gobuffalo/packr/v2"
"github.com/sirupsen/logrus"

"github.com/ory/fosite"
"github.com/ory/x/tracing"
Expand Down Expand Up @@ -84,6 +83,3 @@ type ProviderMutators interface {
MutatorConfig(id string, overrides json.RawMessage, destination interface{}) error
MutatorIsEnabled(id string) bool
}

func MustValidate(l logrus.FieldLogger, p Provider) {
}
6 changes: 3 additions & 3 deletions driver/configuration/provider_viper.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"github.com/imdario/mergo"
"github.com/pkg/errors"
"github.com/rs/cors"
"github.com/sirupsen/logrus"

"github.com/ory/viper"
"github.com/ory/x/logrusx"

"github.com/ory/go-convenience/stringsx"

Expand Down Expand Up @@ -116,7 +116,7 @@ const (
)

type ViperProvider struct {
l logrus.FieldLogger
l *logrusx.Logger

enabledMutex sync.RWMutex
enabledCache map[uint64]bool
Expand All @@ -125,7 +125,7 @@ type ViperProvider struct {
configCache map[uint64]json.RawMessage
}

func NewViperProvider(l logrus.FieldLogger) *ViperProvider {
func NewViperProvider(l *logrusx.Logger) *ViperProvider {
return &ViperProvider{
l: l,
enabledCache: make(map[uint64]bool),
Expand Down
5 changes: 3 additions & 2 deletions driver/configuration/provider_viper_private_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ package configuration
import (
"testing"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"

"github.com/ory/x/logrusx"
)

func TestGetURL(t *testing.T) {
v := NewViperProvider(logrus.New())
v := NewViperProvider(logrusx.New("", ""))
assert.Nil(t, v.getURL("", "key"))
assert.Nil(t, v.getURL("a", "key"))
}
32 changes: 18 additions & 14 deletions driver/configuration/provider_viper_public_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"testing"

"github.com/rs/cors"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/ory/x/logrusx"

"github.com/ory/x/urlx"
"github.com/ory/x/viperx"

Expand All @@ -28,7 +29,7 @@ import (
)

func setup(t *testing.T) *ViperProvider {
l := logrus.New()
l := logrusx.New("", "")
viper.Reset()
viperx.InitializeConfig(
"oathkeeper",
Expand All @@ -38,7 +39,7 @@ func setup(t *testing.T) *ViperProvider {

err := viperx.ValidateFromURL("file://../../.schema/config.schema.json")
if err != nil {
viperx.LoggerWithValidationErrorFields(l, err).Error("unable to validate")
l.WithError(err).Error("unable to validate")
}
require.NoError(t, err)

Expand Down Expand Up @@ -112,19 +113,20 @@ v0.35.2

func BenchmarkPipelineConfig(b *testing.B) {
viper.Reset()
l := logrusx.New("", "")
viperx.InitializeConfig(
"oathkeeper",
"./../../internal/config/",
logrus.New(),
l,
)

err := viperx.ValidateFromURL("file://../../.schema/config.schema.json")
if err != nil {
viperx.LoggerWithValidationErrorFields(logrus.New(), err).Error("unable to validate")
l.WithError(err).Error("unable to validate")
}
require.NoError(b, err)

p := NewViperProvider(logrus.New())
p := NewViperProvider(logrusx.New("", ""))

for n := 0; n < b.N; n++ {
res := json.RawMessage{}
Expand All @@ -144,19 +146,20 @@ v0.35.5

func BenchmarkPipelineEnabled(b *testing.B) {
viper.Reset()
logger := logrusx.New("", "")
viperx.InitializeConfig(
"oathkeeper",
"./../../internal/config/",
logrus.New(),
logger,
)

err := viperx.ValidateFromURL("file://../../.schema/config.schema.json")
if err != nil {
viperx.LoggerWithValidationErrorFields(logrus.New(), err).Error("unable to validate")
logger.WithError(err).Error("unable to validate")
}
require.NoError(b, err)

p := NewViperProvider(logrus.New())
p := NewViperProvider(logrusx.New("", ""))

for n := 0; n < b.N; n++ {
p.AuthorizerIsEnabled("allow")
Expand All @@ -167,17 +170,18 @@ func BenchmarkPipelineEnabled(b *testing.B) {

func TestViperProvider(t *testing.T) {
viper.Reset()
logger := logrusx.New("", "")
viperx.InitializeConfig(
"oathkeeper",
"./../../internal/config/",
logrus.New(),
logger,
)

err := viperx.ValidateFromURL("file://../../.schema/config.schema.json")
if err != nil {
viperx.LoggerWithValidationErrorFields(logrus.New(), err).Error("unable to validate")
logger.WithError(err).Error("unable to validate")
}
p := NewViperProvider(logrus.New())
p := NewViperProvider(logrusx.New("", ""))

t.Run("group=serve", func(t *testing.T) {
assert.Equal(t, "127.0.0.1:1234", p.ProxyServeAddress())
Expand Down Expand Up @@ -393,7 +397,7 @@ func TestViperProvider(t *testing.T) {
}

func TestToScopeStrategy(t *testing.T) {
v := NewViperProvider(logrus.New())
v := NewViperProvider(logrusx.New("", ""))

assert.True(t, v.ToScopeStrategy("exact", "foo")([]string{"foo"}, "foo"))
assert.True(t, v.ToScopeStrategy("hierarchic", "foo")([]string{"foo"}, "foo.bar"))
Expand All @@ -404,7 +408,7 @@ func TestToScopeStrategy(t *testing.T) {

func TestAuthenticatorOAuth2TokenIntrospectionPreAuthorization(t *testing.T) {
viper.Reset()
v := NewViperProvider(logrus.New())
v := NewViperProvider(logrusx.New("", ""))
viper.Set("authenticators.oauth2_introspection.enabled", true)
viper.Set("authenticators.oauth2_introspection.config.introspection_url", "http://some-url/")

Expand Down
9 changes: 2 additions & 7 deletions driver/driver_default.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package driver

import (
"github.com/sirupsen/logrus"
"github.com/ory/x/logrusx"

"github.com/ory/oathkeeper/driver/configuration"
)
Expand All @@ -11,13 +11,8 @@ type DefaultDriver struct {
r Registry
}

func NewDefaultDriver(l logrus.FieldLogger, version, build, date string, validate bool) Driver {
func NewDefaultDriver(l *logrusx.Logger, version, build, date string) Driver {
c := configuration.NewViperProvider(l)

if validate {
configuration.MustValidate(l, c)
}

r := NewRegistry(c).WithLogger(l).WithBuildInfo(version, build, date)

return &DefaultDriver{r: r, c: c}
Expand Down
Loading

0 comments on commit f15e38d

Please sign in to comment.