소스 검색

noop services poc

Torkel Ödegaard 7 년 전
부모
커밋
d2464812eb
2개의 변경된 파일51개의 추가작업 그리고 0개의 파일을 삭제
  1. 1 0
      pkg/cmd/grafana-server/server.go
  2. 50 0
      pkg/services/datasources/datasource_service.go

+ 1 - 0
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"

+ 50 - 0
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
+}