datasource_service.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package datasources
  2. import (
  3. "github.com/grafana/grafana/pkg/log"
  4. "github.com/grafana/grafana/pkg/models"
  5. "github.com/grafana/grafana/pkg/registry"
  6. "github.com/grafana/grafana/pkg/setting"
  7. )
  8. type DataSourceService interface {
  9. GetById(id int64, user *models.SignedInUser) (*models.DataSource, error)
  10. }
  11. type DataSourceServiceImpl struct {
  12. log log.Logger
  13. Cfg *setting.Cfg `inject:""`
  14. Guardian DataSourceGuardian `inject:""`
  15. }
  16. func init() {
  17. registry.RegisterService(&DataSourceServiceImpl{})
  18. registry.RegisterService(&DataSourceGuardianNoop{})
  19. }
  20. func (srv *DataSourceServiceImpl) Init() error {
  21. srv.log = log.New("datasources")
  22. srv.log.Info("hello", "guardian", srv.Guardian.GetPermission(0, nil))
  23. return nil
  24. }
  25. func (srv *DataSourceServiceImpl) GetById(id int64, user *models.SignedInUser) {
  26. // check cache
  27. // Get by id from db
  28. // check permissions
  29. }
  30. type DataSourceGuardian interface {
  31. GetPermission(id int64, user *models.SignedInUser) bool
  32. }
  33. type DataSourceGuardianNoop struct {
  34. }
  35. func (dsg *DataSourceGuardianNoop) Init() error {
  36. return nil
  37. }
  38. func (dsg *DataSourceGuardianNoop) GetPermission(id int64, user *models.SignedInUser) bool {
  39. return false
  40. }