Refactor app auth
This commit is contained in:
parent
b3e660d354
commit
5db1d00d64
4 changed files with 21 additions and 17 deletions
|
@ -1,6 +1,7 @@
|
||||||
package app
|
package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/mattermost/focalboard/server/auth"
|
||||||
"github.com/mattermost/focalboard/server/services/config"
|
"github.com/mattermost/focalboard/server/services/config"
|
||||||
"github.com/mattermost/focalboard/server/services/store"
|
"github.com/mattermost/focalboard/server/services/store"
|
||||||
"github.com/mattermost/focalboard/server/services/webhook"
|
"github.com/mattermost/focalboard/server/services/webhook"
|
||||||
|
@ -11,11 +12,26 @@ import (
|
||||||
type App struct {
|
type App struct {
|
||||||
config *config.Configuration
|
config *config.Configuration
|
||||||
store store.Store
|
store store.Store
|
||||||
|
auth *auth.Auth
|
||||||
wsServer *ws.Server
|
wsServer *ws.Server
|
||||||
filesBackend filesstore.FileBackend
|
filesBackend filesstore.FileBackend
|
||||||
webhook *webhook.Client
|
webhook *webhook.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(config *config.Configuration, store store.Store, wsServer *ws.Server, filesBackend filesstore.FileBackend, webhook *webhook.Client) *App {
|
func New(
|
||||||
return &App{config: config, store: store, wsServer: wsServer, filesBackend: filesBackend, webhook: webhook}
|
config *config.Configuration,
|
||||||
|
store store.Store,
|
||||||
|
auth *auth.Auth,
|
||||||
|
wsServer *ws.Server,
|
||||||
|
filesBackend filesstore.FileBackend,
|
||||||
|
webhook *webhook.Client,
|
||||||
|
) *App {
|
||||||
|
return &App{
|
||||||
|
config: config,
|
||||||
|
store: store,
|
||||||
|
auth: auth,
|
||||||
|
wsServer: wsServer,
|
||||||
|
filesBackend: filesBackend,
|
||||||
|
webhook: webhook,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package app
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/mattermost/focalboard/server/model"
|
"github.com/mattermost/focalboard/server/model"
|
||||||
|
@ -13,18 +12,7 @@ import (
|
||||||
|
|
||||||
// GetSession Get a user active session and refresh the session if is needed
|
// GetSession Get a user active session and refresh the session if is needed
|
||||||
func (a *App) GetSession(token string) (*model.Session, error) {
|
func (a *App) GetSession(token string) (*model.Session, error) {
|
||||||
if len(token) < 1 {
|
return a.auth.GetSession(token)
|
||||||
return nil, errors.New("no session token")
|
|
||||||
}
|
|
||||||
|
|
||||||
session, err := a.store.GetSession(token, a.config.SessionExpireTime)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "unable to get the session for the token")
|
|
||||||
}
|
|
||||||
if session.UpdateAt < (time.Now().Unix() - a.config.SessionRefreshTime) {
|
|
||||||
a.store.RefreshSession(session)
|
|
||||||
}
|
|
||||||
return session, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRegisteredUserCount returns the number of registered users
|
// GetRegisteredUserCount returns the number of registered users
|
||||||
|
|
|
@ -26,7 +26,7 @@ func TestGetParentID(t *testing.T) {
|
||||||
auth := auth.New(&cfg, store)
|
auth := auth.New(&cfg, store)
|
||||||
wsserver := ws.NewServer(auth, true)
|
wsserver := ws.NewServer(auth, true)
|
||||||
webhook := webhook.NewClient(&cfg)
|
webhook := webhook.NewClient(&cfg)
|
||||||
app := New(&cfg, store, wsserver, &mocks.FileBackend{}, webhook)
|
app := New(&cfg, store, auth, wsserver, &mocks.FileBackend{}, webhook)
|
||||||
|
|
||||||
t.Run("success query", func(t *testing.T) {
|
t.Run("success query", func(t *testing.T) {
|
||||||
store.EXPECT().GetParentID(gomock.Eq("test-id")).Return("test-parent-id", nil)
|
store.EXPECT().GetParentID(gomock.Eq("test-id")).Return("test-parent-id", nil)
|
||||||
|
|
|
@ -77,7 +77,7 @@ func New(cfg *config.Configuration, singleUser bool) (*Server, error) {
|
||||||
|
|
||||||
webhookClient := webhook.NewClient(cfg)
|
webhookClient := webhook.NewClient(cfg)
|
||||||
|
|
||||||
appBuilder := func() *app.App { return app.New(cfg, store, wsServer, filesBackend, webhookClient) }
|
appBuilder := func() *app.App { return app.New(cfg, store, auth, wsServer, filesBackend, webhookClient) }
|
||||||
api := api.NewAPI(appBuilder, singleUser)
|
api := api.NewAPI(appBuilder, singleUser)
|
||||||
|
|
||||||
// Local router for admin APIs
|
// Local router for admin APIs
|
||||||
|
|
Loading…
Reference in a new issue