diff --git a/pkg/cmd/grafana-server/server.go b/pkg/cmd/grafana-server/server.go index 8794d7d8338..b2f4a620208 100644 --- a/pkg/cmd/grafana-server/server.go +++ b/pkg/cmd/grafana-server/server.go @@ -32,6 +32,7 @@ import ( _ "github.com/grafana/grafana/pkg/plugins" _ "github.com/grafana/grafana/pkg/services/alerting" _ "github.com/grafana/grafana/pkg/services/cleanup" + _ "github.com/grafana/grafana/pkg/services/datasources" _ "github.com/grafana/grafana/pkg/services/notifications" _ "github.com/grafana/grafana/pkg/services/provisioning" _ "github.com/grafana/grafana/pkg/services/rendering" diff --git a/pkg/services/datasources/datasource_service.go b/pkg/services/datasources/datasource_service.go new file mode 100644 index 00000000000..2fba0bb5b87 --- /dev/null +++ b/pkg/services/datasources/datasource_service.go @@ -0,0 +1,50 @@ +package datasources + +import ( + "github.com/grafana/grafana/pkg/log" + "github.com/grafana/grafana/pkg/models" + "github.com/grafana/grafana/pkg/registry" + "github.com/grafana/grafana/pkg/setting" +) + +type DataSourceService interface { + GetById(id int64, user *models.SignedInUser) (*models.DataSource, error) +} + +type DataSourceServiceImpl struct { + log log.Logger + Cfg *setting.Cfg `inject:""` + Guardian DataSourceGuardian `inject:""` +} + +func init() { + registry.RegisterService(&DataSourceServiceImpl{}) + registry.RegisterService(&DataSourceGuardianNoop{}) +} + +func (srv *DataSourceServiceImpl) Init() error { + srv.log = log.New("datasources") + srv.log.Info("hello", "guardian", srv.Guardian.GetPermission(0, nil)) + return nil +} + +func (srv *DataSourceServiceImpl) GetById(id int64, user *models.SignedInUser) { + // check cache + // Get by id from db + // check permissions +} + +type DataSourceGuardian interface { + GetPermission(id int64, user *models.SignedInUser) bool +} + +type DataSourceGuardianNoop struct { +} + +func (dsg *DataSourceGuardianNoop) Init() error { + return nil +} + +func (dsg *DataSourceGuardianNoop) GetPermission(id int64, user *models.SignedInUser) bool { + return false +}