noop services poc

This commit is contained in:
Torkel Ödegaard
2018-09-28 14:52:12 +02:00
parent 8009bc3940
commit d2464812eb
2 changed files with 51 additions and 0 deletions
+1
View File
@@ -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
}