Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
5fc255bd
Unverified
Commit
5fc255bd
authored
Apr 16, 2020
by
Carl Bergquist
Committed by
GitHub
Apr 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linting fixes for provisoning (#23600)
parent
6e313e7d
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
90 additions
and
88 deletions
+90
-88
.circleci/config.yml
+2
-1
pkg/api/dashboard.go
+2
-2
pkg/api/dashboard_test.go
+1
-1
pkg/services/dashboards/dashboard_service.go
+7
-6
pkg/services/provisioning/dashboards/config_reader.go
+12
-12
pkg/services/provisioning/dashboards/config_reader_test.go
+5
-5
pkg/services/provisioning/dashboards/dashboard.go
+3
-3
pkg/services/provisioning/dashboards/file_reader.go
+9
-9
pkg/services/provisioning/dashboards/file_reader_linux_test.go
+2
-2
pkg/services/provisioning/dashboards/file_reader_test.go
+15
-15
pkg/services/provisioning/dashboards/types.go
+32
-32
No files found.
.circleci/config.yml
View file @
5fc255bd
...
...
@@ -731,8 +731,9 @@ jobs:
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/...
./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/dashboards/...
./scripts/go/bin/gosec -quiet -exclude=G104,G107,G108,G201,G202,G204,G301,G304,G401,G402,G501 \
-conf=./scripts/go/configs/gosec.json ./pkg/...
...
...
pkg/api/dashboard.go
View file @
5fc255bd
...
...
@@ -107,7 +107,7 @@ func (hs *HTTPServer) GetDashboard(c *models.ReqContext) Response {
meta
.
FolderUrl
=
query
.
Result
.
GetUrl
()
}
provisioningData
,
err
:=
dashboards
.
NewProvisioningService
()
.
GetProvisionedDashboardDataByDashboardI
d
(
dash
.
Id
)
provisioningData
,
err
:=
dashboards
.
NewProvisioningService
()
.
GetProvisionedDashboardDataByDashboardI
D
(
dash
.
Id
)
if
err
!=
nil
{
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
}
}
provisioningData
,
err
:=
dashboards
.
NewProvisioningService
()
.
GetProvisionedDashboardDataByDashboardI
d
(
dash
.
Id
)
provisioningData
,
err
:=
dashboards
.
NewProvisioningService
()
.
GetProvisionedDashboardDataByDashboardI
D
(
dash
.
Id
)
if
err
!=
nil
{
return
Error
(
500
,
"Error while checking if dashboard is provisioned"
,
err
)
}
...
...
pkg/api/dashboard_test.go
View file @
5fc255bd
...
...
@@ -1196,7 +1196,7 @@ func (m mockDashboardProvisioningService) GetProvisionedDashboardData(name strin
panic
(
"implement me"
)
}
func
(
mock
mockDashboardProvisioningService
)
GetProvisionedDashboardDataByDashboardI
d
(
dashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
func
(
mock
mockDashboardProvisioningService
)
GetProvisionedDashboardDataByDashboardI
D
(
dashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
return
&
models
.
DashboardProvisioning
{},
nil
}
...
...
pkg/services/dashboards/dashboard_service.go
View file @
5fc255bd
package
dashboards
import
(
"github.com/grafana/grafana/pkg/components/gtime"
"github.com/grafana/grafana/pkg/setting"
"strings"
"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/infra/log"
"github.com/grafana/grafana/pkg/models"
...
...
@@ -26,7 +27,7 @@ type DashboardProvisioningService interface {
SaveProvisionedDashboard
(
dto
*
SaveDashboardDTO
,
provisioning
*
models
.
DashboardProvisioning
)
(
*
models
.
Dashboard
,
error
)
SaveFolderForProvisionedDashboards
(
*
SaveDashboardDTO
)
(
*
models
.
Dashboard
,
error
)
GetProvisionedDashboardData
(
name
string
)
([]
*
models
.
DashboardProvisioning
,
error
)
GetProvisionedDashboardDataByDashboardI
d
(
d
ashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
GetProvisionedDashboardDataByDashboardI
D
(
D
ashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
UnprovisionDashboard
(
dashboardId
int64
)
error
DeleteProvisionedDashboard
(
dashboardId
int64
,
orgId
int64
)
error
}
...
...
@@ -70,7 +71,7 @@ func (dr *dashboardServiceImpl) GetProvisionedDashboardData(name string) ([]*mod
return
cmd
.
Result
,
nil
}
func
(
dr
*
dashboardServiceImpl
)
GetProvisionedDashboardDataByDashboardI
d
(
dashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
func
(
dr
*
dashboardServiceImpl
)
GetProvisionedDashboardDataByDashboardI
D
(
dashboardId
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
cmd
:=
&
models
.
GetProvisionedDashboardDataByIdQuery
{
DashboardId
:
dashboardId
}
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
{
...
...
@@ -142,7 +143,7 @@ func (dr *dashboardServiceImpl) buildSaveDashboardCommand(dto *SaveDashboardDTO,
}
if
validateProvisionedDashboard
{
provisionedData
,
err
:=
dr
.
GetProvisionedDashboardDataByDashboardI
d
(
dash
.
Id
)
provisionedData
,
err
:=
dr
.
GetProvisionedDashboardDataByDashboardI
D
(
dash
.
Id
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -308,7 +309,7 @@ func (dr *dashboardServiceImpl) DeleteProvisionedDashboard(dashboardId int64, or
func
(
dr
*
dashboardServiceImpl
)
deleteDashboard
(
dashboardId
int64
,
orgId
int64
,
validateProvisionedDashboard
bool
)
error
{
if
validateProvisionedDashboard
{
provisionedData
,
err
:=
dr
.
GetProvisionedDashboardDataByDashboardI
d
(
dashboardId
)
provisionedData
,
err
:=
dr
.
GetProvisionedDashboardDataByDashboardI
D
(
dashboardId
)
if
err
!=
nil
{
return
errutil
.
Wrap
(
"failed to check if dashboard is provisioned"
,
err
)
}
...
...
pkg/services/provisioning/dashboards/config_reader.go
View file @
5fc255bd
...
...
@@ -16,14 +16,14 @@ type configReader struct {
log
log
.
Logger
}
func
(
cr
*
configReader
)
parseConfigs
(
file
os
.
FileInfo
)
([]
*
DashboardsAsC
onfig
,
error
)
{
func
(
cr
*
configReader
)
parseConfigs
(
file
os
.
FileInfo
)
([]
*
c
onfig
,
error
)
{
filename
,
_
:=
filepath
.
Abs
(
filepath
.
Join
(
cr
.
path
,
file
.
Name
()))
yamlFile
,
err
:=
ioutil
.
ReadFile
(
filename
)
if
err
!=
nil
{
return
nil
,
err
}
apiVersion
:=
&
ConfigVersion
{
Api
Version
:
0
}
apiVersion
:=
&
configVersion
{
API
Version
:
0
}
// 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
...
...
@@ -32,8 +32,8 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
// integer > max version?).
_
=
yaml
.
Unmarshal
(
yamlFile
,
&
apiVersion
)
if
apiVersion
.
A
pi
Version
>
0
{
v1
:=
&
DashboardAsC
onfigV1
{}
if
apiVersion
.
A
PI
Version
>
0
{
v1
:=
&
c
onfigV1
{}
err
:=
yaml
.
Unmarshal
(
yamlFile
,
&
v1
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -43,7 +43,7 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
return
v1
.
mapToDashboardsAsConfig
()
}
}
else
{
var
v0
[]
*
DashboardsAsC
onfigV0
var
v0
[]
*
c
onfigV0
err
:=
yaml
.
Unmarshal
(
yamlFile
,
&
v0
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -55,11 +55,11 @@ func (cr *configReader) parseConfigs(file os.FileInfo) ([]*DashboardsAsConfig, e
}
}
return
[]
*
DashboardsAsC
onfig
{},
nil
return
[]
*
c
onfig
{},
nil
}
func
(
cr
*
configReader
)
readConfig
()
([]
*
DashboardsAsC
onfig
,
error
)
{
var
dashboards
[]
*
DashboardsAsC
onfig
func
(
cr
*
configReader
)
readConfig
()
([]
*
c
onfig
,
error
)
{
var
dashboards
[]
*
c
onfig
files
,
err
:=
ioutil
.
ReadDir
(
cr
.
path
)
if
err
!=
nil
{
...
...
@@ -84,15 +84,15 @@ func (cr *configReader) readConfig() ([]*DashboardsAsConfig, error) {
uidUsage
:=
map
[
string
]
uint8
{}
for
_
,
dashboard
:=
range
dashboards
{
if
dashboard
.
OrgI
d
==
0
{
dashboard
.
OrgI
d
=
1
if
dashboard
.
OrgI
D
==
0
{
dashboard
.
OrgI
D
=
1
}
if
dashboard
.
UpdateIntervalSeconds
==
0
{
dashboard
.
UpdateIntervalSeconds
=
10
}
if
len
(
dashboard
.
FolderU
id
)
>
0
{
uidUsage
[
dashboard
.
FolderU
id
]
++
if
len
(
dashboard
.
FolderU
ID
)
>
0
{
uidUsage
[
dashboard
.
FolderU
ID
]
++
}
}
...
...
pkg/services/provisioning/dashboards/config_reader_test.go
View file @
5fc255bd
...
...
@@ -59,7 +59,7 @@ func TestDashboardsAsConfig(t *testing.T) {
})
})
}
func
validateDashboardAsConfig
(
t
*
testing
.
T
,
cfg
[]
*
DashboardsAsC
onfig
)
{
func
validateDashboardAsConfig
(
t
*
testing
.
T
,
cfg
[]
*
c
onfig
)
{
t
.
Helper
()
So
(
len
(
cfg
),
ShouldEqual
,
2
)
...
...
@@ -67,9 +67,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) {
ds
:=
cfg
[
0
]
So
(
ds
.
Name
,
ShouldEqual
,
"general dashboards"
)
So
(
ds
.
Type
,
ShouldEqual
,
"file"
)
So
(
ds
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
ds
.
OrgI
D
,
ShouldEqual
,
2
)
So
(
ds
.
Folder
,
ShouldEqual
,
"developers"
)
So
(
ds
.
FolderU
id
,
ShouldEqual
,
"xyz"
)
So
(
ds
.
FolderU
ID
,
ShouldEqual
,
"xyz"
)
So
(
ds
.
Editable
,
ShouldBeTrue
)
So
(
len
(
ds
.
Options
),
ShouldEqual
,
1
)
So
(
ds
.
Options
[
"path"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
...
...
@@ -79,9 +79,9 @@ func validateDashboardAsConfig(t *testing.T, cfg []*DashboardsAsConfig) {
ds2
:=
cfg
[
1
]
So
(
ds2
.
Name
,
ShouldEqual
,
"default"
)
So
(
ds2
.
Type
,
ShouldEqual
,
"file"
)
So
(
ds2
.
OrgI
d
,
ShouldEqual
,
1
)
So
(
ds2
.
OrgI
D
,
ShouldEqual
,
1
)
So
(
ds2
.
Folder
,
ShouldEqual
,
""
)
So
(
ds2
.
FolderU
id
,
ShouldEqual
,
""
)
So
(
ds2
.
FolderU
ID
,
ShouldEqual
,
""
)
So
(
ds2
.
Editable
,
ShouldBeFalse
)
So
(
len
(
ds2
.
Options
),
ShouldEqual
,
1
)
So
(
ds2
.
Options
[
"path"
],
ShouldEqual
,
"/var/lib/grafana/dashboards"
)
...
...
pkg/services/provisioning/dashboards/dashboard.go
View file @
5fc255bd
...
...
@@ -25,7 +25,7 @@ type DashboardProvisionerFactory func(string) (DashboardProvisioner, error)
type
Provisioner
struct
{
log
log
.
Logger
fileReaders
[]
*
FileReader
configs
[]
*
DashboardsAsC
onfig
configs
[]
*
c
onfig
}
// New returns a new DashboardProvisioner
...
...
@@ -94,13 +94,13 @@ func (provider *Provisioner) GetProvisionerResolvedPath(name string) string {
func
(
provider
*
Provisioner
)
GetAllowUIUpdatesFromConfig
(
name
string
)
bool
{
for
_
,
config
:=
range
provider
.
configs
{
if
config
.
Name
==
name
{
return
config
.
AllowU
i
Updates
return
config
.
AllowU
I
Updates
}
}
return
false
}
func
getFileReaders
(
configs
[]
*
DashboardsAsC
onfig
,
logger
log
.
Logger
)
([]
*
FileReader
,
error
)
{
func
getFileReaders
(
configs
[]
*
c
onfig
,
logger
log
.
Logger
)
([]
*
FileReader
,
error
)
{
var
readers
[]
*
FileReader
for
_
,
config
:=
range
configs
{
...
...
pkg/services/provisioning/dashboards/file_reader.go
View file @
5fc255bd
...
...
@@ -29,14 +29,14 @@ var (
// insert/update dashboards to the Grafana database using
// `dashboards.DashboardProvisioningService`
type
FileReader
struct
{
Cfg
*
DashboardsAsC
onfig
Cfg
*
c
onfig
Path
string
log
log
.
Logger
dashboardProvisioningService
dashboards
.
DashboardProvisioningService
}
// NewDashboardFileReader returns a new filereader based on `
DashboardsAsC
onfig`
func
NewDashboardFileReader
(
cfg
*
DashboardsAsC
onfig
,
log
log
.
Logger
)
(
*
FileReader
,
error
)
{
// NewDashboardFileReader returns a new filereader based on `
c
onfig`
func
NewDashboardFileReader
(
cfg
*
c
onfig
,
log
log
.
Logger
)
(
*
FileReader
,
error
)
{
var
path
string
path
,
ok
:=
cfg
.
Options
[
"path"
]
.
(
string
)
if
!
ok
{
...
...
@@ -139,7 +139,7 @@ func (fr *FileReader) handleMissingDashboardFiles(provisionedDashboardRefs map[s
// delete dashboard that are missing json file
for
_
,
dashboardID
:=
range
dashboardToDelete
{
fr
.
log
.
Debug
(
"deleting provisioned dashboard. missing on disk"
,
"id"
,
dashboardID
)
err
:=
fr
.
dashboardProvisioningService
.
DeleteProvisionedDashboard
(
dashboardID
,
fr
.
Cfg
.
OrgI
d
)
err
:=
fr
.
dashboardProvisioningService
.
DeleteProvisionedDashboard
(
dashboardID
,
fr
.
Cfg
.
OrgI
D
)
if
err
!=
nil
{
fr
.
log
.
Error
(
"failed to delete dashboard"
,
"id"
,
dashboardID
,
"error"
,
err
)
}
...
...
@@ -212,12 +212,12 @@ func getProvisionedDashboardByPath(service dashboards.DashboardProvisioningServi
return
byPath
,
nil
}
func
getOrCreateFolderID
(
cfg
*
DashboardsAsC
onfig
,
service
dashboards
.
DashboardProvisioningService
)
(
int64
,
error
)
{
func
getOrCreateFolderID
(
cfg
*
c
onfig
,
service
dashboards
.
DashboardProvisioningService
)
(
int64
,
error
)
{
if
cfg
.
Folder
==
""
{
return
0
,
ErrFolderNameMissing
}
cmd
:=
&
models
.
GetDashboardQuery
{
Slug
:
models
.
SlugifyTitle
(
cfg
.
Folder
),
OrgId
:
cfg
.
OrgI
d
}
cmd
:=
&
models
.
GetDashboardQuery
{
Slug
:
models
.
SlugifyTitle
(
cfg
.
Folder
),
OrgId
:
cfg
.
OrgI
D
}
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
&&
err
!=
models
.
ErrDashboardNotFound
{
...
...
@@ -230,9 +230,9 @@ func getOrCreateFolderID(cfg *DashboardsAsConfig, service dashboards.DashboardPr
dash
.
Dashboard
=
models
.
NewDashboardFolder
(
cfg
.
Folder
)
dash
.
Dashboard
.
IsFolder
=
true
dash
.
Overwrite
=
true
dash
.
OrgId
=
cfg
.
OrgI
d
dash
.
OrgId
=
cfg
.
OrgI
D
// set dashboard folderUid if given
dash
.
Dashboard
.
SetUid
(
cfg
.
FolderU
id
)
dash
.
Dashboard
.
SetUid
(
cfg
.
FolderU
ID
)
dbDash
,
err
:=
service
.
SaveFolderForProvisionedDashboards
(
dash
)
if
err
!=
nil
{
return
0
,
err
...
...
@@ -321,7 +321,7 @@ func (fr *FileReader) readDashboardFromFile(path string, lastModified time.Time,
return
nil
,
err
}
dash
,
err
:=
createDashboardJ
son
(
data
,
lastModified
,
fr
.
Cfg
,
folderID
)
dash
,
err
:=
createDashboardJ
SON
(
data
,
lastModified
,
fr
.
Cfg
,
folderID
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/services/provisioning/dashboards/file_reader_linux_test.go
View file @
5fc255bd
...
...
@@ -14,10 +14,10 @@ var (
)
func
TestProvsionedSymlinkedFolder
(
t
*
testing
.
T
)
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
""
,
Options
:
map
[
string
]
interface
{}{
"path"
:
symlinkedFolder
},
}
...
...
pkg/services/provisioning/dashboards/file_reader_test.go
View file @
5fc255bd
...
...
@@ -30,10 +30,10 @@ var (
func
TestCreatingNewDashboardFileReader
(
t
*
testing
.
T
)
{
Convey
(
"creating new dashboard file reader"
,
t
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
""
,
Options
:
map
[
string
]
interface
{}{},
}
...
...
@@ -88,10 +88,10 @@ func TestDashboardFileReader(t *testing.T) {
Convey
(
"Reading dashboards from disk"
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
""
,
Options
:
map
[
string
]
interface
{}{},
}
...
...
@@ -153,10 +153,10 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey
(
"Invalid configuration should return error"
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
""
,
}
...
...
@@ -172,8 +172,8 @@ func TestDashboardFileReader(t *testing.T) {
})
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
}}
cfg2
:=
&
DashboardsAsConfig
{
Name
:
"2"
,
Type
:
"file"
,
OrgId
:
1
,
Folder
:
"f2"
,
Options
:
map
[
string
]
interface
{}{
"path"
:
containingID
}}
cfg1
:=
&
config
{
Name
:
"1"
,
Type
:
"file"
,
OrgID
:
1
,
Folder
:
"f1"
,
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
)
So
(
err
,
ShouldBeNil
)
...
...
@@ -203,10 +203,10 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey
(
"Should not create new folder if folder name is missing"
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
""
,
Options
:
map
[
string
]
interface
{}{
"folder"
:
defaultDashboards
,
...
...
@@ -218,10 +218,10 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey
(
"can get or Create dashboard folder"
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Folder
:
"TEAM A"
,
Options
:
map
[
string
]
interface
{}{
"folder"
:
defaultDashboards
,
...
...
@@ -255,10 +255,10 @@ func TestDashboardFileReader(t *testing.T) {
})
Convey
(
"Given missing dashboard file"
,
func
()
{
cfg
:=
&
DashboardsAsC
onfig
{
cfg
:=
&
c
onfig
{
Name
:
"Default"
,
Type
:
"file"
,
OrgI
d
:
1
,
OrgI
D
:
1
,
Options
:
map
[
string
]
interface
{}{
"folder"
:
unprovision
,
},
...
...
@@ -436,7 +436,7 @@ func (s *fakeDashboardProvisioningService) DeleteProvisionedDashboard(dashboardI
return
nil
}
func
(
s
*
fakeDashboardProvisioningService
)
GetProvisionedDashboardDataByDashboardI
d
(
dashboardID
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
func
(
s
*
fakeDashboardProvisioningService
)
GetProvisionedDashboardDataByDashboardI
D
(
dashboardID
int64
)
(
*
models
.
DashboardProvisioning
,
error
)
{
return
nil
,
nil
}
...
...
pkg/services/provisioning/dashboards/types.go
View file @
5fc255bd
...
...
@@ -10,61 +10,61 @@ import (
"github.com/grafana/grafana/pkg/services/provisioning/values"
)
type
DashboardsAsC
onfig
struct
{
type
c
onfig
struct
{
Name
string
Type
string
OrgI
d
int64
OrgI
D
int64
Folder
string
FolderU
id
string
FolderU
ID
string
Editable
bool
Options
map
[
string
]
interface
{}
DisableDeletion
bool
UpdateIntervalSeconds
int64
AllowU
i
Updates
bool
AllowU
I
Updates
bool
}
type
DashboardsAsC
onfigV0
struct
{
type
c
onfigV0
struct
{
Name
string
`json:"name" yaml:"name"`
Type
string
`json:"type" yaml:"type"`
OrgI
d
int64
`json:"org_id" yaml:"org_id"`
OrgI
D
int64
`json:"org_id" yaml:"org_id"`
Folder
string
`json:"folder" yaml:"folder"`
FolderU
id
string
`json:"folderUid" yaml:"folderUid"`
FolderU
ID
string
`json:"folderUid" yaml:"folderUid"`
Editable
bool
`json:"editable" yaml:"editable"`
Options
map
[
string
]
interface
{}
`json:"options" yaml:"options"`
DisableDeletion
bool
`json:"disableDeletion" yaml:"disableDeletion"`
UpdateIntervalSeconds
int64
`json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
AllowU
i
Updates
bool
`json:"allowUiUpdates" yaml:"allowUiUpdates"`
AllowU
I
Updates
bool
`json:"allowUiUpdates" yaml:"allowUiUpdates"`
}
type
C
onfigVersion
struct
{
A
pi
Version
int64
`json:"apiVersion" yaml:"apiVersion"`
type
c
onfigVersion
struct
{
A
PI
Version
int64
`json:"apiVersion" yaml:"apiVersion"`
}
type
DashboardAsC
onfigV1
struct
{
Providers
[]
*
DashboardProviderC
onfigs
`json:"providers" yaml:"providers"`
type
c
onfigV1
struct
{
Providers
[]
*
c
onfigs
`json:"providers" yaml:"providers"`
}
type
DashboardProviderC
onfigs
struct
{
type
c
onfigs
struct
{
Name
values
.
StringValue
`json:"name" yaml:"name"`
Type
values
.
StringValue
`json:"type" yaml:"type"`
OrgI
d
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
OrgI
D
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
Folder
values
.
StringValue
`json:"folder" yaml:"folder"`
FolderU
id
values
.
StringValue
`json:"folderUid" yaml:"folderUid"`
FolderU
ID
values
.
StringValue
`json:"folderUid" yaml:"folderUid"`
Editable
values
.
BoolValue
`json:"editable" yaml:"editable"`
Options
values
.
JSONValue
`json:"options" yaml:"options"`
DisableDeletion
values
.
BoolValue
`json:"disableDeletion" yaml:"disableDeletion"`
UpdateIntervalSeconds
values
.
Int64Value
`json:"updateIntervalSeconds" yaml:"updateIntervalSeconds"`
AllowU
i
Updates
values
.
BoolValue
`json:"allowUiUpdates" yaml:"allowUiUpdates"`
AllowU
I
Updates
values
.
BoolValue
`json:"allowUiUpdates" yaml:"allowUiUpdates"`
}
func
createDashboardJ
son
(
data
*
simplejson
.
Json
,
lastModified
time
.
Time
,
cfg
*
DashboardsAsConfig
,
folderId
int64
)
(
*
dashboards
.
SaveDashboardDTO
,
error
)
{
func
createDashboardJ
SON
(
data
*
simplejson
.
Json
,
lastModified
time
.
Time
,
cfg
*
config
,
folderID
int64
)
(
*
dashboards
.
SaveDashboardDTO
,
error
)
{
dash
:=
&
dashboards
.
SaveDashboardDTO
{}
dash
.
Dashboard
=
models
.
NewDashboardFromJson
(
data
)
dash
.
UpdatedAt
=
lastModified
dash
.
Overwrite
=
true
dash
.
OrgId
=
cfg
.
OrgI
d
dash
.
Dashboard
.
OrgId
=
cfg
.
OrgI
d
dash
.
Dashboard
.
FolderId
=
folderI
d
dash
.
OrgId
=
cfg
.
OrgI
D
dash
.
Dashboard
.
OrgId
=
cfg
.
OrgI
D
dash
.
Dashboard
.
FolderId
=
folderI
D
if
dash
.
Dashboard
.
Title
==
""
{
return
nil
,
models
.
ErrDashboardTitleEmpty
...
...
@@ -73,8 +73,8 @@ func createDashboardJson(data *simplejson.Json, lastModified time.Time, cfg *Das
return
dash
,
nil
}
func
mapV0ToDashboardsAsConfig
(
v0
[]
*
DashboardsAsConfigV0
)
([]
*
DashboardsAsC
onfig
,
error
)
{
var
r
[]
*
DashboardsAsC
onfig
func
mapV0ToDashboardsAsConfig
(
v0
[]
*
configV0
)
([]
*
c
onfig
,
error
)
{
var
r
[]
*
c
onfig
seen
:=
make
(
map
[
string
]
bool
)
for
_
,
v
:=
range
v0
{
...
...
@@ -83,25 +83,25 @@ func mapV0ToDashboardsAsConfig(v0 []*DashboardsAsConfigV0) ([]*DashboardsAsConfi
}
seen
[
v
.
Name
]
=
true
r
=
append
(
r
,
&
DashboardsAsC
onfig
{
r
=
append
(
r
,
&
c
onfig
{
Name
:
v
.
Name
,
Type
:
v
.
Type
,
OrgI
d
:
v
.
OrgId
,
OrgI
D
:
v
.
OrgID
,
Folder
:
v
.
Folder
,
FolderU
id
:
v
.
FolderUid
,
FolderU
ID
:
v
.
FolderUID
,
Editable
:
v
.
Editable
,
Options
:
v
.
Options
,
DisableDeletion
:
v
.
DisableDeletion
,
UpdateIntervalSeconds
:
v
.
UpdateIntervalSeconds
,
AllowU
iUpdates
:
v
.
AllowUi
Updates
,
AllowU
IUpdates
:
v
.
AllowUI
Updates
,
})
}
return
r
,
nil
}
func
(
dc
*
DashboardAsConfigV1
)
mapToDashboardsAsConfig
()
([]
*
DashboardsAsC
onfig
,
error
)
{
var
r
[]
*
DashboardsAsC
onfig
func
(
dc
*
configV1
)
mapToDashboardsAsConfig
()
([]
*
c
onfig
,
error
)
{
var
r
[]
*
c
onfig
seen
:=
make
(
map
[
string
]
bool
)
for
_
,
v
:=
range
dc
.
Providers
{
...
...
@@ -110,17 +110,17 @@ func (dc *DashboardAsConfigV1) mapToDashboardsAsConfig() ([]*DashboardsAsConfig,
}
seen
[
v
.
Name
.
Value
()]
=
true
r
=
append
(
r
,
&
DashboardsAsC
onfig
{
r
=
append
(
r
,
&
c
onfig
{
Name
:
v
.
Name
.
Value
(),
Type
:
v
.
Type
.
Value
(),
OrgI
d
:
v
.
OrgId
.
Value
(),
OrgI
D
:
v
.
OrgID
.
Value
(),
Folder
:
v
.
Folder
.
Value
(),
FolderU
id
:
v
.
FolderUid
.
Value
(),
FolderU
ID
:
v
.
FolderUID
.
Value
(),
Editable
:
v
.
Editable
.
Value
(),
Options
:
v
.
Options
.
Value
(),
DisableDeletion
:
v
.
DisableDeletion
.
Value
(),
UpdateIntervalSeconds
:
v
.
UpdateIntervalSeconds
.
Value
(),
AllowU
iUpdates
:
v
.
AllowUi
Updates
.
Value
(),
AllowU
IUpdates
:
v
.
AllowUI
Updates
.
Value
(),
})
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment