Refactor: rename auth package (#172)

This commit is contained in:
Hidetake Iwata
2019-10-28 20:02:59 +09:00
committed by GitHub
parent 93e893bc36
commit dbf6238029
14 changed files with 72 additions and 70 deletions

View File

@@ -15,7 +15,7 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/credentialplugin/mock_credentialplugin"
"github.com/int128/kubelogin/pkg/adaptors/logger/mock_logger"
"github.com/int128/kubelogin/pkg/di"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
)
// Run the integration tests of the credential plugin use-case.
@@ -74,7 +74,7 @@ func TestCmd_Run_CredentialPlugin(t *testing.T) {
})
}
func runGetTokenCmd(t *testing.T, ctx context.Context, localServerReadyFunc auth.LocalServerReadyFunc, interaction credentialplugin.Interface, args ...string) {
func runGetTokenCmd(t *testing.T, ctx context.Context, localServerReadyFunc authentication.LocalServerReadyFunc, interaction credentialplugin.Interface, args ...string) {
t.Helper()
cmd := di.NewCmdForHeadless(mock_logger.New(t), localServerReadyFunc, interaction)
exitCode := cmd.Run(ctx, append([]string{"kubelogin", "get-token", "--v=1"}, args...), "HEAD")

View File

@@ -17,7 +17,7 @@ import (
"github.com/int128/kubelogin/e2e_test/localserver"
"github.com/int128/kubelogin/pkg/adaptors/logger/mock_logger"
"github.com/int128/kubelogin/pkg/di"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
)
var (
@@ -312,7 +312,7 @@ func setupMockIDPForCodeFlow(t *testing.T, service *mock_idp.MockService, server
})
}
func runCmd(t *testing.T, ctx context.Context, localServerReadyFunc auth.LocalServerReadyFunc, args ...string) {
func runCmd(t *testing.T, ctx context.Context, localServerReadyFunc authentication.LocalServerReadyFunc, args ...string) {
t.Helper()
cmd := di.NewCmdForHeadless(mock_logger.New(t), localServerReadyFunc, nil)
exitCode := cmd.Run(ctx, append([]string{"kubelogin", "--v=1"}, args...), "HEAD")
@@ -321,7 +321,7 @@ func runCmd(t *testing.T, ctx context.Context, localServerReadyFunc auth.LocalSe
}
}
func openBrowserOnReadyFunc(t *testing.T, ctx context.Context, clientConfig *tls.Config) auth.LocalServerReadyFunc {
func openBrowserOnReadyFunc(t *testing.T, ctx context.Context, clientConfig *tls.Config) authentication.LocalServerReadyFunc {
return func(url string) {
client := http.Client{Transport: &http.Transport{TLSClientConfig: clientConfig}}
req, err := http.NewRequest("GET", url, nil)

View File

@@ -12,7 +12,7 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/logger"
"github.com/int128/kubelogin/pkg/adaptors/oidc"
"github.com/int128/kubelogin/pkg/adaptors/tokencache"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
credentialPluginUseCase "github.com/int128/kubelogin/pkg/usecases/credentialplugin"
"github.com/int128/kubelogin/pkg/usecases/setup"
"github.com/int128/kubelogin/pkg/usecases/standalone"
@@ -22,8 +22,8 @@ import (
func NewCmd() cmd.Interface {
wire.Build(
// use-cases
auth.Set,
wire.Value(auth.DefaultLocalServerReadyFunc),
authentication.Set,
wire.Value(authentication.DefaultLocalServerReadyFunc),
standalone.Set,
credentialPluginUseCase.Set,
setup.Set,
@@ -41,9 +41,9 @@ func NewCmd() cmd.Interface {
}
// NewCmdForHeadless returns an instance of adaptors.Cmd for headless testing.
func NewCmdForHeadless(logger.Interface, auth.LocalServerReadyFunc, credentialPluginAdaptor.Interface) cmd.Interface {
func NewCmdForHeadless(logger.Interface, authentication.LocalServerReadyFunc, credentialPluginAdaptor.Interface) cmd.Interface {
wire.Build(
auth.Set,
authentication.Set,
standalone.Set,
credentialPluginUseCase.Set,
setup.Set,

View File

@@ -13,7 +13,7 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/logger"
"github.com/int128/kubelogin/pkg/adaptors/oidc"
"github.com/int128/kubelogin/pkg/adaptors/tokencache"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
credentialplugin2 "github.com/int128/kubelogin/pkg/usecases/credentialplugin"
"github.com/int128/kubelogin/pkg/usecases/setup"
"github.com/int128/kubelogin/pkg/usecases/standalone"
@@ -29,7 +29,7 @@ func NewCmd() cmd.Interface {
decoder := &oidc.Decoder{}
envEnv := &env.Env{}
localServerReadyFunc := _wireLocalServerReadyFuncValue
authentication := &auth.Authentication{
authenticationAuthentication := &authentication.Authentication{
OIDCFactory: factory,
OIDCDecoder: decoder,
Env: envEnv,
@@ -38,7 +38,7 @@ func NewCmd() cmd.Interface {
}
kubeconfigKubeconfig := &kubeconfig.Kubeconfig{}
standaloneStandalone := &standalone.Standalone{
Authentication: authentication,
Authentication: authenticationAuthentication,
Kubeconfig: kubeconfigKubeconfig,
Logger: loggerInterface,
}
@@ -49,7 +49,7 @@ func NewCmd() cmd.Interface {
repository := &tokencache.Repository{}
interaction := &credentialplugin.Interaction{}
getToken := &credentialplugin2.GetToken{
Authentication: authentication,
Authentication: authenticationAuthentication,
TokenCacheRepository: repository,
Interaction: interaction,
Logger: loggerInterface,
@@ -59,7 +59,7 @@ func NewCmd() cmd.Interface {
Logger: loggerInterface,
}
setupSetup := &setup.Setup{
Authentication: authentication,
Authentication: authenticationAuthentication,
Logger: loggerInterface,
}
cmdSetup := &cmd.Setup{
@@ -75,16 +75,16 @@ func NewCmd() cmd.Interface {
}
var (
_wireLocalServerReadyFuncValue = auth.DefaultLocalServerReadyFunc
_wireLocalServerReadyFuncValue = authentication.DefaultLocalServerReadyFunc
)
func NewCmdForHeadless(loggerInterface logger.Interface, localServerReadyFunc auth.LocalServerReadyFunc, credentialpluginInterface credentialplugin.Interface) cmd.Interface {
func NewCmdForHeadless(loggerInterface logger.Interface, localServerReadyFunc authentication.LocalServerReadyFunc, credentialpluginInterface credentialplugin.Interface) cmd.Interface {
factory := &oidc.Factory{
Logger: loggerInterface,
}
decoder := &oidc.Decoder{}
envEnv := &env.Env{}
authentication := &auth.Authentication{
authenticationAuthentication := &authentication.Authentication{
OIDCFactory: factory,
OIDCDecoder: decoder,
Env: envEnv,
@@ -93,7 +93,7 @@ func NewCmdForHeadless(loggerInterface logger.Interface, localServerReadyFunc au
}
kubeconfigKubeconfig := &kubeconfig.Kubeconfig{}
standaloneStandalone := &standalone.Standalone{
Authentication: authentication,
Authentication: authenticationAuthentication,
Kubeconfig: kubeconfigKubeconfig,
Logger: loggerInterface,
}
@@ -103,7 +103,7 @@ func NewCmdForHeadless(loggerInterface logger.Interface, localServerReadyFunc au
}
repository := &tokencache.Repository{}
getToken := &credentialplugin2.GetToken{
Authentication: authentication,
Authentication: authenticationAuthentication,
TokenCacheRepository: repository,
Interaction: credentialpluginInterface,
Logger: loggerInterface,
@@ -113,7 +113,7 @@ func NewCmdForHeadless(loggerInterface logger.Interface, localServerReadyFunc au
Logger: loggerInterface,
}
setupSetup := &setup.Setup{
Authentication: authentication,
Authentication: authenticationAuthentication,
Logger: loggerInterface,
}
cmdSetup := &cmd.Setup{

View File

@@ -1,4 +1,4 @@
package auth
package authentication
import (
"context"
@@ -13,7 +13,7 @@ import (
"golang.org/x/xerrors"
)
//go:generate mockgen -destination mock_auth/mock_auth.go github.com/int128/kubelogin/pkg/usecases/auth Interface
//go:generate mockgen -destination mock_authentication/mock_authentication.go github.com/int128/kubelogin/pkg/usecases/authentication Interface
// Set provides the use-case of Authentication.
var Set = wire.NewSet(

View File

@@ -1,4 +1,4 @@
package auth
package authentication
import (
"context"

View File

@@ -1,13 +1,13 @@
// Code generated by MockGen. DO NOT EDIT.
// Source: github.com/int128/kubelogin/pkg/usecases/auth (interfaces: Interface)
// Source: github.com/int128/kubelogin/pkg/usecases/authentication (interfaces: Interface)
// Package mock_auth is a generated GoMock package.
package mock_auth
// Package mock_authentication is a generated GoMock package.
package mock_authentication
import (
context "context"
gomock "github.com/golang/mock/gomock"
auth "github.com/int128/kubelogin/pkg/usecases/auth"
authentication "github.com/int128/kubelogin/pkg/usecases/authentication"
reflect "reflect"
)
@@ -35,14 +35,16 @@ func (m *MockInterface) EXPECT() *MockInterfaceMockRecorder {
}
// Do mocks base method
func (m *MockInterface) Do(arg0 context.Context, arg1 auth.Input) (*auth.Output, error) {
func (m *MockInterface) Do(arg0 context.Context, arg1 authentication.Input) (*authentication.Output, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "Do", arg0, arg1)
ret0, _ := ret[0].(*auth.Output)
ret0, _ := ret[0].(*authentication.Output)
ret1, _ := ret[1].(error)
return ret0, ret1
}
// Do indicates an expected call of Do
func (mr *MockInterfaceMockRecorder) Do(arg0, arg1 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Do", reflect.TypeOf((*MockInterface)(nil).Do), arg0, arg1)
}

View File

@@ -11,7 +11,7 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig"
"github.com/int128/kubelogin/pkg/adaptors/logger"
"github.com/int128/kubelogin/pkg/adaptors/tokencache"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"golang.org/x/xerrors"
)
@@ -42,7 +42,7 @@ type Input struct {
}
type GetToken struct {
Authentication auth.Interface
Authentication authentication.Interface
TokenCacheRepository tokencache.Interface
Interaction credentialplugin.Interface
Logger logger.Interface
@@ -61,7 +61,7 @@ func (u *GetToken) Do(ctx context.Context, in Input) error {
return nil
}
func (u *GetToken) getTokenFromCacheOrProvider(ctx context.Context, in Input) (*auth.Output, error) {
func (u *GetToken) getTokenFromCacheOrProvider(ctx context.Context, in Input) (*authentication.Output, error) {
u.Logger.V(1).Infof("finding a token from cache directory %s", in.TokenCacheDir)
cacheKey := tokencache.Key{IssuerURL: in.IssuerURL, ClientID: in.ClientID}
cache, err := u.TokenCacheRepository.FindByKey(in.TokenCacheDir, cacheKey)
@@ -70,7 +70,7 @@ func (u *GetToken) getTokenFromCacheOrProvider(ctx context.Context, in Input) (*
cache = &tokencache.TokenCache{}
}
out, err := u.Authentication.Do(ctx, auth.Input{
out, err := u.Authentication.Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: in.IssuerURL,
ClientID: in.ClientID,

View File

@@ -12,8 +12,8 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/logger/mock_logger"
"github.com/int128/kubelogin/pkg/adaptors/tokencache"
"github.com/int128/kubelogin/pkg/adaptors/tokencache/mock_tokencache"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/auth/mock_auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"github.com/int128/kubelogin/pkg/usecases/authentication/mock_authentication"
"golang.org/x/xerrors"
)
@@ -37,9 +37,9 @@ func TestGetToken_Do(t *testing.T) {
CACertFilename: "/path/to/cert",
SkipTLSVerify: true,
}
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{
Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: "https://accounts.google.com",
ClientID: "YOUR_CLIENT_ID",
@@ -52,7 +52,7 @@ func TestGetToken_Do(t *testing.T) {
CACertFilename: "/path/to/cert",
SkipTLSVerify: true,
}).
Return(&auth.Output{
Return(&authentication.Output{
IDToken: "YOUR_ID_TOKEN",
RefreshToken: "YOUR_REFRESH_TOKEN",
IDTokenExpiry: futureTime,
@@ -102,9 +102,9 @@ func TestGetToken_Do(t *testing.T) {
ClientSecret: "YOUR_CLIENT_SECRET",
TokenCacheDir: "/path/to/token-cache",
}
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{
Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: "https://accounts.google.com",
ClientID: "YOUR_CLIENT_ID",
@@ -112,7 +112,7 @@ func TestGetToken_Do(t *testing.T) {
IDToken: "VALID_ID_TOKEN",
},
}).
Return(&auth.Output{
Return(&authentication.Output{
AlreadyHasValidIDToken: true,
IDToken: "VALID_ID_TOKEN",
IDTokenExpiry: futureTime,
@@ -154,9 +154,9 @@ func TestGetToken_Do(t *testing.T) {
ClientSecret: "YOUR_CLIENT_SECRET",
TokenCacheDir: "/path/to/token-cache",
}
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{
Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: "https://accounts.google.com",
ClientID: "YOUR_CLIENT_ID",

View File

@@ -6,7 +6,7 @@ import (
"github.com/google/wire"
"github.com/int128/kubelogin/pkg/adaptors/logger"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
)
var Set = wire.NewSet(
@@ -20,6 +20,6 @@ type Interface interface {
}
type Setup struct {
Authentication auth.Interface
Authentication authentication.Interface
Logger logger.Interface
}

View File

@@ -7,7 +7,7 @@ import (
"text/template"
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"golang.org/x/xerrors"
)
@@ -79,7 +79,7 @@ type Stage2Input struct {
func (u *Setup) DoStage2(ctx context.Context, in Stage2Input) error {
u.Logger.Printf(`## 2. Verify authentication`)
out, err := u.Authentication.Do(ctx, auth.Input{
out, err := u.Authentication.Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: in.IssuerURL,
ClientID: in.ClientID,

View File

@@ -8,8 +8,8 @@ import (
"github.com/golang/mock/gomock"
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig"
"github.com/int128/kubelogin/pkg/adaptors/logger/mock_logger"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/auth/mock_auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"github.com/int128/kubelogin/pkg/usecases/authentication/mock_authentication"
)
func TestSetup_DoStage2(t *testing.T) {
@@ -28,9 +28,9 @@ func TestSetup_DoStage2(t *testing.T) {
SkipTLSVerify: true,
}
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{
Do(ctx, authentication.Input{
OIDCConfig: kubeconfig.OIDCConfig{
IDPIssuerURL: "https://accounts.google.com",
ClientID: "YOUR_CLIENT_ID",
@@ -42,7 +42,7 @@ func TestSetup_DoStage2(t *testing.T) {
CACertFilename: "/path/to/cert",
SkipTLSVerify: true,
}).
Return(&auth.Output{
Return(&authentication.Output{
IDToken: "YOUR_ID_TOKEN",
RefreshToken: "YOUR_REFRESH_TOKEN",
IDTokenSubject: "YOUR_SUBJECT",

View File

@@ -8,7 +8,7 @@ import (
"github.com/google/wire"
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig"
"github.com/int128/kubelogin/pkg/adaptors/logger"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"golang.org/x/xerrors"
)
@@ -48,7 +48,7 @@ See https://github.com/int128/kubelogin for more.
// Otherwise, update the kubeconfig.
//
type Standalone struct {
Authentication auth.Interface
Authentication authentication.Interface
Kubeconfig kubeconfig.Interface
Logger logger.Interface
}
@@ -67,7 +67,7 @@ func (u *Standalone) Do(ctx context.Context, in Input) error {
u.Logger.V(1).Infof("using the authentication provider of the user %s", authProvider.UserName)
u.Logger.V(1).Infof("a token will be written to %s", authProvider.LocationOfOrigin)
out, err := u.Authentication.Do(ctx, auth.Input{
out, err := u.Authentication.Do(ctx, authentication.Input{
OIDCConfig: authProvider.OIDCConfig,
SkipOpenBrowser: in.SkipOpenBrowser,
BindAddress: in.BindAddress,

View File

@@ -9,8 +9,8 @@ import (
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig"
"github.com/int128/kubelogin/pkg/adaptors/kubeconfig/mock_kubeconfig"
"github.com/int128/kubelogin/pkg/adaptors/logger/mock_logger"
"github.com/int128/kubelogin/pkg/usecases/auth"
"github.com/int128/kubelogin/pkg/usecases/auth/mock_auth"
"github.com/int128/kubelogin/pkg/usecases/authentication"
"github.com/int128/kubelogin/pkg/usecases/authentication/mock_authentication"
"golang.org/x/xerrors"
)
@@ -58,9 +58,9 @@ func TestStandalone_Do(t *testing.T) {
RefreshToken: "YOUR_REFRESH_TOKEN",
},
})
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{
Do(ctx, authentication.Input{
OIDCConfig: currentAuthProvider.OIDCConfig,
BindAddress: []string{"127.0.0.1:8000"},
SkipOpenBrowser: true,
@@ -69,7 +69,7 @@ func TestStandalone_Do(t *testing.T) {
CACertFilename: "/path/to/cert",
SkipTLSVerify: true,
}).
Return(&auth.Output{
Return(&authentication.Output{
IDToken: "YOUR_ID_TOKEN",
RefreshToken: "YOUR_REFRESH_TOKEN",
IDTokenExpiry: futureTime,
@@ -103,10 +103,10 @@ func TestStandalone_Do(t *testing.T) {
mockKubeconfig.EXPECT().
GetCurrentAuthProvider("", kubeconfig.ContextName(""), kubeconfig.UserName("")).
Return(currentAuthProvider, nil)
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Return(&auth.Output{
Do(ctx, authentication.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Return(&authentication.Output{
AlreadyHasValidIDToken: true,
IDToken: "VALID_ID_TOKEN",
IDTokenExpiry: futureTime,
@@ -131,7 +131,7 @@ func TestStandalone_Do(t *testing.T) {
mockKubeconfig.EXPECT().
GetCurrentAuthProvider("", kubeconfig.ContextName(""), kubeconfig.UserName("")).
Return(nil, xerrors.New("no oidc config"))
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
u := Standalone{
Authentication: mockAuthentication,
Kubeconfig: mockKubeconfig,
@@ -160,9 +160,9 @@ func TestStandalone_Do(t *testing.T) {
mockKubeconfig.EXPECT().
GetCurrentAuthProvider("", kubeconfig.ContextName(""), kubeconfig.UserName("")).
Return(currentAuthProvider, nil)
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Do(ctx, authentication.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Return(nil, xerrors.New("authentication error"))
u := Standalone{
Authentication: mockAuthentication,
@@ -205,10 +205,10 @@ func TestStandalone_Do(t *testing.T) {
},
}).
Return(xerrors.New("I/O error"))
mockAuthentication := mock_auth.NewMockInterface(ctrl)
mockAuthentication := mock_authentication.NewMockInterface(ctrl)
mockAuthentication.EXPECT().
Do(ctx, auth.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Return(&auth.Output{
Do(ctx, authentication.Input{OIDCConfig: currentAuthProvider.OIDCConfig}).
Return(&authentication.Output{
IDToken: "YOUR_ID_TOKEN",
RefreshToken: "YOUR_REFRESH_TOKEN",
IDTokenExpiry: futureTime,