noop services poc

pull/13700/head
Torkel Ödegaard 7 years ago
parent 8009bc3940
commit d2464812eb
  1. 1
      pkg/cmd/grafana-server/server.go
  2. 50
      pkg/services/datasources/datasource_service.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"

@ -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
}
Loading…
Cancel
Save