Skip to content

Commit

Permalink
Rename package uauth to auth
Browse files Browse the repository at this point in the history
  • Loading branch information
anuptalwalkar committed Dec 27, 2016
1 parent f8fb1da commit e15fe25
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package uauth
package auth

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion uauth/auth_stub.go → auth/auth_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package uauth
package auth

import "context"

Expand Down
4 changes: 2 additions & 2 deletions uauth/localauth.go → auth/localauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package uauth
package auth

import "context"

Expand All @@ -44,7 +44,7 @@ func Instance() Client {
}

func (*defaultClient) Name() string {
return "uauth"
return "auth"
}

func (d *defaultClient) Authenticate(ctx context.Context) (context.Context, error) {
Expand Down
4 changes: 2 additions & 2 deletions uauth/uauth.go → auth/uauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package uauth
package auth

import (
"context"
Expand Down Expand Up @@ -58,7 +58,7 @@ func RegisterClient(registerFunc RegisterFunc) {
_registerFunc = registerFunc
}

// UnregisterClient unregisters uauth RegisterFunc for testing and resets to noopClient
// UnregisterClient unregisters auth RegisterFunc for testing and resets to noopClient
func UnregisterClient() {
_setupMu.Lock()
defer _setupMu.Unlock()
Expand Down
4 changes: 2 additions & 2 deletions uauth/uauth_test.go → auth/uauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

package uauth
package auth

import (
"context"
Expand All @@ -39,7 +39,7 @@ func withAuthClientSetup(t *testing.T, registerFunc RegisterFunc, info CreateAut

func TestUauth_Stub(t *testing.T) {
authClient := Instance()
assert.Equal(t, "uauth", authClient.Name())
assert.Equal(t, "auth", authClient.Name())
assert.NotNil(t, authClient)
assert.Nil(t, authClient.Authorize(context.Background()))
ctx, err := authClient.Authenticate(context.Background())
Expand Down
6 changes: 3 additions & 3 deletions modules/rpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"context"

"go.uber.org/fx"
"go.uber.org/fx/auth"
"go.uber.org/fx/internal/fxcontext"
"go.uber.org/fx/service"
"go.uber.org/fx/uauth"
"go.uber.org/thriftrw/wire"
"go.uber.org/yarpc"
"go.uber.org/yarpc/encoding/thrift"
Expand Down Expand Up @@ -127,10 +127,10 @@ func authorize(ctx context.Context, host service.Host) (fx.Context, error) {
fxctx := &fxcontext.Context{
Context: ctx,
}
authClient := uauth.Instance()
authClient := auth.Instance()
if err := authClient.Authorize(fxctx); err != nil {
host.Metrics().SubScope("rpc").SubScope("auth").Counter("fail").Inc(1)
fxctx.Logger().Error(uauth.ErrAuthorization, "error", err)
fxctx.Logger().Error(auth.ErrAuthorization, "error", err)
// TODO(anup): GFM-255 update returned error to transport.BadRequestError (user error than server error)
return nil, err
}
Expand Down
14 changes: 7 additions & 7 deletions modules/rpc/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
"github.com/stretchr/testify/assert"

"go.uber.org/fx"
"go.uber.org/fx/auth"
"go.uber.org/fx/internal/fxcontext"
"go.uber.org/fx/service"
"go.uber.org/fx/uauth"
"go.uber.org/thriftrw/wire"
"go.uber.org/yarpc"
"go.uber.org/yarpc/encoding/thrift"
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestInboundMiddleware_auth(t *testing.T) {
}

func TestInboundMiddleware_authFailure(t *testing.T) {
withAuthClient(t, uauth.FakeFailureClient, func() {
withAuthClient(t, auth.FakeFailureClient, func() {
unary := authInboundMiddleware{
Host: service.NullHost(),
}
Expand All @@ -137,7 +137,7 @@ func TestOnewayInboundMiddleware_auth(t *testing.T) {
}

func TestOnewayInboundMiddleware_authFailure(t *testing.T) {
withAuthClient(t, uauth.FakeFailureClient, func() {
withAuthClient(t, auth.FakeFailureClient, func() {
oneway := authOnewayInboundMiddleware{
Host: service.NullHost(),
}
Expand All @@ -146,10 +146,10 @@ func TestOnewayInboundMiddleware_authFailure(t *testing.T) {
})
}

func withAuthClient(t *testing.T, registerFunc uauth.RegisterFunc, fn func()) {
uauth.UnregisterClient()
uauth.RegisterClient(registerFunc)
uauth.SetupClient(service.NullHost())
func withAuthClient(t *testing.T, registerFunc auth.RegisterFunc, fn func()) {
auth.UnregisterClient()
auth.RegisterClient(registerFunc)
auth.SetupClient(service.NullHost())
fn()
}

Expand Down
6 changes: 3 additions & 3 deletions modules/uhttp/client/client_filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"net/http"

"go.uber.org/fx"
"go.uber.org/fx/auth"
"go.uber.org/fx/internal/fxcontext"
"go.uber.org/fx/uauth"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
Expand Down Expand Up @@ -85,10 +85,10 @@ func tracingFilter(
func authenticationFilter(
ctx fx.Context, req *http.Request, next BasicClient,
) (resp *http.Response, err error) {
authClient := uauth.Instance()
authClient := auth.Instance()
authctx, err := authClient.Authenticate(ctx)
if err != nil {
ctx.Logger().Error(uauth.ErrAuthentication, "error", err)
ctx.Logger().Error(auth.ErrAuthentication, "error", err)
return nil, err
}
return next.Do(&fxcontext.Context{Context: authctx}, req)
Expand Down
6 changes: 3 additions & 3 deletions modules/uhttp/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
"net/http"

"go.uber.org/fx"
"go.uber.org/fx/auth"
"go.uber.org/fx/internal/fxcontext"
"go.uber.org/fx/service"
"go.uber.org/fx/uauth"

"github.com/opentracing/opentracing-go"
"github.com/opentracing/opentracing-go/ext"
Expand Down Expand Up @@ -87,11 +87,11 @@ func authorizationFilter(host service.Host) FilterFunc {
fxctx := &fxcontext.Context{
Context: ctx,
}
authClient := uauth.Instance()
authClient := auth.Instance()
err := authClient.Authorize(fxctx)
if err != nil {
host.Metrics().SubScope("http").SubScope("auth").Counter("fail").Inc(1)
fxctx.Logger().Error(uauth.ErrAuthorization, "error", err)
fxctx.Logger().Error(auth.ErrAuthorization, "error", err)
w.WriteHeader(http.StatusUnauthorized)
fmt.Fprintf(w, "Unauthorized access: %+v", err)
return
Expand Down
12 changes: 6 additions & 6 deletions modules/uhttp/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import (
"testing"

"go.uber.org/fx"
"go.uber.org/fx/auth"
"go.uber.org/fx/internal/fxcontext"
"go.uber.org/fx/service"
"go.uber.org/fx/uauth"

"github.com/stretchr/testify/assert"
)
Expand All @@ -57,11 +57,11 @@ func TestFilterChainFilters(t *testing.T) {

func TestFilterChainFilters_AuthFailure(t *testing.T) {
host := service.NullHost()
uauth.UnregisterClient()
uauth.RegisterClient(uauth.FakeFailureClient)
uauth.SetupClient(host)
defer uauth.UnregisterClient()
defer uauth.SetupClient(host)
auth.UnregisterClient()
auth.RegisterClient(auth.FakeFailureClient)
auth.SetupClient(host)
defer auth.UnregisterClient()
defer auth.SetupClient(host)
chain := newFilterChain([]Filter{
contextFilter(host),
tracingServerFilter(host),
Expand Down
8 changes: 4 additions & 4 deletions service/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"io"
"sync"

"go.uber.org/fx/auth"
"go.uber.org/fx/config"
"go.uber.org/fx/metrics"
"go.uber.org/fx/uauth"
"go.uber.org/fx/ulog"

"github.com/opentracing/opentracing-go"
Expand All @@ -36,7 +36,7 @@ import (

// A Host represents the hosting environment for a service instance
type Host interface {
AuthClient() uauth.Client
AuthClient() auth.Client
Name() string
Description() string
Roles() []string
Expand Down Expand Up @@ -109,7 +109,7 @@ type serviceCore struct {
loggingCore
metricsCore
tracerCore
authClient uauth.Client
authClient auth.Client
configProvider config.Provider
observer Observer
resources map[string]interface{}
Expand All @@ -121,7 +121,7 @@ type serviceCore struct {

var _ Host = &serviceCore{}

func (s *serviceCore) AuthClient() uauth.Client {
func (s *serviceCore) AuthClient() auth.Client {
return s.authClient
}

Expand Down
6 changes: 3 additions & 3 deletions service/service_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ package service
import (
"time"

"go.uber.org/fx/auth"
"go.uber.org/fx/config"
"go.uber.org/fx/metrics"
"go.uber.org/fx/tracing"
"go.uber.org/fx/uauth"
"go.uber.org/fx/ulog"

"github.com/go-validator/validator"
Expand Down Expand Up @@ -117,6 +117,6 @@ func (svc *serviceCore) setupAuthClient(cfg config.Provider) {
if svc.authClient != nil {
return
}
uauth.SetupClient(svc)
svc.authClient = uauth.Instance()
auth.SetupClient(svc)
svc.authClient = auth.Instance()
}

0 comments on commit e15fe25

Please sign in to comment.