Skip to content

Commit

Permalink
feat: use the new tenant user handler (#18190)
Browse files Browse the repository at this point in the history
Switch to use the new user handler. We have been using the tenant backend for some
time now and just need to switch over to using tenant front to back.
  • Loading branch information
lyondhill authored May 27, 2020
1 parent 0770046 commit 97dc4d1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 90 deletions.
37 changes: 15 additions & 22 deletions cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,6 @@ func buildLauncherCommand(l *Launcher, cmd *cobra.Command) {
Default: "",
Desc: "TLS key for HTTPs",
},
{
DestP: &l.enableNewMetaStore,
Flag: "new-meta-store",
Default: true,
Desc: "enables the new meta store",
},
{
DestP: &l.noTasks,
Flag: "no-tasks",
Expand Down Expand Up @@ -340,8 +334,6 @@ type Launcher struct {
enginePath string
secretStore string

enableNewMetaStore bool

featureFlags map[string]string

// Query options.
Expand Down Expand Up @@ -588,12 +580,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
m.reg.MustRegister(m.boltClient)

var (
userSvc platform.UserService = m.kvService
orgSvc platform.OrganizationService = m.kvService
userResourceSvc platform.UserResourceMappingService = m.kvService
bucketSvc platform.BucketService = m.kvService
passwdsSvc platform.PasswordsService = m.kvService

authSvc platform.AuthorizationService = m.kvService
variableSvc platform.VariableService = m.kvService
sourceSvc platform.SourceService = m.kvService
Expand All @@ -615,15 +601,15 @@ func (m *Launcher) run(ctx context.Context) (err error) {
m.log.Error("Failed creating new meta store", zap.Error(err))
return err
}
ts := tenant.NewService(store)

if m.enableNewMetaStore {
ts := tenant.NewService(store)
userSvc = tenant.NewUserLogger(m.log.With(zap.String("store", "new")), tenant.NewUserMetrics(m.reg, ts, metric.WithSuffix("new")))
orgSvc = tenant.NewOrgLogger(m.log.With(zap.String("store", "new")), tenant.NewOrgMetrics(m.reg, ts, metric.WithSuffix("new")))
userResourceSvc = tenant.NewURMLogger(m.log.With(zap.String("store", "new")), tenant.NewUrmMetrics(m.reg, ts, metric.WithSuffix("new")))
bucketSvc = tenant.NewBucketLogger(m.log.With(zap.String("store", "new")), tenant.NewBucketMetrics(m.reg, ts, metric.WithSuffix("new")))
passwdsSvc = tenant.NewPasswordLogger(m.log.With(zap.String("store", "new")), tenant.NewPasswordMetrics(m.reg, ts, metric.WithSuffix("new")))
}
var (
userSvc platform.UserService = tenant.NewUserLogger(m.log.With(zap.String("store", "new")), tenant.NewUserMetrics(m.reg, ts, metric.WithSuffix("new")))
orgSvc platform.OrganizationService = tenant.NewOrgLogger(m.log.With(zap.String("store", "new")), tenant.NewOrgMetrics(m.reg, ts, metric.WithSuffix("new")))
userResourceSvc platform.UserResourceMappingService = tenant.NewURMLogger(m.log.With(zap.String("store", "new")), tenant.NewUrmMetrics(m.reg, ts, metric.WithSuffix("new")))
bucketSvc platform.BucketService = tenant.NewBucketLogger(m.log.With(zap.String("store", "new")), tenant.NewBucketMetrics(m.reg, ts, metric.WithSuffix("new")))
passwdsSvc platform.PasswordsService = tenant.NewPasswordLogger(m.log.With(zap.String("store", "new")), tenant.NewPasswordMetrics(m.reg, ts, metric.WithSuffix("new")))
)

switch m.secretStore {
case "bolt":
Expand Down Expand Up @@ -966,6 +952,11 @@ func (m *Launcher) run(ctx context.Context) (err error) {
pkgHTTPServer = pkger.NewHTTPServer(pkgServerLogger, pkgSVC)
}

var userHTTPServer *tenant.UserHandler
{
userHTTPServer = tenant.NewHTTPUserHandler(m.log.With(zap.String("handler", "user")), tenant.NewAuthedUserService(userSvc), tenant.NewAuthedPasswordService(passwdsSvc))
}

var onboardHTTPServer *tenant.OnboardHandler
{
onboardSvc := tenant.NewOnboardService(store, authSvc) // basic service
Expand Down Expand Up @@ -1014,6 +1005,8 @@ func (m *Launcher) run(ctx context.Context) (err error) {
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())),
http.WithResourceHandler(userHTTPServer.MeResourceHandler()),
http.WithResourceHandler(userHTTPServer.UserResourceHandler()),
)

httpLogger := m.log.With(zap.String("service", "http"))
Expand Down
62 changes: 0 additions & 62 deletions cmd/influxd/launcher/tenant_test.go

This file was deleted.

6 changes: 0 additions & 6 deletions http/api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,6 @@ func NewAPIHandler(b *APIBackend, opts ...APIHandlerOptFn) *APIHandler {
h.Mount(prefixTelegrafPlugins, NewTelegrafHandler(b.Logger, telegrafBackend))
h.Mount(prefixTelegraf, NewTelegrafHandler(b.Logger, telegrafBackend))

userBackend := NewUserBackend(b.Logger.With(zap.String("handler", "user")), b)
userBackend.UserService = authorizer.NewUserService(b.UserService)
userBackend.PasswordsService = authorizer.NewPasswordService(b.PasswordsService)
userHandler := NewUserHandler(b.Logger, userBackend)
h.Mount(prefixMe, userHandler)
h.Mount(prefixUsers, userHandler)
h.Mount("/api/v2/flags", b.FlagsHandler)

variableBackend := NewVariableBackend(b.Logger.With(zap.String("handler", "variable")), b)
Expand Down
3 changes: 3 additions & 0 deletions tenant/http_server_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ type resourceHandler struct {
*UserHandler
}

func (h *resourceHandler) Prefix() string {
return h.prefix
}
func (h *UserHandler) MeResourceHandler() *resourceHandler {
return &resourceHandler{prefix: prefixMe, UserHandler: h}
}
Expand Down

0 comments on commit 97dc4d1

Please sign in to comment.