From 57a445c668bbf5bba32dcf7298c6a21f6bdb6568 Mon Sep 17 00:00:00 2001 From: Salaton Date: Thu, 26 Aug 2021 09:51:45 +0300 Subject: [PATCH] chore: purge login service implementation (#101) --- pkg/onboarding/application/extension/base.go | 27 ---------- .../extension/mock/extension_mock.go | 24 --------- .../login_service/mock/service_mock.go | 34 ------------- .../services/login_service/service.go | 49 ------------------- pkg/onboarding/presentation/config.go | 28 ----------- 5 files changed, 162 deletions(-) delete mode 100644 pkg/onboarding/infrastructure/services/login_service/mock/service_mock.go delete mode 100644 pkg/onboarding/infrastructure/services/login_service/service.go diff --git a/pkg/onboarding/application/extension/base.go b/pkg/onboarding/application/extension/base.go index d4bb7b45..eb7e5fd6 100644 --- a/pkg/onboarding/application/extension/base.go +++ b/pkg/onboarding/application/extension/base.go @@ -84,12 +84,6 @@ type BaseExtension interface { source interface{}, status int, ) - - // Login - GetLoginFunc(ctx context.Context) http.HandlerFunc - GetLogoutFunc(ctx context.Context) http.HandlerFunc - GetRefreshFunc() http.HandlerFunc - GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc } // BaseExtensionImpl ... @@ -166,27 +160,6 @@ func (b *BaseExtensionImpl) GetEnvVar(envName string) (string, error) { return serverutils.GetEnvVar(envName) } -// GetLoginFunc returns a function that can authenticate against both Slade 360 and Firebase -func (b *BaseExtensionImpl) GetLoginFunc(ctx context.Context) http.HandlerFunc { - return apiclient.GetLoginFunc(ctx, b.fc) -} - -// GetLogoutFunc logs the user out of Firebase -func (b *BaseExtensionImpl) GetLogoutFunc(ctx context.Context) http.HandlerFunc { - return apiclient.GetLogoutFunc(ctx, b.fc) -} - -// GetRefreshFunc is used to refresh OAuth tokens -func (b *BaseExtensionImpl) GetRefreshFunc() http.HandlerFunc { - return apiclient.GetRefreshFunc() -} - -// GetVerifyTokenFunc confirms that an EDI access token (supplied) is valid. -// If it is valid, it exchanges it for a Firebase ID token. -func (b *BaseExtensionImpl) GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc { - return apiclient.GetVerifyTokenFunc(ctx, b.fc) -} - // NewServerClient ... func (b *BaseExtensionImpl) NewServerClient( clientID string, diff --git a/pkg/onboarding/application/extension/mock/extension_mock.go b/pkg/onboarding/application/extension/mock/extension_mock.go index ed7dfee7..58dbbd8c 100644 --- a/pkg/onboarding/application/extension/mock/extension_mock.go +++ b/pkg/onboarding/application/extension/mock/extension_mock.go @@ -77,10 +77,6 @@ type FakeBaseExtensionImpl struct { source interface{}, status int, ) - GetLoginFuncFn func(ctx context.Context) http.HandlerFunc - GetLogoutFuncFn func(ctx context.Context) http.HandlerFunc - GetRefreshFuncFn func() http.HandlerFunc - GetVerifyTokenFuncFn func(ctx context.Context) http.HandlerFunc GetUserProfileByPrimaryPhoneNumberFn func(ctx context.Context, phone string, suspended bool) (*profileutils.UserProfile, error) } @@ -130,26 +126,6 @@ func (b *FakeBaseExtensionImpl) GetEnvVar(envName string) (string, error) { return b.GetEnvVarFn(envName) } -// GetLoginFunc .. -func (b *FakeBaseExtensionImpl) GetLoginFunc(ctx context.Context) http.HandlerFunc { - return b.GetLoginFuncFn(ctx) -} - -// GetLogoutFunc .. -func (b *FakeBaseExtensionImpl) GetLogoutFunc(ctx context.Context) http.HandlerFunc { - return b.GetLogoutFuncFn(ctx) -} - -// GetRefreshFunc .. -func (b *FakeBaseExtensionImpl) GetRefreshFunc() http.HandlerFunc { - return b.GetRefreshFuncFn() -} - -// GetVerifyTokenFunc .. -func (b *FakeBaseExtensionImpl) GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc { - return b.GetVerifyTokenFuncFn(ctx) -} - // NewServerClient ... func (b *FakeBaseExtensionImpl) NewServerClient( clientID string, diff --git a/pkg/onboarding/infrastructure/services/login_service/mock/service_mock.go b/pkg/onboarding/infrastructure/services/login_service/mock/service_mock.go deleted file mode 100644 index c1e36d10..00000000 --- a/pkg/onboarding/infrastructure/services/login_service/mock/service_mock.go +++ /dev/null @@ -1,34 +0,0 @@ -package mock - -import ( - "context" - "net/http" -) - -// FakeServiceLogin .. -type FakeServiceLogin struct { - GetLoginFuncFn func(ctx context.Context) http.HandlerFunc - GetLogoutFuncFn func(ctx context.Context) http.HandlerFunc - GetRefreshFuncFn func() http.HandlerFunc - GetVerifyTokenFuncFn func(ctx context.Context) http.HandlerFunc -} - -// GetLoginFunc ... -func (l *FakeServiceLogin) GetLoginFunc(ctx context.Context) http.HandlerFunc { - return l.GetLoginFuncFn(ctx) -} - -// GetLogoutFunc ... -func (l *FakeServiceLogin) GetLogoutFunc(ctx context.Context) http.HandlerFunc { - return l.GetLogoutFuncFn(ctx) -} - -// GetRefreshFunc ... -func (l *FakeServiceLogin) GetRefreshFunc() http.HandlerFunc { - return l.GetRefreshFuncFn() -} - -// GetVerifyTokenFunc ... -func (l *FakeServiceLogin) GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc { - return l.GetVerifyTokenFuncFn(ctx) -} diff --git a/pkg/onboarding/infrastructure/services/login_service/service.go b/pkg/onboarding/infrastructure/services/login_service/service.go deleted file mode 100644 index 124c1788..00000000 --- a/pkg/onboarding/infrastructure/services/login_service/service.go +++ /dev/null @@ -1,49 +0,0 @@ -package loginservice - -import ( - "context" - "net/http" - - "github.com/savannahghi/onboarding/pkg/onboarding/application/extension" -) - -// ServiceLogin represents external login service logic -type ServiceLogin interface { - GetLoginFunc(ctx context.Context) http.HandlerFunc - GetLogoutFunc(ctx context.Context) http.HandlerFunc - GetRefreshFunc() http.HandlerFunc - GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc -} - -// ServiceLoginImpl represents the service implementation object -type ServiceLoginImpl struct { - baseExt extension.BaseExtension -} - -// NewServiceLogin initializes a new login service -func NewServiceLogin(ext extension.BaseExtension) ServiceLogin { - return &ServiceLoginImpl{ - baseExt: ext, - } -} - -// GetLoginFunc returns a function that can authenticate against both Slade 360 and Firebase -func (l ServiceLoginImpl) GetLoginFunc(ctx context.Context) http.HandlerFunc { - return l.baseExt.GetLoginFunc(ctx) -} - -// GetLogoutFunc logs the user out of Firebase -func (l ServiceLoginImpl) GetLogoutFunc(ctx context.Context) http.HandlerFunc { - return l.baseExt.GetLogoutFunc(ctx) -} - -// GetRefreshFunc is used to refresh OAuth tokens -func (l ServiceLoginImpl) GetRefreshFunc() http.HandlerFunc { - return l.baseExt.GetRefreshFunc() -} - -// GetVerifyTokenFunc confirms that an EDI access token (supplied) is valid. -// If it is valid, it exchanges it for a Firebase ID token. -func (l ServiceLoginImpl) GetVerifyTokenFunc(ctx context.Context) http.HandlerFunc { - return l.baseExt.GetVerifyTokenFunc(ctx) -} diff --git a/pkg/onboarding/presentation/config.go b/pkg/onboarding/presentation/config.go index 9ea418c7..feed47db 100644 --- a/pkg/onboarding/presentation/config.go +++ b/pkg/onboarding/presentation/config.go @@ -19,7 +19,6 @@ import ( "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/database/fb" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/engagement" - loginservice "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/login_service" "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/messaging" pubsubmessaging "github.com/savannahghi/onboarding/pkg/onboarding/infrastructure/services/pubsub" "github.com/savannahghi/onboarding/pkg/onboarding/repository" @@ -138,7 +137,6 @@ func Router(ctx context.Context) (*mux.Router, error) { } h := rest.NewHandlersInterfaces(i) - loginService := loginservice.NewServiceLogin(baseExt) r := mux.NewRouter() // gorilla mux r.Use(otelmux.Middleware(serverutils.MetricsCollectorService("onboarding"))) @@ -161,32 +159,6 @@ func Router(ctx context.Context) (*mux.Router, error) { h.SwitchFlaggedFeaturesHandler(), ) - // login service routes - r.Path("/login").Methods( - http.MethodPost, - http.MethodOptions, - ).HandlerFunc( - loginService.GetLoginFunc(ctx), - ) - r.Path("/logout").Methods( - http.MethodPost, - http.MethodOptions, - ).HandlerFunc( - loginService.GetLogoutFunc(ctx), - ) - r.Path("/refresh").Methods( - http.MethodPost, - http.MethodOptions, - ).HandlerFunc( - loginService.GetRefreshFunc(), - ) - r.Path("/verify_access_token").Methods( - http.MethodPost, - http.MethodOptions, - ).HandlerFunc( - loginService.GetVerifyTokenFunc(ctx), - ) - r.Path("/pubsub").Methods( http.MethodPost). HandlerFunc(pubSub.ReceivePubSubPushMessages)