feat: use the new tenant user handler (#18190)
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.pull/18250/head
parent
0770046659
commit
97dc4d18db
|
@ -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",
|
||||
|
@ -340,8 +334,6 @@ type Launcher struct {
|
|||
enginePath string
|
||||
secretStore string
|
||||
|
||||
enableNewMetaStore bool
|
||||
|
||||
featureFlags map[string]string
|
||||
|
||||
// Query options.
|
||||
|
@ -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
|
||||
|
@ -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":
|
||||
|
@ -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
|
||||
|
@ -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"))
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
package launcher_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/influxdata/influxdb/v2"
|
||||
"github.com/influxdata/influxdb/v2/cmd/influxd/launcher"
|
||||
icontext "github.com/influxdata/influxdb/v2/context"
|
||||
)
|
||||
|
||||
func testTenant(t *testing.T, args ...string) {
|
||||
l := launcher.RunTestLauncherOrFail(t, ctx, args...)
|
||||
l.SetupOrFail(t)
|
||||
defer l.ShutdownOrFail(t, ctx)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = icontext.SetAuthorizer(ctx, l.Auth)
|
||||
|
||||
o := &influxdb.Organization{Name: "a-org"}
|
||||
if err := l.OrganizationService().CreateOrganization(ctx, o); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
u := &influxdb.User{Name: "a-user"}
|
||||
if err := l.UserService().CreateUser(ctx, u); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := l.BucketService(t).CreateBucket(ctx, &influxdb.Bucket{Name: "a-bucket", OrgID: o.ID}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if err := l.UserResourceMappingService().CreateUserResourceMapping(ctx, &influxdb.UserResourceMapping{
|
||||
UserID: u.ID,
|
||||
UserType: influxdb.Owner,
|
||||
ResourceType: influxdb.OrgsResourceType,
|
||||
ResourceID: o.ID,
|
||||
}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if _, _, err := l.BucketService(t).FindBuckets(ctx, influxdb.BucketFilter{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, _, err := l.OrganizationService().FindOrganizations(ctx, influxdb.OrganizationFilter{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, _, err := l.UserService().FindUsers(ctx, influxdb.UserFilter{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
if _, _, err := l.UserResourceMappingService().FindUserResourceMappings(ctx, influxdb.UserResourceMappingFilter{}); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Tenant(t *testing.T) {
|
||||
t.Run("tenant service", func(t *testing.T) {
|
||||
testTenant(t)
|
||||
})
|
||||
|
||||
t.Run("duplicate read tenant service", func(t *testing.T) {
|
||||
testTenant(t, "--new-meta-store")
|
||||
})
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue