Skip to content

Commit

Permalink
Merge e58a3b0 into 75ea3fd
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed May 1, 2017
2 parents 75ea3fd + e58a3b0 commit 23adbd8
Show file tree
Hide file tree
Showing 78 changed files with 2,100 additions and 1,485 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,23 @@
# Changelog

## v1.0.0-beta4 (unreleased)

- **[Breaking]** Introduce a config loader, this will allow to override config loading
and use custom dirs to load from. In order to load configs calls to `config.Load()`
should be replaced with `config.NewLoader().Load()`.
- Added `metrics.NopScope` for tests on service.NopHost with tagging capabilities
turned on by default
- Added a command line provider `config.NewCommandLineProvider()`, which can be used
to pass configuration parameters through command line.
- **[Breaking]** `uhttp module` now accepts `http.Handler` as part of module setup.
As part of refactor, RouteHandler is removed from the module registration.
- `Loader.Path() string` is now `Loader.Paths() []string`, to better reflect that
configuration is loaded from multiple directories.
- **[Breaking]** Removed `CreateAuthInfo` interface from auth package. package auth
RegisterFunc now accepts `config.Provider` and `tally.Scope` for initialization.
- **[Breaking]** Removed `auth.Client` access from `service.Host`. `auth.Client` can
now be accessed via `auth.Load()` call.

## v1.0.0-beta3 (28 Mar 2017)

- **[Breaking]** Environment config provider was removed. If you were using
Expand Down
2 changes: 1 addition & 1 deletion auth/README.md
Expand Up @@ -36,7 +36,7 @@ type userAuthClient struct {
// embed backend security service client here
}
func userAuthClient(info CreateAuthInfo) auth.Client {
func userAuthClient(config config.Provider, scope tally.Scope) auth.Client {
return &userAuthClient{}
}
Expand Down
12 changes: 9 additions & 3 deletions auth/auth_failure_client.go
Expand Up @@ -23,13 +23,19 @@ package auth
import (
"context"
"errors"

"go.uber.org/fx/config"

"github.com/uber-go/tally"
)

type failureClient struct {
}
// FailureClient is used for auth failure testing
var FailureClient = FakeFailureClient(nil, tally.NoopScope)

type failureClient struct{}

// FakeFailureClient fails all auth request and must only be used for testing
func FakeFailureClient(info CreateAuthInfo) Client {
func FakeFailureClient(config config.Provider, scope tally.Scope) Client {
return &failureClient{}
}

Expand Down
12 changes: 9 additions & 3 deletions auth/auth_stub.go
Expand Up @@ -20,19 +20,25 @@

package auth

import "context"
import (
"context"

"go.uber.org/fx/config"

"github.com/uber-go/tally"
)

var (
// NopClient is used for testing and no-op integration
NopClient = nopClient(nil)
NopClient = nopClient(nil, tally.NoopScope)

_ Client = &nop{}
)

type nop struct {
}

func nopClient(info CreateAuthInfo) Client {
func nopClient(config config.Provider, scope tally.Scope) Client {
return &nop{}
}

Expand Down
2 changes: 1 addition & 1 deletion auth/doc.go
Expand Up @@ -66,7 +66,7 @@
// // embed backend security service client here
// }
//
// func userAuthClient(info CreateAuthInfo) auth.Client {
// func userAuthClient(config config.Provider, scope tally.Scope) auth.Client {
// return &userAuthClient{}
// }
//
Expand Down
10 changes: 8 additions & 2 deletions auth/localauth.go
Expand Up @@ -20,7 +20,13 @@

package auth

import "context"
import (
"context"

"go.uber.org/fx/config"

"github.com/uber-go/tally"
)

var _ Client = &defaultClient{}

Expand All @@ -30,7 +36,7 @@ type defaultClient struct {

// defaultAuth is a placeholder auth client when no auth client is registered
// TODO(anup): add configurable authentication, whether a service needs one or not
func defaultAuth(info CreateAuthInfo) Client {
func defaultAuth(config config.Provider, scope tally.Scope) Client {
return &defaultClient{
authClient: NopClient,
}
Expand Down
15 changes: 5 additions & 10 deletions auth/uauth.go
Expand Up @@ -24,8 +24,9 @@ import (
"context"
"sync"

"github.com/uber-go/tally"
"go.uber.org/fx/config"

"github.com/uber-go/tally"
)

var (
Expand All @@ -44,14 +45,8 @@ var (
ErrAuthorization = "Error authorizing the service"
)

// CreateAuthInfo interface provides necessary data
type CreateAuthInfo interface {
Config() config.Provider
Metrics() tally.Scope
}

// RegisterFunc is used during service init time to register the Auth client
type RegisterFunc func(info CreateAuthInfo) Client
type RegisterFunc func(config config.Provider, scope tally.Scope) Client

// RegisterClient sets up the registerFunc for Auth client initialization
func RegisterClient(registerFunc RegisterFunc) {
Expand All @@ -71,11 +66,11 @@ func UnregisterClient() {
}

// Load returns a Client instance based on registered auth client implementation
func Load(info CreateAuthInfo) Client {
func Load(config config.Provider, scope tally.Scope) Client {
_setupMu.Lock()
defer _setupMu.Unlock()
if _registerFunc != nil {
return _registerFunc(info)
return _registerFunc(config, scope)
}
return NopClient
}
Expand Down
31 changes: 7 additions & 24 deletions auth/uauth_test.go
Expand Up @@ -24,23 +24,20 @@ import (
"context"
"testing"

"go.uber.org/fx/config"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/uber-go/tally"
"go.uber.org/zap"
)

func withAuthClientSetup(t *testing.T, registerFunc RegisterFunc, info CreateAuthInfo, fn func()) {
func withAuthClientSetup(t *testing.T, registerFunc RegisterFunc, fn func()) {
UnregisterClient()
RegisterClient(registerFunc)
fn()
}

func TestUauth_Stub(t *testing.T) {
RegisterClient(defaultAuth)
authClient := Load(fakeAuthInfo{})
authClient := Load(nil, tally.NoopScope)
assert.Equal(t, "auth", authClient.Name())
assert.NotNil(t, authClient)
assert.Nil(t, authClient.Authorize(context.Background()))
Expand All @@ -52,8 +49,8 @@ func TestUauth_Stub(t *testing.T) {
}

func TestUauth_Register(t *testing.T) {
withAuthClientSetup(t, FakeFailureClient, fakeAuthInfo{}, func() {
authClient := Load(fakeAuthInfo{})
withAuthClientSetup(t, FakeFailureClient, func() {
authClient := Load(nil, tally.NoopScope)
assert.Equal(t, "failure", authClient.Name())
assert.NotNil(t, authClient)
err := authClient.Authorize(context.Background())
Expand All @@ -67,29 +64,15 @@ func TestUauth_Register(t *testing.T) {
}

func TestUauth_RegisterPanic(t *testing.T) {
withAuthClientSetup(t, FakeFailureClient, nil, func() {
withAuthClientSetup(t, FakeFailureClient, func() {
assert.Panics(t, func() {
RegisterClient(FakeFailureClient)
})
})
}

func TestUauth_Default(t *testing.T) {
withAuthClientSetup(t, nil, fakeAuthInfo{}, func() {
assert.Equal(t, "nop", Load(fakeAuthInfo{}).Name())
withAuthClientSetup(t, nil, func() {
assert.Equal(t, "nop", Load(nil, tally.NoopScope).Name())
})
}

type fakeAuthInfo struct{}

func (fakeAuthInfo) Config() config.Provider {
return nil
}

func (fakeAuthInfo) Logger() *zap.Logger {
return zap.NewNop()
}

func (fakeAuthInfo) Metrics() tally.Scope {
return tally.NoopScope
}

0 comments on commit 23adbd8

Please sign in to comment.