Commit 5fc255bd by Carl Bergquist Committed by GitHub

Linting fixes for provisoning (#23600)

parent 6e313e7d
...@@ -731,8 +731,9 @@ jobs: ...@@ -731,8 +731,9 @@ jobs:
golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.yml -E unconvert -E unused \ golangci-lint run -v -j 4 --config scripts/go/configs/ci/.golangci.yml -E unconvert -E unused \
-E varcheck -E goconst -E errcheck -E staticcheck ./pkg/... -E varcheck -E goconst -E errcheck -E staticcheck ./pkg/...
./scripts/go/bin/revive -formatter stylish -config ./scripts/go/configs/revive.toml ./pkg/... ./scripts/go/bin/revive -formatter stylish -config ./scripts/go/configs/revive.toml ./pkg/...
./scripts/go/bin/revive -formatter stylish ./pkg/services/alerting/... ./scripts/go/bin/revive ./pkg/services/alerting/...
./scripts/go/bin/revive -formatter stylish ./pkg/services/provisioning/datasources/... ./scripts/go/bin/revive -formatter stylish ./pkg/services/provisioning/datasources/...
./scripts/go/bin/revive -formatter stylish ./pkg/services/provisioning/dashboards/...
./scripts/go/bin/gosec -quiet -exclude=G104,G107,G108,G201,G202,G204,G301,G304,G401,G402,G501 \ ./scripts/go/bin/gosec -quiet -exclude=G104,G107,G108,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json ./pkg/... -conf=./scripts/go/configs/gosec.json ./pkg/...
......
...@@ -107,7 +107,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) Response { ...@@ -107,7 +107,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) Response {
meta.FolderUrl = query.Result.GetUrl() meta.FolderUrl = query.Result.GetUrl()
} }
provisioningData, err := dashboards.NewProvisioningService().GetProvisionedDashboardDataByDashboardId(dash.Id) provisioningData, err := dashboards.NewProvisioningService().GetProvisionedDashboardDataByDashboardID(dash.Id)
if err != nil { if err != nil {
return Error(500, "Error while checking if dashboard is provisioned", err) return Error(500, "Error while checking if dashboard is provisioned", err)
} }
...@@ -225,7 +225,7 @@ func (hs *HTTPServer) PostDashboard(c *models.ReqContext, cmd models.SaveDashboa ...@@ -225,7 +225,7 @@ func (hs *HTTPServer) PostDashboard(c *models.ReqContext, cmd models.SaveDashboa
} }
} }
provisioningData, err := dashboards.NewProvisioningService().GetProvisionedDashboardDataByDashboardId(dash.Id) provisioningData, err := dashboards.NewProvisioningService().GetProvisionedDashboardDataByDashboardID(dash.Id)
if err != nil { if err != nil {
return Error(500, "Error while checking if dashboard is provisioned", err) return Error(500, "Error while checking if dashboard is provisioned", err)
} }
......
...@@ -1196,7 +1196,7 @@ func (m mockDashboardProvisioningService) GetProvisionedDashboardData(name strin ...@@ -1196,7 +1196,7 @@ func (m mockDashboardProvisioningService) GetProvisionedDashboardData(name strin
panic("implement me") panic("implement me")
} }
func (mock mockDashboardProvisioningService) GetProvisionedDashboardDataByDashboardId(dashboardId int64) (*models.DashboardProvisioning, error) { func (mock mockDashboardProvisioningService) GetProvisionedDashboardDataByDashboardID(dashboardId int64) (*models.DashboardProvisioning, error) {
return &models.DashboardProvisioning{}, nil return &models.DashboardProvisioning{}, nil
} }
......
package dashboards package dashboards
import ( import (
"github.com/grafana/grafana/pkg/components/gtime"
"github.com/grafana/grafana/pkg/setting"
"strings" "strings"
"time" "time"
"github.com/grafana/grafana/pkg/components/gtime"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/bus"
"github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models" "github.com/grafana/grafana/pkg/models"
...@@ -26,7 +27,7 @@ type DashboardProvisioningService interface { ...@@ -26,7 +27,7 @@ type DashboardProvisioningService interface {
SaveProvisionedDashboard(dto *SaveDashboardDTO, provisioning *models.DashboardProvisioning) (*models.Dashboard, error) SaveProvisionedDashboard(dto *SaveDashboardDTO, provisioning *models.DashboardProvisioning) (*models.Dashboard, error)
SaveFolderForProvisionedDashboards(*SaveDashboardDTO) (*models.Dashboard, error) SaveFolderForProvisionedDashboards(*SaveDashboardDTO) (*models.Dashboard, error)
GetProvisionedDashboardData(name string) ([]*models.DashboardProvisioning, error) GetProvisionedDashboardData(name string) ([]*models.DashboardProvisioning, error)
GetProvisionedDashboardDataByDashboardId(dashboardId int64) (*models.DashboardProvisioning, error) GetProvisionedDashboardDataByDashboardID(DashboardId int64) (*models.DashboardProvisioning, error)
UnprovisionDashboard(dashboardId int64) error UnprovisionDashboard(dashboardId int64) error
DeleteProvisionedDashboard(dashboardId int64, orgId int64) error DeleteProvisionedDashboard(dashboardId int64, orgId int64) error
} }
...@@ -70,7 +71,7 @@ func (dr *dashboardServiceImpl) GetProvisionedDashboardData(name string) ([]*mod ...@@ -70,7 +71,7 @@ func (dr *dashboardServiceImpl) GetProvisionedDashboardData(name string) ([]*mod
return cmd.Result, nil return cmd.Result, nil
} }
func (dr *dashboardServiceImpl) GetProvisionedDashboardDataByDashboardId(dashboardId int64) (*models.DashboardProvisioning, error) { func (dr *dashboardServiceImpl) GetProvisionedDashboardDataByDashboardID(dashboardId int64) (*models.DashboardProvisioning, error) {
cmd := &models.GetProvisionedDashboardDataByIdQuery{DashboardId: dashboardId} cmd := &models.GetProvisionedDashboardDataByIdQuery{DashboardId: dashboardId}
err := bus.Dispatch(cmd) err := bus.Dispatch(cmd)
if err != nil { if err != nil {
...@@ -142,7 +143,7 @@ func (dr *dashboardServiceImpl) buildSaveDashboardCommand(dto *SaveDashboardDTO, ...@@ -142,7 +143,7 @@ func (dr *dashboardServiceImpl) buildSaveDashboardCommand(dto *SaveDashboardDTO,
} }
if validateProvisionedDashboard { if validateProvisionedDashboard {
provisionedData, err := dr.GetProvisionedDashboardDataByDashboardId(dash.Id) provisionedData, err := dr.GetProvisionedDashboardDataByDashboardID(dash.Id)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -308,7 +309,7 @@ func (dr *dashboardServiceImpl) DeleteProvisionedDashboard(dashboardId int64, or ...@@ -308,7 +309,7 @@ func (dr *dashboardServiceImpl) DeleteProvisionedDashboard(dashboardId int64, or
func (dr *dashboardServiceImpl) deleteDashboard(dashboardId int64, orgId int64, validateProvisionedDashboard bool) error { func (dr *dashboardServiceImpl) deleteDashboard(dashboardId int64, orgId int64, validateProvisionedDashboard bool) error {
if validateProvisionedDashboard { if validateProvisionedDashboard {
provisionedData, err := dr.GetProvisionedDashboardDataByDashboardId(dashboardId) provisionedData, err := dr.GetProvisionedDashboardDataByDashboardID(dashboardId)
if err != nil { if err != nil {
return errutil.Wrap("failed to check if dashboard is provisioned", err) return errutil.Wrap("failed to check if dashboard is provisioned", err)
} }
......
...@@ -16,14 +16,14 @@ type configReader struct { ...@@ -16,14 +16,14 @@ type configReader struct {
log log.Logger log log.Logger
} }
func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, error) { func (cr *configReader) parseConfigs(file os.FileInfo) ([]*config, error) {
filename, _ := filepath.Abs(filepath.Join(cr.path, file.Name())) filename, _ := filepath.Abs(filepath.Join(cr.path, file.Name()))
yamlFile, err := ioutil.ReadFile(filename) yamlFile, err := ioutil.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
apiVersion := &ConfigVersion{ApiVersion: 0} apiVersion := &configVersion{APIVersion: 0}
// We ignore the error here because it errors out for version 0 which does not have apiVersion // We ignore the error here because it errors out for version 0 which does not have apiVersion
// specified (so 0 is default). This can also error in case the apiVersion is not an integer but at the moment // specified (so 0 is default). This can also error in case the apiVersion is not an integer but at the moment
...@@ -32,8 +32,8 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e ...@@ -32,8 +32,8 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
// integer > max version?). // integer > max version?).
_ = yaml.Unmarshal(yamlFile, &apiVersion) _ = yaml.Unmarshal(yamlFile, &apiVersion)
if apiVersion.ApiVersion > 0 { if apiVersion.APIVersion > 0 {
v1 := &DashboardAsConfigV1{} v1 := &configV1{}
err := yaml.Unmarshal(yamlFile, &v1) err := yaml.Unmarshal(yamlFile, &v1)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -43,7 +43,7 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e ...@@ -43,7 +43,7 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
return v1.mapToDashboardsAsConfig() return v1.mapToDashboardsAsConfig()
} }
} else { } else {
var v0 []*DashboardsAsConfigV0 var v0 []*configV0
err := yaml.Unmarshal(yamlFile, &v0) err := yaml.Unmarshal(yamlFile, &v0)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -55,11 +55,11 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e ...@@ -55,11 +55,11 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
} }
} }
return []*DashboardsAsConfig{}, nil return []*config{}, nil
} }
func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) { func (cr *configReader) readConfig() ([]*config, error) {
var dashboards []*DashboardsAsConfig var dashboards []*config
files, err := ioutil.ReadDir(cr.path) files, err := ioutil.ReadDir(cr.path)
if err != nil { if err != nil {
...@@ -84,15 +84,15 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) { ...@@ -84,15 +84,15 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) {
uidUsage := map[string]uint8{} uidUsage := map[string]uint8{}
for _, dashboard := range dashboards { for _, dashboard := range dashboards {
if dashboard.OrgId == 0 { if dashboard.OrgID == 0 {
dashboard.OrgId = 1 dashboard.OrgID = 1
} }
if dashboard.UpdateIntervalSeconds == 0 { if dashboard.UpdateIntervalSeconds == 0 {
dashboard.UpdateIntervalSeconds = 10 dashboard.UpdateIntervalSeconds = 10
} }
if len(dashboard.FolderUid) > 0 { if len(dashboard.FolderUID) > 0 {
uidUsage[dashboard.FolderUid]++ uidUsage[dashboard.FolderUID]++
} }
} }
......
...@@ -59,7 +59,7 @@ func TestDashboardsAsConfig(t *testing.T) { ...@@ -59,7 +59,7 @@ func TestDashboardsAsConfig(t *testing.T) {
}) })
}) })
} }
func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) { func validateDashboardAsConfig(t *testing.T, cfg []*config) {
t.Helper() t.Helper()
So(len(cfg), ShouldEqual, 2) So(len(cfg), ShouldEqual, 2)
...@@ -67,9 +67,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) { ...@@ -67,9 +67,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) {
ds := cfg[0] ds := cfg[0]
So(ds.Name, ShouldEqual, "general dashboards") So(ds.Name, ShouldEqual, "general dashboards")
So(ds.Type, ShouldEqual, "file") So(ds.Type, ShouldEqual, "file")
So(ds.OrgId, ShouldEqual, 2) So(ds.OrgID, ShouldEqual, 2)
So(ds.Folder, ShouldEqual, "developers") So(ds.Folder, ShouldEqual, "developers")
So(ds.FolderUid, ShouldEqual, "xyz") So(ds.FolderUID, ShouldEqual, "xyz")
So(ds.Editable, ShouldBeTrue) So(ds.Editable, ShouldBeTrue)
So(len(ds.Options), ShouldEqual, 1) So(len(ds.Options), ShouldEqual, 1)
So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards") So(ds.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
...@@ -79,9 +79,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) { ...@@ -79,9 +79,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) {
ds2 := cfg[1] ds2 := cfg[1]
So(ds2.Name, ShouldEqual, "default") So(ds2.Name, ShouldEqual, "default")
So(ds2.Type, ShouldEqual, "file") So(ds2.Type, ShouldEqual, "file")
So(ds2.OrgId, ShouldEqual, 1) So(ds2.OrgID, ShouldEqual, 1)
So(ds2.Folder, ShouldEqual, "") So(ds2.Folder, ShouldEqual, "")
So(ds2.FolderUid, ShouldEqual, "") So(ds2.FolderUID, ShouldEqual, "")
So(ds2.Editable, ShouldBeFalse) So(ds2.Editable, ShouldBeFalse)
So(len(ds2.Options), ShouldEqual, 1) So(len(ds2.Options), ShouldEqual, 1)
So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards") So(ds2.Options["path"], ShouldEqual, "/var/lib/grafana/dashboards")
......
...@@ -25,7 +25,7 @@ type DashboardProvisionerFactory func(string) (DashboardProvisioner, error) ...@@ -25,7 +25,7 @@ type DashboardProvisionerFactory func(string) (DashboardProvisioner, error)
type Provisioner struct { type Provisioner struct {
log log.Logger log log.Logger
fileReaders []*FileReader fileReaders []*FileReader
configs []*DashboardsAsConfig configs []*config
} }
// New returns a new DashboardProvisioner // New returns a new DashboardProvisioner
...@@ -94,13 +94,13 @@ func (provider *Provisioner) GetProvisionerResolvedPath(name string) string { ...@@ -94,13 +94,13 @@ func (provider *Provisioner) GetProvisionerResolvedPath(name string) string {
func (provider *Provisioner) GetAllowUIUpdatesFromConfig(name string) bool { func (provider *Provisioner) GetAllowUIUpdatesFromConfig(name string) bool {
for _, config := range provider.configs { for _, config := range provider.configs {
if config.Name == name { if config.Name == name {
return config.AllowUiUpdates return config.AllowUIUpdates
} }
} }
return false return false
} }
func getFileReaders(configs []*DashboardsAsConfig, logger log.Logger) ([]*FileReader, error) { func getFileReaders(configs []*config, logger log.Logger) ([]*FileReader, error) {
var readers []*FileReader var readers []*FileReader
for _, config := range configs { for _, config := range configs {
......
...@@ -29,14 +29,14 @@ var ( ...@@ -29,14 +29,14 @@ var (
// insert/update dashboards to the Grafana database using // insert/update dashboards to the Grafana database using
// `dashboards.DashboardProvisioningService` // `dashboards.DashboardProvisioningService`
type FileReader struct { type FileReader struct {
Cfg *DashboardsAsConfig Cfg *config
Path string Path string
log log.Logger log log.Logger
dashboardProvisioningService dashboards.DashboardProvisioningService dashboardProvisioningService dashboards.DashboardProvisioningService
} }
// NewDashboardFileReader returns a new filereader based on `DashboardsAsConfig` // NewDashboardFileReader returns a new filereader based on `config`
func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*FileReader, error) { func NewDashboardFileReader(cfg *config, log log.Logger) (*FileReader, error) {
var path string var path string
path, ok := cfg.Options["path"].(string) path, ok := cfg.Options["path"].(string)
if !ok { if !ok {
...@@ -139,7 +139,7 @@ func (fr *FileReader) handleMissingDashboardFiles(provisionedDashboardRefs map[s ...@@ -139,7 +139,7 @@ func (fr *FileReader) handleMissingDashboardFiles(provisionedDashboardRefs map[s
// delete dashboard that are missing json file // delete dashboard that are missing json file
for _, dashboardID := range dashboardToDelete { for _, dashboardID := range dashboardToDelete {
fr.log.Debug("deleting provisioned dashboard. missing on disk", "id", dashboardID) fr.log.Debug("deleting provisioned dashboard. missing on disk", "id", dashboardID)
err := fr.dashboardProvisioningService.DeleteProvisionedDashboard(dashboardID, fr.Cfg.OrgId) err := fr.dashboardProvisioningService.DeleteProvisionedDashboard(dashboardID, fr.Cfg.OrgID)
if err != nil { if err != nil {
fr.log.Error("failed to delete dashboard", "id", dashboardID, "error", err) fr.log.Error("failed to delete dashboard", "id", dashboardID, "error", err)
} }
...@@ -212,12 +212,12 @@ func getProvisionedDashboardByPath(service dashboards.DashboardProvisioningServi ...@@ -212,12 +212,12 @@ func getProvisionedDashboardByPath(service dashboards.DashboardProvisioningServi
return byPath, nil return byPath, nil
} }
func getOrCreateFolderID(cfg *DashboardsAsConfig, service dashboards.DashboardProvisioningService) (int64, error) { func getOrCreateFolderID(cfg *config, service dashboards.DashboardProvisioningService) (int64, error) {
if cfg.Folder == "" { if cfg.Folder == "" {
return 0, ErrFolderNameMissing return 0, ErrFolderNameMissing
} }
cmd := &models.GetDashboardQuery{Slug: models.SlugifyTitle(cfg.Folder), OrgId: cfg.OrgId} cmd := &models.GetDashboardQuery{Slug: models.SlugifyTitle(cfg.Folder), OrgId: cfg.OrgID}
err := bus.Dispatch(cmd) err := bus.Dispatch(cmd)
if err != nil && err != models.ErrDashboardNotFound { if err != nil && err != models.ErrDashboardNotFound {
...@@ -230,9 +230,9 @@ func getOrCreateFolderID(cfg *DashboardsAsConfig, service dashboards.DashboardPr ...@@ -230,9 +230,9 @@ func getOrCreateFolderID(cfg *DashboardsAsConfig, service dashboards.DashboardPr
dash.Dashboard = models.NewDashboardFolder(cfg.Folder) dash.Dashboard = models.NewDashboardFolder(cfg.Folder)
dash.Dashboard.IsFolder = true dash.Dashboard.IsFolder = true
dash.Overwrite = true dash.Overwrite = true
dash.OrgId = cfg.OrgId dash.OrgId = cfg.OrgID
// set dashboard folderUid if given // set dashboard folderUid if given
dash.Dashboard.SetUid(cfg.FolderUid) dash.Dashboard.SetUid(cfg.FolderUID)
dbDash, err := service.SaveFolderForProvisionedDashboards(dash) dbDash, err := service.SaveFolderForProvisionedDashboards(dash)
if err != nil { if err != nil {
return 0, err return 0, err
...@@ -321,7 +321,7 @@ func (fr *FileReader) readDashboardFromFile(path string, lastModified time.Time, ...@@ -321,7 +321,7 @@ func (fr *FileReader) readDashboardFromFile(path string, lastModified time.Time,
return nil, err return nil, err
} }
dash, err := createDashboardJson(data, lastModified, fr.Cfg, folderID) dash, err := createDashboardJSON(data, lastModified, fr.Cfg, folderID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -14,10 +14,10 @@ var ( ...@@ -14,10 +14,10 @@ var (
) )
func TestProvsionedSymlinkedFolder(t *testing.T) { func TestProvsionedSymlinkedFolder(t *testing.T) {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "", Folder: "",
Options: map[string]interface{}{"path": symlinkedFolder}, Options: map[string]interface{}{"path": symlinkedFolder},
} }
......
...@@ -30,10 +30,10 @@ var ( ...@@ -30,10 +30,10 @@ var (
func TestCreatingNewDashboardFileReader(t *testing.T) { func TestCreatingNewDashboardFileReader(t *testing.T) {
Convey("creating new dashboard file reader", t, func() { Convey("creating new dashboard file reader", t, func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "", Folder: "",
Options: map[string]interface{}{}, Options: map[string]interface{}{},
} }
...@@ -88,10 +88,10 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -88,10 +88,10 @@ func TestDashboardFileReader(t *testing.T) {
Convey("Reading dashboards from disk", func() { Convey("Reading dashboards from disk", func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "", Folder: "",
Options: map[string]interface{}{}, Options: map[string]interface{}{},
} }
...@@ -153,10 +153,10 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -153,10 +153,10 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("Invalid configuration should return error", func() { Convey("Invalid configuration should return error", func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "", Folder: "",
} }
...@@ -172,8 +172,8 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -172,8 +172,8 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("Two dashboard providers should be able to provisioned the same dashboard without uid", func() { Convey("Two dashboard providers should be able to provisioned the same dashboard without uid", func() {
cfg1 := &DashboardsAsConfig{Name: "1", Type: "file", OrgId: 1, Folder: "f1", Options: map[string]interface{}{"path": containingID}} cfg1 := &config{Name: "1", Type: "file", OrgID: 1, Folder: "f1", Options: map[string]interface{}{"path": containingID}}
cfg2 := &DashboardsAsConfig{Name: "2", Type: "file", OrgId: 1, Folder: "f2", Options: map[string]interface{}{"path": containingID}} cfg2 := &config{Name: "2", Type: "file", OrgID: 1, Folder: "f2", Options: map[string]interface{}{"path": containingID}}
reader1, err := NewDashboardFileReader(cfg1, logger) reader1, err := NewDashboardFileReader(cfg1, logger)
So(err, ShouldBeNil) So(err, ShouldBeNil)
...@@ -203,10 +203,10 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -203,10 +203,10 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("Should not create new folder if folder name is missing", func() { Convey("Should not create new folder if folder name is missing", func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "", Folder: "",
Options: map[string]interface{}{ Options: map[string]interface{}{
"folder": defaultDashboards, "folder": defaultDashboards,
...@@ -218,10 +218,10 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -218,10 +218,10 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("can get or Create dashboard folder", func() { Convey("can get or Create dashboard folder", func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Folder: "TEAM A", Folder: "TEAM A",
Options: map[string]interface{}{ Options: map[string]interface{}{
"folder": defaultDashboards, "folder": defaultDashboards,
...@@ -255,10 +255,10 @@ func TestDashboardFileReader(t *testing.T) { ...@@ -255,10 +255,10 @@ func TestDashboardFileReader(t *testing.T) {
}) })
Convey("Given missing dashboard file", func() { Convey("Given missing dashboard file", func() {
cfg := &DashboardsAsConfig{ cfg := &config{
Name: "Default", Name: "Default",
Type: "file", Type: "file",
OrgId: 1, OrgID: 1,
Options: map[string]interface{}{ Options: map[string]interface{}{
"folder": unprovision, "folder": unprovision,
}, },
...@@ -436,7 +436,7 @@ func (s *fakeDashboardProvisioningService) DeleteProvisionedDashboard(dashboardI ...@@ -436,7 +436,7 @@ func (s *fakeDashboardProvisioningService) DeleteProvisionedDashboard(dashboardI
return nil return nil
} }
func (s *fakeDashboardProvisioningService) GetProvisionedDashboardDataByDashboardId(dashboardID int64) (*models.DashboardProvisioning, error) { func (s *fakeDashboardProvisioningService) GetProvisionedDashboardDataByDashboardID(dashboardID int64) (*models.DashboardProvisioning, error) {
return nil, nil return nil, nil
} }
......
...@@ -10,61 +10,61 @@ import ( ...@@ -10,61 +10,61 @@ import (
"github.com/grafana/grafana/pkg/services/provisioning/values" "github.com/grafana/grafana/pkg/services/provisioning/values"
) )
type DashboardsAsConfig struct { type config struct {
Name string Name string
Type string Type string
OrgId int64 OrgID int64
Folder string Folder string
FolderUid string FolderUID string
Editable bool Editable bool
Options map[string]interface{} Options map[string]interface{}
DisableDeletion bool DisableDeletion bool
UpdateIntervalSeconds int64 UpdateIntervalSeconds int64
AllowUiUpdates bool AllowUIUpdates bool
} }
type DashboardsAsConfigV0 struct { type configV0 struct {
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
Type string `json:"type" yaml:"type"` Type string `json:"type" yaml:"type"`
OrgId int64 `json:"org_id" yaml:"org_id"` OrgID int64 `json:"org_id" yaml:"org_id"`
Folder string `json:"folder" yaml:"folder"` Folder string `json:"folder" yaml:"folder"`
FolderUid string `json:"folderUid" yaml:"folderUid"` FolderUID string `json:"folderUid" yaml:"folderUid"`
Editable bool `json:"editable" yaml:"editable"` Editable bool `json:"editable" yaml:"editable"`
Options map[string]interface{} `json:"options" yaml:"options"` Options map[string]interface{} `json:"options" yaml:"options"`
DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"` DisableDeletion bool `json:"disableDeletion" yaml:"disableDeletion"`
UpdateIntervalSeconds int64 `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"` UpdateIntervalSeconds int64 `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
AllowUiUpdates bool `json:"allowUiUpdates" yaml:"allowUiUpdates"` AllowUIUpdates bool `json:"allowUiUpdates" yaml:"allowUiUpdates"`
} }
type ConfigVersion struct { type configVersion struct {
ApiVersion int64 `json:"apiVersion" yaml:"apiVersion"` APIVersion int64 `json:"apiVersion" yaml:"apiVersion"`
} }
type DashboardAsConfigV1 struct { type configV1 struct {
Providers []*DashboardProviderConfigs `json:"providers" yaml:"providers"` Providers []*configs `json:"providers" yaml:"providers"`
} }
type DashboardProviderConfigs struct { type configs struct {
Name values.StringValue `json:"name" yaml:"name"` Name values.StringValue `json:"name" yaml:"name"`
Type values.StringValue `json:"type" yaml:"type"` Type values.StringValue `json:"type" yaml:"type"`
OrgId values.Int64Value `json:"orgId" yaml:"orgId"` OrgID values.Int64Value `json:"orgId" yaml:"orgId"`
Folder values.StringValue `json:"folder" yaml:"folder"` Folder values.StringValue `json:"folder" yaml:"folder"`
FolderUid values.StringValue `json:"folderUid" yaml:"folderUid"` FolderUID values.StringValue `json:"folderUid" yaml:"folderUid"`
Editable values.BoolValue `json:"editable" yaml:"editable"` Editable values.BoolValue `json:"editable" yaml:"editable"`
Options values.JSONValue `json:"options" yaml:"options"` Options values.JSONValue `json:"options" yaml:"options"`
DisableDeletion values.BoolValue `json:"disableDeletion" yaml:"disableDeletion"` DisableDeletion values.BoolValue `json:"disableDeletion" yaml:"disableDeletion"`
UpdateIntervalSeconds values.Int64Value `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"` UpdateIntervalSeconds values.Int64Value `json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
AllowUiUpdates values.BoolValue `json:"allowUiUpdates" yaml:"allowUiUpdates"` AllowUIUpdates values.BoolValue `json:"allowUiUpdates" yaml:"allowUiUpdates"`
} }
func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *DashboardsAsConfig, folderId int64) (*dashboards.SaveDashboardDTO, error) { func createDashboardJSON(data *simplejson.Json, lastModified time.Time, cfg *config, folderID int64) (*dashboards.SaveDashboardDTO, error) {
dash := &dashboards.SaveDashboardDTO{} dash := &dashboards.SaveDashboardDTO{}
dash.Dashboard = models.NewDashboardFromJson(data) dash.Dashboard = models.NewDashboardFromJson(data)
dash.UpdatedAt = lastModified dash.UpdatedAt = lastModified
dash.Overwrite = true dash.Overwrite = true
dash.OrgId = cfg.OrgId dash.OrgId = cfg.OrgID
dash.Dashboard.OrgId = cfg.OrgId dash.Dashboard.OrgId = cfg.OrgID
dash.Dashboard.FolderId = folderId dash.Dashboard.FolderId = folderID
if dash.Dashboard.Title == "" { if dash.Dashboard.Title == "" {
return nil, models.ErrDashboardTitleEmpty return nil, models.ErrDashboardTitleEmpty
...@@ -73,8 +73,8 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das ...@@ -73,8 +73,8 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das
return dash, nil return dash, nil
} }
func mapV0ToDashboardsAsConfig(v0 []*DashboardsAsConfigV0) ([]*DashboardsAsConfig, error) { func mapV0ToDashboardsAsConfig(v0 []*configV0) ([]*config, error) {
var r []*DashboardsAsConfig var r []*config
seen := make(map[string]bool) seen := make(map[string]bool)
for _, v := range v0 { for _, v := range v0 {
...@@ -83,25 +83,25 @@ func mapV0ToDashboardsAsConfig(v0 []*DashboardsAsConfigV0) ([]*DashboardsAsConfi ...@@ -83,25 +83,25 @@ func mapV0ToDashboardsAsConfig(v0 []*DashboardsAsConfigV0) ([]*DashboardsAsConfi
} }
seen[v.Name] = true seen[v.Name] = true
r = append(r, &DashboardsAsConfig{ r = append(r, &config{
Name: v.Name, Name: v.Name,
Type: v.Type, Type: v.Type,
OrgId: v.OrgId, OrgID: v.OrgID,
Folder: v.Folder, Folder: v.Folder,
FolderUid: v.FolderUid, FolderUID: v.FolderUID,
Editable: v.Editable, Editable: v.Editable,
Options: v.Options, Options: v.Options,
DisableDeletion: v.DisableDeletion, DisableDeletion: v.DisableDeletion,
UpdateIntervalSeconds: v.UpdateIntervalSeconds, UpdateIntervalSeconds: v.UpdateIntervalSeconds,
AllowUiUpdates: v.AllowUiUpdates, AllowUIUpdates: v.AllowUIUpdates,
}) })
} }
return r, nil return r, nil
} }
func (dc *DashboardAsConfigV1) mapToDashboardsAsConfig() ([]*DashboardsAsConfig, error) { func (dc *configV1) mapToDashboardsAsConfig() ([]*config, error) {
var r []*DashboardsAsConfig var r []*config
seen := make(map[string]bool) seen := make(map[string]bool)
for _, v := range dc.Providers { for _, v := range dc.Providers {
...@@ -110,17 +110,17 @@ func (dc *DashboardAsConfigV1) mapToDashboardsAsConfig() ([]*DashboardsAsConfig, ...@@ -110,17 +110,17 @@ func (dc *DashboardAsConfigV1) mapToDashboardsAsConfig() ([]*DashboardsAsConfig,
} }
seen[v.Name.Value()] = true seen[v.Name.Value()] = true
r = append(r, &DashboardsAsConfig{ r = append(r, &config{
Name: v.Name.Value(), Name: v.Name.Value(),
Type: v.Type.Value(), Type: v.Type.Value(),
OrgId: v.OrgId.Value(), OrgID: v.OrgID.Value(),
Folder: v.Folder.Value(), Folder: v.Folder.Value(),
FolderUid: v.FolderUid.Value(), FolderUID: v.FolderUID.Value(),
Editable: v.Editable.Value(), Editable: v.Editable.Value(),
Options: v.Options.Value(), Options: v.Options.Value(),
DisableDeletion: v.DisableDeletion.Value(), DisableDeletion: v.DisableDeletion.Value(),
UpdateIntervalSeconds: v.UpdateIntervalSeconds.Value(), UpdateIntervalSeconds: v.UpdateIntervalSeconds.Value(),
AllowUiUpdates: v.AllowUiUpdates.Value(), AllowUIUpdates: v.AllowUIUpdates.Value(),
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment