feat: integrate the new session system behind a feature flag (#18042)
parent
9eb180b6c7
commit
c459852f8f
|
@ -43,6 +43,7 @@ import (
|
|||
"github.com/influxdata/influxdb/v2/query"
|
||||
"github.com/influxdata/influxdb/v2/query/control"
|
||||
"github.com/influxdata/influxdb/v2/query/stdlib/influxdata/influxdb"
|
||||
"github.com/influxdata/influxdb/v2/session"
|
||||
"github.com/influxdata/influxdb/v2/snowflake"
|
||||
"github.com/influxdata/influxdb/v2/source"
|
||||
"github.com/influxdata/influxdb/v2/storage"
|
||||
|
@ -595,7 +596,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
|
|||
authSvc platform.AuthorizationService = m.kvService
|
||||
variableSvc platform.VariableService = m.kvService
|
||||
sourceSvc platform.SourceService = m.kvService
|
||||
sessionSvc platform.SessionService = m.kvService
|
||||
dashboardSvc platform.DashboardService = m.kvService
|
||||
dashboardLogSvc platform.DashboardOperationLogService = m.kvService
|
||||
userLogSvc platform.UserOperationLogService = m.kvService
|
||||
|
@ -872,6 +872,14 @@ func (m *Launcher) run(ctx context.Context) (err error) {
|
|||
flagger = f
|
||||
}
|
||||
|
||||
var sessionSvc platform.SessionService
|
||||
{
|
||||
sessionSvc = session.NewService(session.NewStorage(inmem.NewSessionStore()), userSvc, userResourceSvc, authSvc, time.Duration(m.sessionLength)*time.Minute)
|
||||
sessionSvc = session.NewSessionMetrics(m.reg, sessionSvc)
|
||||
sessionSvc = session.NewSessionLogger(m.log.With(zap.String("service", "session")), sessionSvc)
|
||||
sessionSvc = session.NewServiceController(flagger, m.kvService, sessionSvc)
|
||||
}
|
||||
|
||||
m.apibackend = &http.APIBackend{
|
||||
AssetsPath: m.assetsPath,
|
||||
HTTPErrorHandler: kithttp.ErrorHandler(0),
|
||||
|
@ -991,8 +999,21 @@ func (m *Launcher) run(ctx context.Context) (err error) {
|
|||
authHTTPServer = kithttp.NewFeatureHandler(feature.NewAuthPackage(), flagger, oldHandler, newHandler, newHandler.Prefix())
|
||||
}
|
||||
|
||||
var oldSessionHandler nethttp.Handler
|
||||
var sessionHTTPServer *session.SessionHandler
|
||||
{
|
||||
platformHandler := http.NewPlatformHandler(m.apibackend, http.WithResourceHandler(pkgHTTPServer), http.WithResourceHandler(onboardHTTPServer), http.WithResourceHandler(authHTTPServer))
|
||||
oldSessionHandler = http.NewSessionHandler(m.log.With(zap.String("handler", "old_session")), http.NewSessionBackend(m.log, m.apibackend))
|
||||
sessionHTTPServer = session.NewSessionHandler(m.log.With(zap.String("handler", "session")), sessionSvc, userSvc, passwdsSvc)
|
||||
}
|
||||
|
||||
{
|
||||
platformHandler := http.NewPlatformHandler(m.apibackend,
|
||||
http.WithResourceHandler(pkgHTTPServer),
|
||||
http.WithResourceHandler(onboardHTTPServer),
|
||||
http.WithResourceHandler(authHTTPServer),
|
||||
http.WithResourceHandler(kithttp.NewFeatureHandler(feature.SessionService(), flagger, oldSessionHandler, sessionHTTPServer.SignInResourceHandler(), sessionHTTPServer.SignInResourceHandler().Prefix())),
|
||||
http.WithResourceHandler(kithttp.NewFeatureHandler(feature.SessionService(), flagger, oldSessionHandler, sessionHTTPServer.SignOutResourceHandler(), sessionHTTPServer.SignOutResourceHandler().Prefix())),
|
||||
)
|
||||
|
||||
httpLogger := m.log.With(zap.String("service", "http"))
|
||||
m.httpServer.Handler = http.NewHandlerFromRegistry(
|
||||
|
|
|
@ -33,3 +33,10 @@
|
|||
default: false
|
||||
contact: Alirie Gray
|
||||
lifetime: temporary
|
||||
|
||||
- name: Session Service
|
||||
description: A temporary switching system for the new session system
|
||||
key: sessionService
|
||||
default: false
|
||||
contact: Lyon Hill
|
||||
expose: true
|
||||
|
|
|
@ -177,11 +177,6 @@ func NewAPIHandler(b *APIBackend, opts ...APIHandlerOptFn) *APIHandler {
|
|||
b.OrganizationService)
|
||||
h.Mount(prefixTargets, NewScraperHandler(b.Logger, scraperBackend))
|
||||
|
||||
sessionBackend := newSessionBackend(b.Logger.With(zap.String("handler", "session")), b)
|
||||
sessionHandler := NewSessionHandler(b.Logger, sessionBackend)
|
||||
h.Mount(prefixSignIn, sessionHandler)
|
||||
h.Mount(prefixSignOut, sessionHandler)
|
||||
|
||||
sourceBackend := NewSourceBackend(b.Logger.With(zap.String("handler", "source")), b)
|
||||
sourceBackend.SourceService = authorizer.NewSourceService(b.SourceService)
|
||||
sourceBackend.BucketService = authorizer.NewBucketService(b.BucketService, noAuthUserResourceMappingService)
|
||||
|
|
|
@ -25,8 +25,8 @@ type SessionBackend struct {
|
|||
UserService platform.UserService
|
||||
}
|
||||
|
||||
// newSessionBackend creates a new SessionBackend with associated logger.
|
||||
func newSessionBackend(log *zap.Logger, b *APIBackend) *SessionBackend {
|
||||
// NewSessionBackend creates a new SessionBackend with associated logger.
|
||||
func NewSessionBackend(log *zap.Logger, b *APIBackend) *SessionBackend {
|
||||
return &SessionBackend{
|
||||
HTTPErrorHandler: b.HTTPErrorHandler,
|
||||
log: log,
|
||||
|
|
|
@ -44,14 +44,30 @@ func NewAuthPackage() BoolFlag {
|
|||
return newAuth
|
||||
}
|
||||
|
||||
var sessionService = MakeBoolFlag(
|
||||
"Session Service",
|
||||
"sessionService",
|
||||
"Lyon Hill",
|
||||
false,
|
||||
Temporary,
|
||||
true,
|
||||
)
|
||||
|
||||
// SessionService - A temporary switching system for the new session system
|
||||
func SessionService() BoolFlag {
|
||||
return sessionService
|
||||
}
|
||||
|
||||
var all = []Flag{
|
||||
backendExample,
|
||||
frontendExample,
|
||||
newAuth,
|
||||
sessionService,
|
||||
}
|
||||
|
||||
var byKey = map[string]Flag{
|
||||
"backendExample": backendExample,
|
||||
"frontendExample": frontendExample,
|
||||
"newAuth": newAuth,
|
||||
"sessionService": sessionService,
|
||||
}
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
package session
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/kit/feature"
|
||||
)
|
||||
|
||||
var _ influxdb.SessionService = (*ServiceController)(nil)
|
||||
|
||||
// ServiceController is a temporary switching mechanism to allow
|
||||
// a safe rollout of the new session service
|
||||
type ServiceController struct {
|
||||
flagger feature.Flagger
|
||||
oldSessionService influxdb.SessionService
|
||||
newSessionService influxdb.SessionService
|
||||
}
|
||||
|
||||
func NewServiceController(flagger feature.Flagger, oldSessionService influxdb.SessionService, newSessionService influxdb.SessionService) *ServiceController {
|
||||
return &ServiceController{
|
||||
flagger: flagger,
|
||||
oldSessionService: oldSessionService,
|
||||
newSessionService: newSessionService,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ServiceController) useNew(ctx context.Context) bool {
|
||||
return feature.SessionService().Enabled(ctx, s.flagger)
|
||||
}
|
||||
|
||||
func (s *ServiceController) FindSession(ctx context.Context, key string) (*influxdb.Session, error) {
|
||||
if s.useNew(ctx) {
|
||||
return s.newSessionService.FindSession(ctx, key)
|
||||
}
|
||||
return s.oldSessionService.FindSession(ctx, key)
|
||||
}
|
||||
|
||||
func (s *ServiceController) ExpireSession(ctx context.Context, key string) error {
|
||||
if s.useNew(ctx) {
|
||||
return s.newSessionService.ExpireSession(ctx, key)
|
||||
}
|
||||
return s.oldSessionService.ExpireSession(ctx, key)
|
||||
}
|
||||
|
||||
func (s *ServiceController) CreateSession(ctx context.Context, user string) (*influxdb.Session, error) {
|
||||
if s.useNew(ctx) {
|
||||
return s.newSessionService.CreateSession(ctx, user)
|
||||
}
|
||||
return s.oldSessionService.CreateSession(ctx, user)
|
||||
}
|
||||
|
||||
func (s *ServiceController) RenewSession(ctx context.Context, session *influxdb.Session, newExpiration time.Time) error {
|
||||
if s.useNew(ctx) {
|
||||
return s.newSessionService.RenewSession(ctx, session, newExpiration)
|
||||
}
|
||||
return s.oldSessionService.RenewSession(ctx, session, newExpiration)
|
||||
}
|
Loading…
Reference in New Issue