Refactor data stores into a common interface

pull/10616/head
Michael Desa 2017-10-31 16:41:17 -04:00
parent 7ae4481178
commit 36e14cb111
31 changed files with 477 additions and 291 deletions

46
mocks/store.go Normal file
View File

@ -0,0 +1,46 @@
package mocks
import (
"context"
"github.com/influxdata/chronograf"
)
// Store is a server.DataStore
type Store struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
OrganizationsStore chronograf.OrganizationsStore
}
func (s *Store) Sources(ctx context.Context) chronograf.SourcesStore {
return s.SourcesStore
}
func (s *Store) Servers(ctx context.Context) chronograf.ServersStore {
return s.ServersStore
}
func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore {
return s.LayoutsStore
}
func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
return s.UsersStore
}
// TODO: remove me and put logic into Users Call
func (s *Store) RawUsers(ctx context.Context) chronograf.UsersStore {
return s.UsersStore
}
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
return s.OrganizationsStore
}
func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
return s.DashboardsStore
}

View File

@ -52,8 +52,7 @@ func AuthorizedToken(auth oauth2.Authenticator, logger chronograf.Logger, next h
// name and provider. If the user is found, we verify that the user has at at
// least the role supplied.
func AuthorizedUser(
usersStore chronograf.UsersStore,
organizationsStore chronograf.OrganizationsStore,
store DataStore,
useAuth bool,
role string,
logger chronograf.Logger,
@ -98,7 +97,7 @@ func AuthorizedUser(
Error(w, http.StatusUnauthorized, "User is not authorized", logger)
return
}
_, err = organizationsStore.Get(ctx, chronograf.OrganizationQuery{ID: &orgID})
_, err = store.Organizations(ctx).Get(ctx, chronograf.OrganizationQuery{ID: &orgID})
if err != nil {
log.Error("Failed to retrieve organization from organizations store")
Error(w, http.StatusUnauthorized, "User is not authorized", logger)
@ -106,7 +105,7 @@ func AuthorizedUser(
}
ctx = context.WithValue(ctx, "organizationID", p.Organization)
u, err := usersStore.Get(ctx, chronograf.UserQuery{
u, err := store.Users(ctx).Get(ctx, chronograf.UserQuery{
Name: &p.Subject,
Provider: &p.Issuer,
Scheme: &scheme,

View File

@ -108,7 +108,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.ViewerRole,
{
Name: server.ViewerRoleName,
Organization: "1337",
},
},
}, nil
},
@ -152,7 +155,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.EditorRole,
{
Name: server.EditorRoleName,
Organization: "1337",
},
},
}, nil
},
@ -196,7 +202,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -240,7 +249,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.ViewerRole,
{
Name: server.ViewerRoleName,
Organization: "1337",
},
},
}, nil
},
@ -284,7 +296,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.EditorRole,
{
Name: server.EditorRoleName,
Organization: "1337",
},
},
}, nil
},
@ -328,7 +343,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -372,7 +390,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.ViewerRole,
{
Name: server.ViewerRoleName,
Organization: "1337",
},
},
}, nil
},
@ -416,7 +437,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.EditorRole,
{
Name: server.EditorRoleName,
Organization: "1337",
},
},
}, nil
},
@ -460,7 +484,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -768,7 +795,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -808,7 +838,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -851,7 +884,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -895,7 +931,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
},
@ -946,7 +985,10 @@ func TestAuthorizedUser(t *testing.T) {
Provider: "google",
Scheme: "oauth2",
Roles: []chronograf.Role{
server.AdminRole,
{
Name: server.AdminRoleName,
Organization: "1337",
},
},
}, nil
default:
@ -988,8 +1030,10 @@ func TestAuthorizedUser(t *testing.T) {
authorized = true
}
fn := server.AuthorizedUser(
tt.fields.UsersStore,
tt.fields.OrganizationsStore,
&server.Store{
UsersStore: tt.fields.UsersStore,
OrganizationsStore: tt.fields.OrganizationsStore,
},
tt.args.useAuth,
tt.args.role,
tt.fields.Logger,

View File

@ -135,7 +135,7 @@ func (s *Service) DashboardCells(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
e, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
e, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -155,7 +155,7 @@ func (s *Service) NewDashboardCell(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -181,7 +181,7 @@ func (s *Service) NewDashboardCell(w http.ResponseWriter, r *http.Request) {
cell.ID = cid
dash.Cells = append(dash.Cells, cell)
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error adding cell %s to dashboard %d: %v", cid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -205,7 +205,7 @@ func (s *Service) DashboardCellID(w http.ResponseWriter, r *http.Request) {
return
}
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -231,7 +231,7 @@ func (s *Service) RemoveDashboardCell(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -251,7 +251,7 @@ func (s *Service) RemoveDashboardCell(w http.ResponseWriter, r *http.Request) {
}
dash.Cells = append(dash.Cells[:cellid], dash.Cells[cellid+1:]...)
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error removing cell %s from dashboard %d: %v", cid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -268,7 +268,7 @@ func (s *Service) ReplaceDashboardCell(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -300,7 +300,7 @@ func (s *Service) ReplaceDashboardCell(w http.ResponseWriter, r *http.Request) {
cell.ID = cid
dash.Cells[cellid] = cell
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error updating cell %s in dashboard %d: %v", cid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return

View File

@ -228,14 +228,16 @@ func Test_Service_DashboardCells(t *testing.T) {
// setup mock DashboardCells store and logger
tlog := &mocks.TestLogger{}
svc := &server.Service{
DashboardsStore: &mocks.DashboardsStore{
GetF: func(ctx context.Context, id chronograf.DashboardID) (chronograf.Dashboard, error) {
return chronograf.Dashboard{
ID: chronograf.DashboardID(1),
Cells: test.mockResponse,
Templates: []chronograf.Template{},
Name: "empty dashboard",
}, nil
Store: &mocks.Store{
DashboardsStore: &mocks.DashboardsStore{
GetF: func(ctx context.Context, id chronograf.DashboardID) (chronograf.Dashboard, error) {
return chronograf.Dashboard{
ID: chronograf.DashboardID(1),
Cells: test.mockResponse,
Templates: []chronograf.Template{},
Name: "empty dashboard",
}, nil
},
},
},
Logger: tlog,

View File

@ -49,7 +49,7 @@ func newDashboardResponse(d chronograf.Dashboard) *dashboardResponse {
// Dashboards returns all dashboards within the store
func (s *Service) Dashboards(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
dashboards, err := s.DashboardsStore.All(ctx)
dashboards, err := s.Store.Dashboards(ctx).All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading dashboards", s.Logger)
return
@ -74,7 +74,7 @@ func (s *Service) DashboardID(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
e, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
e, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -98,7 +98,8 @@ func (s *Service) NewDashboard(w http.ResponseWriter, r *http.Request) {
}
var err error
if dashboard, err = s.DashboardsStore.Add(r.Context(), dashboard); err != nil {
ctx := r.Context()
if dashboard, err = s.Store.Dashboards(ctx).Add(r.Context(), dashboard); err != nil {
msg := fmt.Errorf("Error storing dashboard %v: %v", dashboard, err)
unknownErrorWithMessage(w, msg, s.Logger)
return
@ -118,13 +119,13 @@ func (s *Service) RemoveDashboard(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
e, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
e, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
}
if err := s.DashboardsStore.Delete(ctx, e); err != nil {
if err := s.Store.Dashboards(ctx).Delete(ctx, e); err != nil {
unknownErrorWithMessage(w, err, s.Logger)
return
}
@ -141,7 +142,7 @@ func (s *Service) ReplaceDashboard(w http.ResponseWriter, r *http.Request) {
}
id := chronograf.DashboardID(idParam)
_, err = s.DashboardsStore.Get(ctx, id)
_, err = s.Store.Dashboards(ctx).Get(ctx, id)
if err != nil {
Error(w, http.StatusNotFound, fmt.Sprintf("ID %d not found", id), s.Logger)
return
@ -159,7 +160,7 @@ func (s *Service) ReplaceDashboard(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.DashboardsStore.Update(ctx, req); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, req); err != nil {
msg := fmt.Sprintf("Error updating dashboard ID %d: %v", id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -180,7 +181,7 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) {
}
id := chronograf.DashboardID(idParam)
orig, err := s.DashboardsStore.Get(ctx, id)
orig, err := s.Store.Dashboards(ctx).Get(ctx, id)
if err != nil {
Error(w, http.StatusNotFound, fmt.Sprintf("ID %d not found", id), s.Logger)
return
@ -206,7 +207,7 @@ func (s *Service) UpdateDashboard(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.DashboardsStore.Update(ctx, orig); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, orig); err != nil {
msg := fmt.Sprintf("Error updating dashboard ID %d: %v", id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return

View File

@ -76,7 +76,7 @@ func (h *Service) GetDatabases(w http.ResponseWriter, r *http.Request) {
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -122,7 +122,7 @@ func (h *Service) NewDatabase(w http.ResponseWriter, r *http.Request) {
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -172,7 +172,7 @@ func (h *Service) DropDatabase(w http.ResponseWriter, r *http.Request) {
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -207,7 +207,7 @@ func (h *Service) RetentionPolicies(w http.ResponseWriter, r *http.Request) {
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -261,7 +261,7 @@ func (h *Service) NewRetentionPolicy(w http.ResponseWriter, r *http.Request) {
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -311,7 +311,7 @@ func (h *Service) UpdateRetentionPolicy(w http.ResponseWriter, r *http.Request)
return
}
src, err := h.SourcesStore.Get(ctx, srcID)
src, err := h.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, h.Logger)
return
@ -364,7 +364,7 @@ func (s *Service) DropRetentionPolicy(w http.ResponseWriter, r *http.Request) {
return
}
src, err := s.SourcesStore.Get(ctx, srcID)
src, err := s.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, s.Logger)
return

View File

@ -11,7 +11,7 @@ func TestService_GetDatabases(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -33,11 +33,13 @@ func TestService_GetDatabases(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -52,7 +54,7 @@ func TestService_NewDatabase(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -74,11 +76,13 @@ func TestService_NewDatabase(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -93,7 +97,7 @@ func TestService_DropDatabase(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -115,11 +119,13 @@ func TestService_DropDatabase(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -134,7 +140,7 @@ func TestService_RetentionPolicies(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -156,11 +162,13 @@ func TestService_RetentionPolicies(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -175,7 +183,7 @@ func TestService_NewRetentionPolicy(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -197,11 +205,13 @@ func TestService_NewRetentionPolicy(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -216,7 +226,7 @@ func TestService_UpdateRetentionPolicy(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -238,11 +248,13 @@ func TestService_UpdateRetentionPolicy(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -257,7 +269,7 @@ func TestService_DropRetentionPolicy(t *testing.T) {
type fields struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
TimeSeriesClient TimeSeriesClient
@ -279,11 +291,13 @@ func TestService_DropRetentionPolicy(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
Store: &Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
LayoutsStore: tt.fields.LayoutsStore,
UsersStore: tt.fields.UsersStore,
DashboardsStore: tt.fields.DashboardsStore,
},
TimeSeriesClient: tt.fields.TimeSeriesClient,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,

View File

@ -42,7 +42,7 @@ func (s *Service) Influx(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
src, err := s.SourcesStore.Get(ctx, id)
src, err := s.Store.Sources(ctx).Get(ctx, id)
if err != nil {
notFound(w, id, s.Logger)
return
@ -87,7 +87,7 @@ func (s *Service) Write(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
src, err := s.SourcesStore.Get(ctx, id)
src, err := s.Store.Sources(ctx).Get(ctx, id)
if err != nil {
notFound(w, id, s.Logger)
return

View File

@ -67,7 +67,7 @@ func (s *Service) NewKapacitor(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
_, err = s.SourcesStore.Get(ctx, srcID)
_, err = s.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, s.Logger)
return
@ -93,7 +93,7 @@ func (s *Service) NewKapacitor(w http.ResponseWriter, r *http.Request) {
Organization: req.Organization,
}
if srv, err = s.ServersStore.Add(ctx, srv); err != nil {
if srv, err = s.Store.Servers(ctx).Add(ctx, srv); err != nil {
msg := fmt.Errorf("Error storing kapacitor %v: %v", req, err)
unknownErrorWithMessage(w, msg, s.Logger)
return
@ -135,7 +135,7 @@ func (s *Service) Kapacitors(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
mrSrvs, err := s.ServersStore.All(ctx)
mrSrvs, err := s.Store.Servers(ctx).All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading kapacitors", s.Logger)
return
@ -170,7 +170,7 @@ func (s *Service) KapacitorsID(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -195,13 +195,13 @@ func (s *Service) RemoveKapacitor(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
}
if err = s.ServersStore.Delete(ctx, srv); err != nil {
if err = s.Store.Servers(ctx).Delete(ctx, srv); err != nil {
unknownErrorWithMessage(w, err, s.Logger)
return
}
@ -245,7 +245,7 @@ func (s *Service) UpdateKapacitor(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -278,7 +278,7 @@ func (s *Service) UpdateKapacitor(w http.ResponseWriter, r *http.Request) {
srv.Active = *req.Active
}
if err := s.ServersStore.Update(ctx, srv); err != nil {
if err := s.Store.Servers(ctx).Update(ctx, srv); err != nil {
msg := fmt.Sprintf("Error updating kapacitor ID %d", id)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -303,7 +303,7 @@ func (s *Service) KapacitorRulesPost(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -432,7 +432,7 @@ func (s *Service) KapacitorRulesPut(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -502,7 +502,7 @@ func (s *Service) KapacitorRulesStatus(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -563,7 +563,7 @@ func (s *Service) KapacitorRulesGet(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -605,7 +605,7 @@ func (s *Service) KapacitorRulesID(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return
@ -644,7 +644,7 @@ func (s *Service) KapacitorRulesDelete(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return

View File

@ -186,12 +186,14 @@ func Test_KapacitorRulesGet(t *testing.T) {
// setup mock service and test logger
testLogger := mocks.TestLogger{}
svc := &server.Service{
ServersStore: &mocks.ServersStore{
GetF: func(ctx context.Context, ID int) (chronograf.Server, error) {
return chronograf.Server{
SrcID: ID,
URL: kapaSrv.URL,
}, nil
Store: &mocks.Store{
ServersStore: &mocks.ServersStore{
GetF: func(ctx context.Context, ID int) (chronograf.Server, error) {
return chronograf.Server{
SrcID: ID,
URL: kapaSrv.URL,
}, nil
},
},
},
Logger: &testLogger,

View File

@ -63,7 +63,8 @@ func (s *Service) NewLayout(w http.ResponseWriter, r *http.Request) {
}
var err error
if layout, err = s.LayoutsStore.Add(r.Context(), layout); err != nil {
ctx := r.Context()
if layout, err = s.Store.Layouts(ctx).Add(r.Context(), layout); err != nil {
msg := fmt.Errorf("Error storing layout %v: %v", layout, err)
unknownErrorWithMessage(w, msg, s.Logger)
return
@ -91,7 +92,7 @@ func (s *Service) Layouts(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
layouts, err := s.LayoutsStore.All(ctx)
layouts, err := s.Store.Layouts(ctx).All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading layouts", s.Logger)
return
@ -123,7 +124,7 @@ func (s *Service) LayoutsID(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
id := httprouter.GetParamFromContext(ctx, "id")
layout, err := s.LayoutsStore.Get(ctx, id)
layout, err := s.Store.Layouts(ctx).Get(ctx, id)
if err != nil {
Error(w, http.StatusNotFound, fmt.Sprintf("ID %s not found", id), s.Logger)
return
@ -142,7 +143,7 @@ func (s *Service) RemoveLayout(w http.ResponseWriter, r *http.Request) {
ID: id,
}
if err := s.LayoutsStore.Delete(ctx, layout); err != nil {
if err := s.Store.Layouts(ctx).Delete(ctx, layout); err != nil {
unknownErrorWithMessage(w, err, s.Logger)
return
}
@ -155,7 +156,7 @@ func (s *Service) UpdateLayout(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
id := httprouter.GetParamFromContext(ctx, "id")
_, err := s.LayoutsStore.Get(ctx, id)
_, err := s.Store.Layouts(ctx).Get(ctx, id)
if err != nil {
Error(w, http.StatusNotFound, fmt.Sprintf("ID %s not found", id), s.Logger)
return
@ -173,7 +174,7 @@ func (s *Service) UpdateLayout(w http.ResponseWriter, r *http.Request) {
return
}
if err := s.LayoutsStore.Update(ctx, req); err != nil {
if err := s.Store.Layouts(ctx).Update(ctx, req); err != nil {
msg := fmt.Sprintf("Error updating layout ID %s: %v", id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return

View File

@ -126,7 +126,7 @@ func Test_Layouts(t *testing.T) {
// setup mock chronograf.Service and mock logger
lg := &mocks.TestLogger{}
svc := server.Service{
LayoutsStore: &mocks.LayoutsStore{
Store: &mocks.Store{LayoutsStore: &mocks.LayoutsStore{
AllF: func(ctx context.Context) ([]chronograf.Layout, error) {
if len(test.allLayouts) == 0 {
return []chronograf.Layout{
@ -137,6 +137,7 @@ func Test_Layouts(t *testing.T) {
}
},
},
},
Logger: lg,
}

View File

@ -14,7 +14,7 @@ type mapping struct {
// GetMappings returns the known mappings of measurements to applications
func (s *Service) GetMappings(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
layouts, err := s.LayoutsStore.All(ctx)
layouts, err := s.Store.Layouts(ctx).All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading layouts", s.Logger)
return

View File

@ -119,7 +119,7 @@ func (s *Service) MeOrganization(auth oauth2.Authenticator) func(http.ResponseWr
Error(w, http.StatusInternalServerError, err.Error(), s.Logger)
return
}
_, err = s.OrganizationsStore.Get(ctx, chronograf.OrganizationQuery{ID: &orgID})
_, err = s.Store.Organizations(ctx).Get(ctx, chronograf.OrganizationQuery{ID: &orgID})
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -137,7 +137,7 @@ func (s *Service) MeOrganization(auth oauth2.Authenticator) func(http.ResponseWr
}
// validate that user belongs to organization
ctx = context.WithValue(ctx, "organizationID", req.OrganizationID)
_, err = s.OrganizationUsersStore.Get(ctx, chronograf.UserQuery{
_, err = s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{
Name: &p.Subject,
Provider: &p.Issuer,
Scheme: &scheme,
@ -188,7 +188,8 @@ func (s *Service) Me(w http.ResponseWriter, r *http.Request) {
// TODO: add real implementation
ctx = context.WithValue(ctx, "organizationID", p.Organization)
usr, err := s.UsersStore.Get(ctx, chronograf.UserQuery{
// TODO: Change RawUsers to Users
usr, err := s.Store.RawUsers(ctx).Get(ctx, chronograf.UserQuery{
Name: &p.Subject,
Provider: &p.Issuer,
Scheme: &scheme,
@ -215,7 +216,7 @@ func (s *Service) Me(w http.ResponseWriter, r *http.Request) {
Scheme: scheme,
}
newUser, err := s.UsersStore.Add(ctx, user)
newUser, err := s.Store.RawUsers(ctx).Add(ctx, user)
if err != nil {
msg := fmt.Errorf("error storing user %s: %v", user.Name, err)
unknownErrorWithMessage(w, msg, s.Logger)

View File

@ -159,9 +159,11 @@ func TestService_Me(t *testing.T) {
for _, tt := range tests {
tt.args.r = tt.args.r.WithContext(context.WithValue(context.Background(), oauth2.PrincipalKey, tt.principal))
s := &Service{
UsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
}
s.Me(tt.args.w, tt.args.r)
@ -184,11 +186,10 @@ func TestService_Me(t *testing.T) {
func TestService_MeOrganizations(t *testing.T) {
type fields struct {
UsersStore chronograf.UsersStore
OrganizationsStore chronograf.OrganizationsStore
OrganizationUsersStore chronograf.UsersStore
Logger chronograf.Logger
UseAuth bool
UsersStore chronograf.UsersStore
OrganizationsStore chronograf.OrganizationsStore
Logger chronograf.Logger
UseAuth bool
}
type args struct {
w *httptest.ResponseRecorder
@ -227,6 +228,12 @@ func TestService_MeOrganizations(t *testing.T) {
Name: "me",
Provider: "github",
Scheme: "oauth2",
Roles: []chronograf.Role{
{
Name: AdminRoleName,
Organization: "1337",
},
},
}, nil
},
},
@ -241,25 +248,6 @@ func TestService_MeOrganizations(t *testing.T) {
}, nil
},
},
OrganizationUsersStore: &mocks.UsersStore{
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
orgID, ok := ctx.Value("organizationID").(string)
if !ok {
return nil, fmt.Errorf("expected organization key to be a string")
}
if orgID == "" {
return nil, fmt.Errorf("expected organization key to be set")
}
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
return nil, fmt.Errorf("Invalid user query: missing Name, Provider, and/or Scheme")
}
return &chronograf.User{
Name: "me",
Provider: "github",
Scheme: "oauth2",
}, nil
},
},
},
principal: oauth2.Principal{
Subject: "me",
@ -267,7 +255,7 @@ func TestService_MeOrganizations(t *testing.T) {
},
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"name":"me","provider":"github","scheme":"oauth2","currentOrganization":"1337","links":{"self":"/chronograf/v1/users/me"}}`,
wantBody: `{"name":"me","roles":[{"name":"admin","organization":"\"1337\""}],"provider":"github","scheme":"oauth2","currentOrganization":"1337","links":{"self":"/chronograf/v1/users/me"}}`,
},
{
name: "Change the current User's organization",
@ -291,6 +279,12 @@ func TestService_MeOrganizations(t *testing.T) {
Name: "me",
Provider: "github",
Scheme: "oauth2",
Roles: []chronograf.Role{
{
Name: AdminRoleName,
Organization: "1337",
},
},
}, nil
},
},
@ -305,25 +299,6 @@ func TestService_MeOrganizations(t *testing.T) {
}, nil
},
},
OrganizationUsersStore: &mocks.UsersStore{
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
orgID, ok := ctx.Value("organizationID").(string)
if !ok {
return nil, fmt.Errorf("expected organization key to be a string")
}
if orgID == "" {
return nil, fmt.Errorf("expected organization key to be set")
}
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
return nil, fmt.Errorf("Invalid user query: missing Name, Provider, and/or Scheme")
}
return &chronograf.User{
Name: "me",
Provider: "github",
Scheme: "oauth2",
}, nil
},
},
},
principal: oauth2.Principal{
Subject: "me",
@ -332,7 +307,7 @@ func TestService_MeOrganizations(t *testing.T) {
},
wantStatus: http.StatusOK,
wantContentType: "application/json",
wantBody: `{"name":"me","provider":"github","scheme":"oauth2","currentOrganization":"1337","links":{"self":"/chronograf/v1/users/me"}}`,
wantBody: `{"name":"me","roles":[{"name":"admin","organization":"\"1337\""}],"provider":"github","scheme":"oauth2","currentOrganization":"1337","links":{"self":"/chronograf/v1/users/me"}}`,
},
{
name: "Unable to find requested user in valid organization",
@ -352,11 +327,7 @@ func TestService_MeOrganizations(t *testing.T) {
if q.Name == nil || q.Provider == nil || q.Scheme == nil {
return nil, fmt.Errorf("Invalid user query: missing Name, Provider, and/or Scheme")
}
return &chronograf.User{
Name: "me",
Provider: "github",
Scheme: "oauth2",
}, nil
return nil, chronograf.ErrUserNotFound
},
},
OrganizationsStore: &mocks.OrganizationsStore{
@ -370,11 +341,6 @@ func TestService_MeOrganizations(t *testing.T) {
}, nil
},
},
OrganizationUsersStore: &mocks.UsersStore{
GetF: func(ctx context.Context, q chronograf.UserQuery) (*chronograf.User, error) {
return nil, chronograf.ErrUserNotFound
},
},
},
principal: oauth2.Principal{
Subject: "me",
@ -407,6 +373,12 @@ func TestService_MeOrganizations(t *testing.T) {
Name: "me",
Provider: "github",
Scheme: "oauth2",
Roles: []chronograf.Role{
{
Name: AdminRoleName,
Organization: "1337",
},
},
}, nil
},
},
@ -429,11 +401,14 @@ func TestService_MeOrganizations(t *testing.T) {
for _, tt := range tests {
tt.args.r = tt.args.r.WithContext(context.WithValue(context.Background(), oauth2.PrincipalKey, tt.principal))
s := &Service{
UsersStore: tt.fields.UsersStore,
OrganizationsStore: tt.fields.OrganizationsStore,
OrganizationUsersStore: tt.fields.OrganizationUsersStore,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
Store: &Store{
UsersStore: tt.fields.UsersStore,
OrganizationsStore: tt.fields.OrganizationsStore,
},
//UsersStore: tt.fields.UsersStore,
//OrganizationUsersStore: tt.fields.OrganizationUsersStore,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
}
buf, _ := json.Marshal(tt.args.orgRequest)

View File

@ -69,8 +69,7 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
EnsureViewer := func(next http.HandlerFunc) http.HandlerFunc {
return AuthorizedUser(
service.OrganizationUsersStore,
service.OrganizationsStore,
service.Store,
opts.UseAuth,
ViewerRoleName,
opts.Logger,
@ -79,8 +78,7 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
}
EnsureEditor := func(next http.HandlerFunc) http.HandlerFunc {
return AuthorizedUser(
service.OrganizationUsersStore,
service.OrganizationsStore,
service.Store,
opts.UseAuth,
EditorRoleName,
opts.Logger,
@ -89,8 +87,7 @@ func NewMux(opts MuxOpts, service Service) http.Handler {
}
EnsureAdmin := func(next http.HandlerFunc) http.HandlerFunc {
return AuthorizedUser(
service.OrganizationUsersStore,
service.OrganizationsStore,
service.Store,
opts.UseAuth,
AdminRoleName,
opts.Logger,

View File

@ -66,7 +66,7 @@ func newOrganizationsResponse(orgs []chronograf.Organization) *organizationsResp
func (s *Service) Organizations(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
orgs, err := s.OrganizationsStore.All(ctx)
orgs, err := s.Store.Organizations(ctx).All(ctx)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -94,7 +94,7 @@ func (s *Service) NewOrganization(w http.ResponseWriter, r *http.Request) {
Name: req.Name,
}
res, err := s.OrganizationsStore.Add(ctx, org)
res, err := s.Store.Organizations(ctx).Add(ctx, org)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -116,7 +116,7 @@ func (s *Service) OrganizationID(w http.ResponseWriter, r *http.Request) {
return
}
org, err := s.OrganizationsStore.Get(ctx, chronograf.OrganizationQuery{ID: &id})
org, err := s.Store.Organizations(ctx).Get(ctx, chronograf.OrganizationQuery{ID: &id})
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -146,7 +146,7 @@ func (s *Service) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
return
}
org, err := s.OrganizationsStore.Get(ctx, chronograf.OrganizationQuery{ID: &id})
org, err := s.Store.Organizations(ctx).Get(ctx, chronograf.OrganizationQuery{ID: &id})
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -156,7 +156,7 @@ func (s *Service) UpdateOrganization(w http.ResponseWriter, r *http.Request) {
org.Name = req.Name
}
err = s.OrganizationsStore.Update(ctx, org)
err = s.Store.Organizations(ctx).Update(ctx, org)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -176,12 +176,12 @@ func (s *Service) RemoveOrganization(w http.ResponseWriter, r *http.Request) {
return
}
org, err := s.OrganizationsStore.Get(ctx, chronograf.OrganizationQuery{ID: &id})
org, err := s.Store.Organizations(ctx).Get(ctx, chronograf.OrganizationQuery{ID: &id})
if err != nil {
Error(w, http.StatusNotFound, err.Error(), s.Logger)
return
}
if err := s.OrganizationsStore.Delete(ctx, org); err != nil {
if err := s.Store.Organizations(ctx).Delete(ctx, org); err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
}

View File

@ -70,8 +70,10 @@ func TestService_OrganizationID(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationsStore: tt.fields.OrganizationsStore,
Logger: tt.fields.Logger,
Store: &Store{
OrganizationsStore: tt.fields.OrganizationsStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(
@ -155,8 +157,10 @@ func TestService_Organizations(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationsStore: tt.fields.OrganizationsStore,
Logger: tt.fields.Logger,
Store: &Store{
OrganizationsStore: tt.fields.OrganizationsStore,
},
Logger: tt.fields.Logger,
}
s.Organizations(tt.args.w, tt.args.r)
@ -234,8 +238,10 @@ func TestService_UpdateOrganization(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationsStore: tt.fields.OrganizationsStore,
Logger: tt.fields.Logger,
Store: &Store{
OrganizationsStore: tt.fields.OrganizationsStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(context.Background(),
@ -319,8 +325,10 @@ func TestService_RemoveOrganization(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationsStore: tt.fields.OrganizationsStore,
Logger: tt.fields.Logger,
Store: &Store{
OrganizationsStore: tt.fields.OrganizationsStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(context.Background(),
@ -393,8 +401,10 @@ func TestService_NewOrganization(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationsStore: tt.fields.OrganizationsStore,
Logger: tt.fields.Logger,
Store: &Store{
OrganizationsStore: tt.fields.OrganizationsStore,
},
Logger: tt.fields.Logger,
}
buf, _ := json.Marshal(tt.args.org)

View File

@ -16,7 +16,7 @@ func (s *Service) Permissions(w http.ResponseWriter, r *http.Request) {
return
}
src, err := s.SourcesStore.Get(ctx, srcID)
src, err := s.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, s.Logger)
return

View File

@ -89,7 +89,9 @@ func TestService_Permissions(t *testing.T) {
},
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,

View File

@ -28,7 +28,7 @@ func (s *Service) KapacitorProxy(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
srv, err := s.ServersStore.Get(ctx, id)
srv, err := s.Store.Servers(ctx).Get(ctx, id)
if err != nil || srv.SrcID != srcID {
notFound(w, id, s.Logger)
return

View File

@ -44,7 +44,7 @@ func (s *Service) Queries(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
src, err := s.SourcesStore.Get(ctx, srcID)
src, err := s.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, s.Logger)
return

View File

@ -19,7 +19,6 @@ import (
"github.com/influxdata/chronograf/influx"
clog "github.com/influxdata/chronograf/log"
"github.com/influxdata/chronograf/oauth2"
"github.com/influxdata/chronograf/organizations"
"github.com/influxdata/chronograf/uuid"
client "github.com/influxdata/usage-client/v1"
flags "github.com/jessevdk/go-flags"
@ -430,17 +429,19 @@ func openService(ctx context.Context, boltPath string, lBuilder LayoutBuilder, s
}
return Service{
TimeSeriesClient: &InfluxClient{},
SourcesStore: organizations.NewSourcesStore(sources),
ServersStore: organizations.NewServersStore(kapacitors),
UsersStore: db.UsersStore,
OrganizationUsersStore: organizations.NewUsersStore(db.UsersStore),
OrganizationsStore: db.OrganizationsStore,
LayoutsStore: organizations.NewLayoutsStore(layouts),
DashboardsStore: organizations.NewDashboardsStore(db.DashboardsStore),
Logger: logger,
UseAuth: useAuth,
Databases: &influx.Client{Logger: logger},
TimeSeriesClient: &InfluxClient{},
Store: &Store{
SourcesStore: sources,
ServersStore: kapacitors,
UsersStore: db.UsersStore,
OrganizationsStore: db.OrganizationsStore,
LayoutsStore: layouts,
DashboardsStore: db.DashboardsStore,
//OrganizationUsersStore: organizations.NewUsersStore(db.UsersStore),
},
Logger: logger,
UseAuth: useAuth,
Databases: &influx.Client{Logger: logger},
}
}

View File

@ -11,17 +11,11 @@ import (
// Service handles REST calls to the persistence
type Service struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
OrganizationUsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
OrganizationsStore chronograf.OrganizationsStore
TimeSeriesClient TimeSeriesClient
Logger chronograf.Logger
UseAuth bool
Databases chronograf.Databases
Store DataStore
TimeSeriesClient TimeSeriesClient
Logger chronograf.Logger
UseAuth bool
Databases chronograf.Databases
}
// TimeSeriesClient returns the correct client for a time series database.

View File

@ -86,7 +86,7 @@ func (s *Service) NewSource(w http.ResponseWriter, r *http.Request) {
}
src.Type = dbType
if src, err = s.SourcesStore.Add(ctx, src); err != nil {
if src, err = s.Store.Sources(ctx).Add(ctx, src); err != nil {
msg := fmt.Errorf("Error storing source %v: %v", src, err)
unknownErrorWithMessage(w, msg, s.Logger)
return
@ -115,7 +115,7 @@ type getSourcesResponse struct {
// Sources returns all sources from the store.
func (s *Service) Sources(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
srcs, err := s.SourcesStore.All(ctx)
srcs, err := s.Store.Sources(ctx).All(ctx)
if err != nil {
Error(w, http.StatusInternalServerError, "Error loading sources", s.Logger)
return
@ -141,7 +141,7 @@ func (s *Service) SourcesID(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
src, err := s.SourcesStore.Get(ctx, id)
src, err := s.Store.Sources(ctx).Get(ctx, id)
if err != nil {
notFound(w, id, s.Logger)
return
@ -161,7 +161,7 @@ func (s *Service) RemoveSource(w http.ResponseWriter, r *http.Request) {
src := chronograf.Source{ID: id}
ctx := r.Context()
if err = s.SourcesStore.Delete(ctx, src); err != nil {
if err = s.Store.Sources(ctx).Delete(ctx, src); err != nil {
if err == chronograf.ErrSourceNotFound {
notFound(w, id, s.Logger)
} else {
@ -182,7 +182,7 @@ func (s *Service) RemoveSource(w http.ResponseWriter, r *http.Request) {
// removeSrcsKapa will remove all kapacitors and kapacitor rules from the stores.
// However, it will not remove the kapacitor tickscript from kapacitor itself.
func (s *Service) removeSrcsKapa(ctx context.Context, srcID int) error {
kapas, err := s.ServersStore.All(ctx)
kapas, err := s.Store.Servers(ctx).All(ctx)
if err != nil {
return err
}
@ -201,7 +201,7 @@ func (s *Service) removeSrcsKapa(ctx context.Context, srcID int) error {
}
s.Logger.Debug("Deleting kapacitor resource id ", kapa.ID)
if err := s.ServersStore.Delete(ctx, kapa); err != nil {
if err := s.Store.Servers(ctx).Delete(ctx, kapa); err != nil {
return err
}
}
@ -218,7 +218,7 @@ func (s *Service) UpdateSource(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
src, err := s.SourcesStore.Get(ctx, id)
src, err := s.Store.Sources(ctx).Get(ctx, id)
if err != nil {
notFound(w, id, s.Logger)
return
@ -266,7 +266,7 @@ func (s *Service) UpdateSource(w http.ResponseWriter, r *http.Request) {
}
src.Type = dbType
if err := s.SourcesStore.Update(ctx, src); err != nil {
if err := s.Store.Sources(ctx).Update(ctx, src); err != nil {
msg := fmt.Sprintf("Error updating source ID %d", id)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -338,7 +338,7 @@ func (s *Service) HandleNewSources(ctx context.Context, input string) error {
// newSourceKapacitor adds sources to BoltDB idempotently by name, as well as respective kapacitors
func (s *Service) newSourceKapacitor(ctx context.Context, src chronograf.Source, kapa chronograf.Server) error {
srcs, err := s.SourcesStore.All(ctx)
srcs, err := s.Store.Sources(ctx).All(ctx)
if err != nil {
return err
}
@ -354,13 +354,13 @@ func (s *Service) newSourceKapacitor(ctx context.Context, src chronograf.Source,
}
}
src, err = s.SourcesStore.Add(ctx, src)
src, err = s.Store.Sources(ctx).Add(ctx, src)
if err != nil {
return err
}
kapa.SrcID = src.ID
if _, err := s.ServersStore.Add(ctx, kapa); err != nil {
if _, err := s.Store.Servers(ctx).Add(ctx, kapa); err != nil {
return err
}
@ -540,7 +540,7 @@ func (s *Service) sourcesSeries(ctx context.Context, w http.ResponseWriter, r *h
return 0, nil, err
}
src, err := s.SourcesStore.Get(ctx, srcID)
src, err := s.Store.Sources(ctx).Get(ctx, srcID)
if err != nil {
notFound(w, srcID, s.Logger)
return 0, nil, err

View File

@ -239,9 +239,11 @@ func TestService_newSourceKapacitor(t *testing.T) {
srcCount = 0
srvCount = 0
h := &Service{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
ServersStore: tt.fields.ServersStore,
},
Logger: tt.fields.Logger,
}
if err := h.newSourceKapacitor(tt.args.ctx, tt.args.src, tt.args.kapa); (err != nil) != tt.wantErr {
t.Errorf("Service.newSourceKapacitor() error = %v, wantErr %v", err, tt.wantErr)
@ -535,7 +537,9 @@ func TestService_NewSourceUser(t *testing.T) {
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -702,7 +706,9 @@ func TestService_SourceUsers(t *testing.T) {
},
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -867,7 +873,9 @@ func TestService_SourceUserID(t *testing.T) {
},
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -962,7 +970,9 @@ func TestService_RemoveSourceUser(t *testing.T) {
},
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -1144,7 +1154,9 @@ func TestService_UpdateSourceUser(t *testing.T) {
},
}))
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
UseAuth: tt.fields.UseAuth,
@ -1367,7 +1379,9 @@ func TestService_NewSourceRole(t *testing.T) {
}
for _, tt := range tests {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
}
@ -1480,7 +1494,9 @@ func TestService_UpdateSourceRole(t *testing.T) {
}
for _, tt := range tests {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
}
@ -1603,7 +1619,9 @@ func TestService_SourceRoleID(t *testing.T) {
}
for _, tt := range tests {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
}
@ -1699,7 +1717,9 @@ func TestService_RemoveSourceRole(t *testing.T) {
}
for _, tt := range tests {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
}
@ -1811,7 +1831,9 @@ func TestService_SourceRoles(t *testing.T) {
}
for _, tt := range tests {
h := &Service{
SourcesStore: tt.fields.SourcesStore,
Store: &mocks.Store{
SourcesStore: tt.fields.SourcesStore,
},
TimeSeriesClient: tt.fields.TimeSeries,
Logger: tt.fields.Logger,
}

64
server/stores.go Normal file
View File

@ -0,0 +1,64 @@
package server
import (
"context"
"github.com/influxdata/chronograf"
"github.com/influxdata/chronograf/organizations"
)
// TODO: Comment
// DataSource is ...
// Having this as an interface is useful for testing
type DataStore interface {
Sources(ctx context.Context) chronograf.SourcesStore
Servers(ctx context.Context) chronograf.ServersStore
Layouts(ctx context.Context) chronograf.LayoutsStore
Users(ctx context.Context) chronograf.UsersStore
// TODO: remove
RawUsers(ctx context.Context) chronograf.UsersStore
Organizations(ctx context.Context) chronograf.OrganizationsStore
Dashboards(ctx context.Context) chronograf.DashboardsStore
}
// ensure that Store implements a DataStore
var _ DataStore = &Store{}
// Store is a DataStore
type Store struct {
SourcesStore chronograf.SourcesStore
ServersStore chronograf.ServersStore
LayoutsStore chronograf.LayoutsStore
UsersStore chronograf.UsersStore
DashboardsStore chronograf.DashboardsStore
OrganizationsStore chronograf.OrganizationsStore
}
func (s *Store) Sources(ctx context.Context) chronograf.SourcesStore {
return organizations.NewSourcesStore(s.SourcesStore)
}
func (s *Store) Servers(ctx context.Context) chronograf.ServersStore {
return organizations.NewServersStore(s.ServersStore)
}
func (s *Store) Layouts(ctx context.Context) chronograf.LayoutsStore {
return organizations.NewLayoutsStore(s.LayoutsStore)
}
func (s *Store) Users(ctx context.Context) chronograf.UsersStore {
return organizations.NewUsersStore(s.UsersStore)
}
// TODO: remove me and put logic into Users Call
func (s *Store) RawUsers(ctx context.Context) chronograf.UsersStore {
return s.UsersStore
}
func (s *Store) Organizations(ctx context.Context) chronograf.OrganizationsStore {
return s.OrganizationsStore
}
func (s *Store) Dashboards(ctx context.Context) chronograf.DashboardsStore {
return organizations.NewDashboardsStore(s.DashboardsStore)
}

View File

@ -73,7 +73,7 @@ func (s *Service) Templates(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
d, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
d, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -94,7 +94,7 @@ func (s *Service) NewTemplate(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -121,7 +121,7 @@ func (s *Service) NewTemplate(w http.ResponseWriter, r *http.Request) {
template.ID = chronograf.TemplateID(tid)
dash.Templates = append(dash.Templates, template)
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error adding template %s to dashboard %d: %v", tid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -140,7 +140,7 @@ func (s *Service) TemplateID(w http.ResponseWriter, r *http.Request) {
return
}
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -167,7 +167,7 @@ func (s *Service) RemoveTemplate(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -187,7 +187,7 @@ func (s *Service) RemoveTemplate(w http.ResponseWriter, r *http.Request) {
}
dash.Templates = append(dash.Templates[:pos], dash.Templates[pos+1:]...)
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error removing template %s from dashboard %d: %v", tid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
@ -205,7 +205,7 @@ func (s *Service) ReplaceTemplate(w http.ResponseWriter, r *http.Request) {
}
ctx := r.Context()
dash, err := s.DashboardsStore.Get(ctx, chronograf.DashboardID(id))
dash, err := s.Store.Dashboards(ctx).Get(ctx, chronograf.DashboardID(id))
if err != nil {
notFound(w, id, s.Logger)
return
@ -237,7 +237,7 @@ func (s *Service) ReplaceTemplate(w http.ResponseWriter, r *http.Request) {
template.ID = chronograf.TemplateID(tid)
dash.Templates[pos] = template
if err := s.DashboardsStore.Update(ctx, dash); err != nil {
if err := s.Store.Dashboards(ctx).Update(ctx, dash); err != nil {
msg := fmt.Sprintf("Error updating template %s in dashboard %d: %v", tid, id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return

View File

@ -151,7 +151,7 @@ func (s *Service) UserID(w http.ResponseWriter, r *http.Request) {
Error(w, http.StatusBadRequest, fmt.Sprintf("invalid user id: %s", err.Error()), s.Logger)
return
}
user, err := s.OrganizationUsersStore.Get(ctx, chronograf.UserQuery{ID: &id})
user, err := s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{ID: &id})
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -182,7 +182,7 @@ func (s *Service) NewUser(w http.ResponseWriter, r *http.Request) {
Roles: req.Roles,
}
res, err := s.OrganizationUsersStore.Add(ctx, user)
res, err := s.Store.Users(ctx).Add(ctx, user)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -203,12 +203,12 @@ func (s *Service) RemoveUser(w http.ResponseWriter, r *http.Request) {
return
}
u, err := s.OrganizationUsersStore.Get(ctx, chronograf.UserQuery{ID: &id})
u, err := s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{ID: &id})
if err != nil {
Error(w, http.StatusNotFound, err.Error(), s.Logger)
return
}
if err := s.OrganizationUsersStore.Delete(ctx, u); err != nil {
if err := s.Store.Users(ctx).Delete(ctx, u); err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
}
@ -237,7 +237,7 @@ func (s *Service) UpdateUser(w http.ResponseWriter, r *http.Request) {
return
}
u, err := s.OrganizationUsersStore.Get(ctx, chronograf.UserQuery{ID: &id})
u, err := s.Store.Users(ctx).Get(ctx, chronograf.UserQuery{ID: &id})
if err != nil {
Error(w, http.StatusNotFound, err.Error(), s.Logger)
return
@ -246,7 +246,7 @@ func (s *Service) UpdateUser(w http.ResponseWriter, r *http.Request) {
// ValidUpdate should ensure that req.Roles is not nil
u.Roles = req.Roles
err = s.OrganizationUsersStore.Update(ctx, u)
err = s.Store.Users(ctx).Update(ctx, u)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return
@ -261,7 +261,7 @@ func (s *Service) UpdateUser(w http.ResponseWriter, r *http.Request) {
func (s *Service) Users(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
users, err := s.OrganizationUsersStore.All(ctx)
users, err := s.Store.Users(ctx).All(ctx)
if err != nil {
Error(w, http.StatusBadRequest, err.Error(), s.Logger)
return

View File

@ -75,8 +75,10 @@ func TestService_UserID(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationUsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(
@ -163,8 +165,10 @@ func TestService_NewUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationUsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
}
buf, _ := json.Marshal(tt.args.user)
@ -251,8 +255,10 @@ func TestService_RemoveUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationUsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(
@ -344,8 +350,10 @@ func TestService_UpdateUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationUsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
}
tt.args.r = tt.args.r.WithContext(httprouter.WithParams(context.Background(),
@ -475,8 +483,10 @@ func TestService_Users(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := &Service{
OrganizationUsersStore: tt.fields.UsersStore,
Logger: tt.fields.Logger,
Store: &mocks.Store{
UsersStore: tt.fields.UsersStore,
},
Logger: tt.fields.Logger,
}
s.Users(tt.args.w, tt.args.r)