Change NewUsersNotSuperAdmin to SuperAdminFirstUserOnly
parent
86b9c0d985
commit
6feba85807
|
@ -313,7 +313,7 @@ func (s *Service) newUsersAreSuperAdmin() bool {
|
||||||
if s.firstUser() {
|
if s.firstUser() {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return !s.NewUsersNotSuperAdmin
|
return !s.SuperAdminFirstUserOnly
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) usersOrganizations(ctx context.Context, u *chronograf.User) ([]chronograf.Organization, error) {
|
func (s *Service) usersOrganizations(ctx context.Context, u *chronograf.User) ([]chronograf.Organization, error) {
|
||||||
|
|
|
@ -21,11 +21,11 @@ type MockUsers struct{}
|
||||||
|
|
||||||
func TestService_Me(t *testing.T) {
|
func TestService_Me(t *testing.T) {
|
||||||
type fields struct {
|
type fields struct {
|
||||||
UsersStore chronograf.UsersStore
|
UsersStore chronograf.UsersStore
|
||||||
OrganizationsStore chronograf.OrganizationsStore
|
OrganizationsStore chronograf.OrganizationsStore
|
||||||
Logger chronograf.Logger
|
Logger chronograf.Logger
|
||||||
UseAuth bool
|
UseAuth bool
|
||||||
NewUsersNotSuperAdmin bool
|
SuperAdminFirstUserOnly bool
|
||||||
}
|
}
|
||||||
type args struct {
|
type args struct {
|
||||||
w *httptest.ResponseRecorder
|
w *httptest.ResponseRecorder
|
||||||
|
@ -47,9 +47,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
OrganizationsStore: &mocks.OrganizationsStore{
|
OrganizationsStore: &mocks.OrganizationsStore{
|
||||||
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
||||||
return &chronograf.Organization{
|
return &chronograf.Organization{
|
||||||
|
@ -179,9 +179,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: false,
|
SuperAdminFirstUserOnly: false,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
OrganizationsStore: &mocks.OrganizationsStore{
|
OrganizationsStore: &mocks.OrganizationsStore{
|
||||||
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
||||||
return &chronograf.Organization{
|
return &chronograf.Organization{
|
||||||
|
@ -235,9 +235,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
OrganizationsStore: &mocks.OrganizationsStore{
|
OrganizationsStore: &mocks.OrganizationsStore{
|
||||||
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
||||||
return &chronograf.Organization{
|
return &chronograf.Organization{
|
||||||
|
@ -291,9 +291,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
OrganizationsStore: &mocks.OrganizationsStore{
|
OrganizationsStore: &mocks.OrganizationsStore{
|
||||||
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
||||||
return &chronograf.Organization{
|
return &chronograf.Organization{
|
||||||
|
@ -347,8 +347,8 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
OrganizationsStore: &mocks.OrganizationsStore{
|
OrganizationsStore: &mocks.OrganizationsStore{
|
||||||
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
DefaultOrganizationF: func(ctx context.Context) (*chronograf.Organization, error) {
|
||||||
return &chronograf.Organization{
|
return &chronograf.Organization{
|
||||||
|
@ -396,9 +396,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: false,
|
UseAuth: false,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
},
|
},
|
||||||
wantStatus: http.StatusOK,
|
wantStatus: http.StatusOK,
|
||||||
wantContentType: "application/json",
|
wantContentType: "application/json",
|
||||||
|
@ -412,9 +412,9 @@ func TestService_Me(t *testing.T) {
|
||||||
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
r: httptest.NewRequest("GET", "http://example.com/foo", nil),
|
||||||
},
|
},
|
||||||
fields: fields{
|
fields: fields{
|
||||||
UseAuth: true,
|
UseAuth: true,
|
||||||
NewUsersNotSuperAdmin: true,
|
SuperAdminFirstUserOnly: true,
|
||||||
Logger: log.New(log.DebugLevel),
|
Logger: log.New(log.DebugLevel),
|
||||||
},
|
},
|
||||||
wantStatus: http.StatusUnprocessableEntity,
|
wantStatus: http.StatusUnprocessableEntity,
|
||||||
principal: oauth2.Principal{
|
principal: oauth2.Principal{
|
||||||
|
@ -476,9 +476,9 @@ func TestService_Me(t *testing.T) {
|
||||||
UsersStore: tt.fields.UsersStore,
|
UsersStore: tt.fields.UsersStore,
|
||||||
OrganizationsStore: tt.fields.OrganizationsStore,
|
OrganizationsStore: tt.fields.OrganizationsStore,
|
||||||
},
|
},
|
||||||
Logger: tt.fields.Logger,
|
Logger: tt.fields.Logger,
|
||||||
UseAuth: tt.fields.UseAuth,
|
UseAuth: tt.fields.UseAuth,
|
||||||
NewUsersNotSuperAdmin: tt.fields.NewUsersNotSuperAdmin,
|
SuperAdminFirstUserOnly: tt.fields.SuperAdminFirstUserOnly,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Me(tt.args.w, tt.args.r)
|
s.Me(tt.args.w, tt.args.r)
|
||||||
|
|
|
@ -52,13 +52,12 @@ type Server struct {
|
||||||
|
|
||||||
NewSources string `long:"new-sources" description:"Config for adding a new InfluxDB source and Kapacitor server, in JSON as an array of objects, and surrounded by single quotes. E.g. --new-sources='[{\"influxdb\":{\"name\":\"Influx 1\",\"username\":\"user1\",\"password\":\"pass1\",\"url\":\"http://localhost:8086\",\"metaUrl\":\"http://metaurl.com\",\"type\":\"influx-enterprise\",\"insecureSkipVerify\":false,\"default\":true,\"telegraf\":\"telegraf\",\"sharedSecret\":\"cubeapples\"},\"kapacitor\":{\"name\":\"Kapa 1\",\"url\":\"http://localhost:9092\",\"active\":true}}]'" env:"NEW_SOURCES" hidden:"true"`
|
NewSources string `long:"new-sources" description:"Config for adding a new InfluxDB source and Kapacitor server, in JSON as an array of objects, and surrounded by single quotes. E.g. --new-sources='[{\"influxdb\":{\"name\":\"Influx 1\",\"username\":\"user1\",\"password\":\"pass1\",\"url\":\"http://localhost:8086\",\"metaUrl\":\"http://metaurl.com\",\"type\":\"influx-enterprise\",\"insecureSkipVerify\":false,\"default\":true,\"telegraf\":\"telegraf\",\"sharedSecret\":\"cubeapples\"},\"kapacitor\":{\"name\":\"Kapa 1\",\"url\":\"http://localhost:9092\",\"active\":true}}]'" env:"NEW_SOURCES" hidden:"true"`
|
||||||
|
|
||||||
Develop bool `short:"d" long:"develop" description:"Run server in develop mode."`
|
Develop bool `short:"d" long:"develop" description:"Run server in develop mode."`
|
||||||
BoltPath string `short:"b" long:"bolt-path" description:"Full path to boltDB file (e.g. './chronograf-v1.db')" env:"BOLT_PATH" default:"chronograf-v1.db"`
|
BoltPath string `short:"b" long:"bolt-path" description:"Full path to boltDB file (e.g. './chronograf-v1.db')" env:"BOLT_PATH" default:"chronograf-v1.db"`
|
||||||
CannedPath string `short:"c" long:"canned-path" description:"Path to directory of pre-canned application layouts (/usr/share/chronograf/canned)" env:"CANNED_PATH" default:"canned"`
|
CannedPath string `short:"c" long:"canned-path" description:"Path to directory of pre-canned application layouts (/usr/share/chronograf/canned)" env:"CANNED_PATH" default:"canned"`
|
||||||
TokenSecret string `short:"t" long:"token-secret" description:"Secret to sign tokens" env:"TOKEN_SECRET"`
|
TokenSecret string `short:"t" long:"token-secret" description:"Secret to sign tokens" env:"TOKEN_SECRET"`
|
||||||
AuthDuration time.Duration `long:"auth-duration" default:"720h" description:"Total duration of cookie life for authentication (in hours). 0 means authentication expires on browser close." env:"AUTH_DURATION"`
|
AuthDuration time.Duration `long:"auth-duration" default:"720h" description:"Total duration of cookie life for authentication (in hours). 0 means authentication expires on browser close." env:"AUTH_DURATION"`
|
||||||
// TODO(desa): think of a better name
|
SuperAdminFirstUserOnly bool `long:"superadmin-first-user-only" description:"All new users will not be given the SuperAdmin status" env:"SUPERADMIN_FIRST_USER_ONLY"`
|
||||||
NewUsersNotSuperAdmin bool `long:"new-users-not-superadmin" description:"All new users will not be given the SuperAdmin status" env:"NEW_USERS_NOT_SUPERADMIN"`
|
|
||||||
|
|
||||||
GithubClientID string `short:"i" long:"github-client-id" description:"Github Client ID for OAuth 2 support" env:"GH_CLIENT_ID"`
|
GithubClientID string `short:"i" long:"github-client-id" description:"Github Client ID for OAuth 2 support" env:"GH_CLIENT_ID"`
|
||||||
GithubClientSecret string `short:"s" long:"github-client-secret" description:"Github Client Secret for OAuth 2 support" env:"GH_CLIENT_SECRET"`
|
GithubClientSecret string `short:"s" long:"github-client-secret" description:"Github Client Secret for OAuth 2 support" env:"GH_CLIENT_SECRET"`
|
||||||
|
@ -302,8 +301,7 @@ func (s *Server) Serve(ctx context.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
service := openService(ctx, s.BoltPath, layoutBuilder, sourcesBuilder, kapacitorBuilder, logger, s.useAuth())
|
service := openService(ctx, s.BoltPath, layoutBuilder, sourcesBuilder, kapacitorBuilder, logger, s.useAuth())
|
||||||
// TODO(desa): better name
|
service.SuperAdminFirstUserOnly = s.SuperAdminFirstUserOnly
|
||||||
service.NewUsersNotSuperAdmin = s.NewUsersNotSuperAdmin
|
|
||||||
if err := service.HandleNewSources(ctx, s.NewSources); err != nil {
|
if err := service.HandleNewSources(ctx, s.NewSources); err != nil {
|
||||||
logger.
|
logger.
|
||||||
WithField("component", "server").
|
WithField("component", "server").
|
||||||
|
|
|
@ -11,13 +11,12 @@ import (
|
||||||
|
|
||||||
// Service handles REST calls to the persistence
|
// Service handles REST calls to the persistence
|
||||||
type Service struct {
|
type Service struct {
|
||||||
Store DataStore
|
Store DataStore
|
||||||
TimeSeriesClient TimeSeriesClient
|
TimeSeriesClient TimeSeriesClient
|
||||||
Logger chronograf.Logger
|
Logger chronograf.Logger
|
||||||
UseAuth bool
|
UseAuth bool
|
||||||
// TODO(desa): better name
|
SuperAdminFirstUserOnly bool
|
||||||
NewUsersNotSuperAdmin bool
|
Databases chronograf.Databases
|
||||||
Databases chronograf.Databases
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TimeSeriesClient returns the correct client for a time series database.
|
// TimeSeriesClient returns the correct client for a time series database.
|
||||||
|
|
Loading…
Reference in New Issue