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
0fd59455
Unverified
Commit
0fd59455
authored
Apr 11, 2020
by
Carl Bergquist
Committed by
GitHub
Apr 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes linting errors in datasource provisioning. (#23515)
parent
6f1a25a8
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
116 additions
and
109 deletions
+116
-109
.circleci/config.yml
+2
-1
Makefile
+2
-1
go.sum
+0
-4
pkg/services/provisioning/datasources/config_reader.go
+17
-17
pkg/services/provisioning/datasources/config_reader_test.go
+17
-15
pkg/services/provisioning/datasources/datasources.go
+10
-4
pkg/services/provisioning/datasources/types.go
+68
-67
No files found.
.circleci/config.yml
View file @
0fd59455
...
@@ -731,7 +731,8 @@ jobs:
...
@@ -731,7 +731,8 @@ 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 -formatter stylish ./pkg/services/alerting/...
./scripts/go/bin/revive -formatter stylish ./pkg/services/provisioning/datasources/...
./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/...
...
...
Makefile
View file @
0fd59455
...
@@ -84,7 +84,8 @@ revive-alerting: scripts/go/bin/revive
...
@@ -84,7 +84,8 @@ revive-alerting: scripts/go/bin/revive
@
echo
"lint alerting via revive"
@
echo
"lint alerting via revive"
@
scripts/go/bin/revive
\
@
scripts/go/bin/revive
\
-formatter
stylish
\
-formatter
stylish
\
./pkg/services/alerting/...
./pkg/services/alerting/...
\
./pkg/services/provisioning/datasources/...
scripts/go/bin/golangci-lint
:
scripts/go/go.mod
scripts/go/bin/golangci-lint
:
scripts/go/go.mod
@
cd
scripts/go
;
\
@
cd
scripts/go
;
\
...
...
go.sum
View file @
0fd59455
...
@@ -133,10 +133,6 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ=
...
@@ -133,10 +133,6 @@ github.com/gosimple/slug v1.4.2 h1:jDmprx3q/9Lfk4FkGZtvzDQ9Cj9eAmsjzeQGp24PeiQ=
github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/gosimple/slug v1.4.2/go.mod h1:ER78kgg1Mv0NQGlXiDe57DpCyfbNywXXZ9mIorhxAf0=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 h1:SPdxCL9BChFTlyi0Khv64vdCW4TMna8+sxL7+Chx+Ag=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4 h1:SPdxCL9BChFTlyi0Khv64vdCW4TMna8+sxL7+Chx+Ag=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To=
github.com/grafana/grafana-plugin-model v0.0.0-20190930120109-1fc953a61fb4/go.mod h1:nc0XxBzjeGcrMltCDw269LoWF9S8ibhgxolCdA1R8To=
github.com/grafana/grafana-plugin-sdk-go v0.39.0 h1:tPP83HeY9gN4q8O3tYka1vd82OQ/3CFdwx4QeEhJ0Qc=
github.com/grafana/grafana-plugin-sdk-go v0.39.0/go.mod h1:xRhfTHl+Dkqf2Py6Lr4pcHBC5pm8/N+IwPJ0R/iAHMM=
github.com/grafana/grafana-plugin-sdk-go v0.40.1-0.20200409163705-fd66aee09a52 h1:WEfl8G9uHk31r3pnAmsK+NRcHGpXnXauWmbhic3KuVU=
github.com/grafana/grafana-plugin-sdk-go v0.40.1-0.20200409163705-fd66aee09a52/go.mod h1:xRhfTHl+Dkqf2Py6Lr4pcHBC5pm8/N+IwPJ0R/iAHMM=
github.com/grafana/grafana-plugin-sdk-go v0.42.0 h1:8oiAQa/uABBFT70GDAv3BnqHfdMOxy/P8SzYVURJH6Y=
github.com/grafana/grafana-plugin-sdk-go v0.42.0 h1:8oiAQa/uABBFT70GDAv3BnqHfdMOxy/P8SzYVURJH6Y=
github.com/grafana/grafana-plugin-sdk-go v0.42.0/go.mod h1:xRhfTHl+Dkqf2Py6Lr4pcHBC5pm8/N+IwPJ0R/iAHMM=
github.com/grafana/grafana-plugin-sdk-go v0.42.0/go.mod h1:xRhfTHl+Dkqf2Py6Lr4pcHBC5pm8/N+IwPJ0R/iAHMM=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd h1:rNuUHR+CvK1IS89MMtcF0EpcVMZtjKfPRp4MEmt/aTs=
...
...
pkg/services/provisioning/datasources/config_reader.go
View file @
0fd59455
...
@@ -14,8 +14,8 @@ type configReader struct {
...
@@ -14,8 +14,8 @@ type configReader struct {
log
log
.
Logger
log
log
.
Logger
}
}
func
(
cr
*
configReader
)
readConfig
(
path
string
)
([]
*
DatasourcesAsConfig
,
error
)
{
func
(
cr
*
configReader
)
readConfig
(
path
string
)
([]
*
configs
,
error
)
{
var
datasources
[]
*
DatasourcesAsConfig
var
datasources
[]
*
configs
files
,
err
:=
ioutil
.
ReadDir
(
path
)
files
,
err
:=
ioutil
.
ReadDir
(
path
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -44,34 +44,34 @@ func (cr *configReader) readConfig(path string) ([]*DatasourcesAsConfig, error)
...
@@ -44,34 +44,34 @@ func (cr *configReader) readConfig(path string) ([]*DatasourcesAsConfig, error)
return
datasources
,
nil
return
datasources
,
nil
}
}
func
(
cr
*
configReader
)
parseDatasourceConfig
(
path
string
,
file
os
.
FileInfo
)
(
*
DatasourcesAsConfig
,
error
)
{
func
(
cr
*
configReader
)
parseDatasourceConfig
(
path
string
,
file
os
.
FileInfo
)
(
*
configs
,
error
)
{
filename
,
_
:=
filepath
.
Abs
(
filepath
.
Join
(
path
,
file
.
Name
()))
filename
,
_
:=
filepath
.
Abs
(
filepath
.
Join
(
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
}
}
var
apiVersion
*
C
onfigVersion
var
apiVersion
*
c
onfigVersion
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
apiVersion
)
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
apiVersion
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
if
apiVersion
==
nil
{
if
apiVersion
==
nil
{
apiVersion
=
&
ConfigVersion
{
Api
Version
:
0
}
apiVersion
=
&
configVersion
{
API
Version
:
0
}
}
}
if
apiVersion
.
A
pi
Version
>
0
{
if
apiVersion
.
A
PI
Version
>
0
{
v1
:=
&
DatasourcesAsConfig
V1
{
log
:
cr
.
log
}
v1
:=
&
configs
V1
{
log
:
cr
.
log
}
err
=
yaml
.
Unmarshal
(
yamlFile
,
v1
)
err
=
yaml
.
Unmarshal
(
yamlFile
,
v1
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
v1
.
mapToDatasourceFromConfig
(
apiVersion
.
A
pi
Version
),
nil
return
v1
.
mapToDatasourceFromConfig
(
apiVersion
.
A
PI
Version
),
nil
}
}
var
v0
*
DatasourcesAsConfig
V0
var
v0
*
configs
V0
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
v0
)
err
=
yaml
.
Unmarshal
(
yamlFile
,
&
v0
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -79,10 +79,10 @@ func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*D
...
@@ -79,10 +79,10 @@ func (cr *configReader) parseDatasourceConfig(path string, file os.FileInfo) (*D
cr
.
log
.
Warn
(
"[Deprecated] the datasource provisioning config is outdated. please upgrade"
,
"filename"
,
filename
)
cr
.
log
.
Warn
(
"[Deprecated] the datasource provisioning config is outdated. please upgrade"
,
"filename"
,
filename
)
return
v0
.
mapToDatasourceFromConfig
(
apiVersion
.
A
pi
Version
),
nil
return
v0
.
mapToDatasourceFromConfig
(
apiVersion
.
A
PI
Version
),
nil
}
}
func
validateDefaultUniqueness
(
datasources
[]
*
DatasourcesAsConfig
)
error
{
func
validateDefaultUniqueness
(
datasources
[]
*
configs
)
error
{
defaultCount
:=
map
[
int64
]
int
{}
defaultCount
:=
map
[
int64
]
int
{}
for
i
:=
range
datasources
{
for
i
:=
range
datasources
{
if
datasources
[
i
]
.
Datasources
==
nil
{
if
datasources
[
i
]
.
Datasources
==
nil
{
...
@@ -90,21 +90,21 @@ func validateDefaultUniqueness(datasources []*DatasourcesAsConfig) error {
...
@@ -90,21 +90,21 @@ func validateDefaultUniqueness(datasources []*DatasourcesAsConfig) error {
}
}
for
_
,
ds
:=
range
datasources
[
i
]
.
Datasources
{
for
_
,
ds
:=
range
datasources
[
i
]
.
Datasources
{
if
ds
.
OrgI
d
==
0
{
if
ds
.
OrgI
D
==
0
{
ds
.
OrgI
d
=
1
ds
.
OrgI
D
=
1
}
}
if
ds
.
IsDefault
{
if
ds
.
IsDefault
{
defaultCount
[
ds
.
OrgI
d
]
=
defaultCount
[
ds
.
OrgId
]
+
1
defaultCount
[
ds
.
OrgI
D
]
=
defaultCount
[
ds
.
OrgID
]
+
1
if
defaultCount
[
ds
.
OrgI
d
]
>
1
{
if
defaultCount
[
ds
.
OrgI
D
]
>
1
{
return
ErrInvalidConfigToManyDefault
return
ErrInvalidConfigToManyDefault
}
}
}
}
}
}
for
_
,
ds
:=
range
datasources
[
i
]
.
DeleteDatasources
{
for
_
,
ds
:=
range
datasources
[
i
]
.
DeleteDatasources
{
if
ds
.
OrgI
d
==
0
{
if
ds
.
OrgI
D
==
0
{
ds
.
OrgI
d
=
1
ds
.
OrgI
D
=
1
}
}
}
}
}
}
...
...
pkg/services/provisioning/datasources/config_reader_test.go
View file @
0fd59455
...
@@ -159,7 +159,7 @@ func TestDatasourceAsConfig(t *testing.T) {
...
@@ -159,7 +159,7 @@ func TestDatasourceAsConfig(t *testing.T) {
dsCfg
:=
cfg
[
0
]
dsCfg
:=
cfg
[
0
]
So
(
dsCfg
.
A
pi
Version
,
ShouldEqual
,
1
)
So
(
dsCfg
.
A
PI
Version
,
ShouldEqual
,
1
)
validateDatasource
(
dsCfg
)
validateDatasource
(
dsCfg
)
validateDeleteDatasources
(
dsCfg
)
validateDeleteDatasources
(
dsCfg
)
...
@@ -187,26 +187,28 @@ func TestDatasourceAsConfig(t *testing.T) {
...
@@ -187,26 +187,28 @@ func TestDatasourceAsConfig(t *testing.T) {
dsCfg
:=
cfg
[
0
]
dsCfg
:=
cfg
[
0
]
So
(
dsCfg
.
A
pi
Version
,
ShouldEqual
,
0
)
So
(
dsCfg
.
A
PI
Version
,
ShouldEqual
,
0
)
validateDatasource
(
dsCfg
)
validateDatasource
(
dsCfg
)
validateDeleteDatasources
(
dsCfg
)
validateDeleteDatasources
(
dsCfg
)
})
})
})
})
}
}
func
validateDeleteDatasources
(
dsCfg
*
DatasourcesAsConfig
)
{
func
validateDeleteDatasources
(
dsCfg
*
configs
)
{
So
(
len
(
dsCfg
.
DeleteDatasources
),
ShouldEqual
,
1
)
So
(
len
(
dsCfg
.
DeleteDatasources
),
ShouldEqual
,
1
)
deleteDs
:=
dsCfg
.
DeleteDatasources
[
0
]
deleteDs
:=
dsCfg
.
DeleteDatasources
[
0
]
So
(
deleteDs
.
Name
,
ShouldEqual
,
"old-graphite3"
)
So
(
deleteDs
.
Name
,
ShouldEqual
,
"old-graphite3"
)
So
(
deleteDs
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
deleteDs
.
OrgI
D
,
ShouldEqual
,
2
)
}
}
func
validateDatasource
(
dsCfg
*
DatasourcesAsConfig
)
{
func
validateDatasource
(
dsCfg
*
configs
)
{
ds
:=
dsCfg
.
Datasources
[
0
]
ds
:=
dsCfg
.
Datasources
[
0
]
So
(
ds
.
Name
,
ShouldEqual
,
"name"
)
So
(
ds
.
Name
,
ShouldEqual
,
"name"
)
So
(
ds
.
Type
,
ShouldEqual
,
"type"
)
So
(
ds
.
Type
,
ShouldEqual
,
"type"
)
So
(
ds
.
Access
,
ShouldEqual
,
models
.
DS_ACCESS_PROXY
)
So
(
ds
.
Access
,
ShouldEqual
,
models
.
DS_ACCESS_PROXY
)
So
(
ds
.
OrgI
d
,
ShouldEqual
,
2
)
So
(
ds
.
OrgI
D
,
ShouldEqual
,
2
)
So
(
ds
.
U
rl
,
ShouldEqual
,
"url"
)
So
(
ds
.
U
RL
,
ShouldEqual
,
"url"
)
So
(
ds
.
User
,
ShouldEqual
,
"user"
)
So
(
ds
.
User
,
ShouldEqual
,
"user"
)
So
(
ds
.
Password
,
ShouldEqual
,
"password"
)
So
(
ds
.
Password
,
ShouldEqual
,
"password"
)
So
(
ds
.
Database
,
ShouldEqual
,
"database"
)
So
(
ds
.
Database
,
ShouldEqual
,
"database"
)
...
@@ -218,15 +220,15 @@ func validateDatasource(dsCfg *DatasourcesAsConfig) {
...
@@ -218,15 +220,15 @@ func validateDatasource(dsCfg *DatasourcesAsConfig) {
So
(
ds
.
Editable
,
ShouldBeTrue
)
So
(
ds
.
Editable
,
ShouldBeTrue
)
So
(
ds
.
Version
,
ShouldEqual
,
10
)
So
(
ds
.
Version
,
ShouldEqual
,
10
)
So
(
len
(
ds
.
J
son
Data
),
ShouldBeGreaterThan
,
2
)
So
(
len
(
ds
.
J
SON
Data
),
ShouldBeGreaterThan
,
2
)
So
(
ds
.
J
son
Data
[
"graphiteVersion"
],
ShouldEqual
,
"1.1"
)
So
(
ds
.
J
SON
Data
[
"graphiteVersion"
],
ShouldEqual
,
"1.1"
)
So
(
ds
.
J
son
Data
[
"tlsAuth"
],
ShouldEqual
,
true
)
So
(
ds
.
J
SON
Data
[
"tlsAuth"
],
ShouldEqual
,
true
)
So
(
ds
.
J
son
Data
[
"tlsAuthWithCACert"
],
ShouldEqual
,
true
)
So
(
ds
.
J
SON
Data
[
"tlsAuthWithCACert"
],
ShouldEqual
,
true
)
So
(
len
(
ds
.
SecureJ
son
Data
),
ShouldBeGreaterThan
,
2
)
So
(
len
(
ds
.
SecureJ
SON
Data
),
ShouldBeGreaterThan
,
2
)
So
(
ds
.
SecureJ
son
Data
[
"tlsCACert"
],
ShouldEqual
,
"MjNOcW9RdkbUDHZmpco2HCYzVq9dE+i6Yi+gmUJotq5CDA=="
)
So
(
ds
.
SecureJ
SON
Data
[
"tlsCACert"
],
ShouldEqual
,
"MjNOcW9RdkbUDHZmpco2HCYzVq9dE+i6Yi+gmUJotq5CDA=="
)
So
(
ds
.
SecureJ
son
Data
[
"tlsClientCert"
],
ShouldEqual
,
"ckN0dGlyMXN503YNfjTcf9CV+GGQneN+xmAclQ=="
)
So
(
ds
.
SecureJ
SON
Data
[
"tlsClientCert"
],
ShouldEqual
,
"ckN0dGlyMXN503YNfjTcf9CV+GGQneN+xmAclQ=="
)
So
(
ds
.
SecureJ
son
Data
[
"tlsClientKey"
],
ShouldEqual
,
"ZkN4aG1aNkja/gKAB1wlnKFIsy2SRDq4slrM0A=="
)
So
(
ds
.
SecureJ
SON
Data
[
"tlsClientKey"
],
ShouldEqual
,
"ZkN4aG1aNkja/gKAB1wlnKFIsy2SRDq4slrM0A=="
)
}
}
type
fakeRepository
struct
{
type
fakeRepository
struct
{
...
...
pkg/services/provisioning/datasources/datasources.go
View file @
0fd59455
...
@@ -11,14 +11,20 @@ import (
...
@@ -11,14 +11,20 @@ import (
)
)
var
(
var
(
// ErrInvalidConfigToManyDefault indicates that multiple datasource in the provisioning files
// contains more than one datasource marked as default.
ErrInvalidConfigToManyDefault
=
errors
.
New
(
"datasource.yaml config is invalid. Only one datasource per organization can be marked as default"
)
ErrInvalidConfigToManyDefault
=
errors
.
New
(
"datasource.yaml config is invalid. Only one datasource per organization can be marked as default"
)
)
)
// Provision scans a directory for provisioning config files
// and provisions the datasource in those files.
func
Provision
(
configDirectory
string
)
error
{
func
Provision
(
configDirectory
string
)
error
{
dc
:=
newDatasourceProvisioner
(
log
.
New
(
"provisioning.datasources"
))
dc
:=
newDatasourceProvisioner
(
log
.
New
(
"provisioning.datasources"
))
return
dc
.
applyChanges
(
configDirectory
)
return
dc
.
applyChanges
(
configDirectory
)
}
}
// DatasourceProvisioner is responsible for provisioning datasources based on
// configuration read by the `configReader`
type
DatasourceProvisioner
struct
{
type
DatasourceProvisioner
struct
{
log
log
.
Logger
log
log
.
Logger
cfgProvider
*
configReader
cfgProvider
*
configReader
...
@@ -31,13 +37,13 @@ func newDatasourceProvisioner(log log.Logger) DatasourceProvisioner {
...
@@ -31,13 +37,13 @@ func newDatasourceProvisioner(log log.Logger) DatasourceProvisioner {
}
}
}
}
func
(
dc
*
DatasourceProvisioner
)
apply
(
cfg
*
DatasourcesAsConfig
)
error
{
func
(
dc
*
DatasourceProvisioner
)
apply
(
cfg
*
configs
)
error
{
if
err
:=
dc
.
deleteDatasources
(
cfg
.
DeleteDatasources
);
err
!=
nil
{
if
err
:=
dc
.
deleteDatasources
(
cfg
.
DeleteDatasources
);
err
!=
nil
{
return
err
return
err
}
}
for
_
,
ds
:=
range
cfg
.
Datasources
{
for
_
,
ds
:=
range
cfg
.
Datasources
{
cmd
:=
&
models
.
GetDataSourceByNameQuery
{
OrgId
:
ds
.
OrgI
d
,
Name
:
ds
.
Name
}
cmd
:=
&
models
.
GetDataSourceByNameQuery
{
OrgId
:
ds
.
OrgI
D
,
Name
:
ds
.
Name
}
err
:=
bus
.
Dispatch
(
cmd
)
err
:=
bus
.
Dispatch
(
cmd
)
if
err
!=
nil
&&
err
!=
models
.
ErrDataSourceNotFound
{
if
err
!=
nil
&&
err
!=
models
.
ErrDataSourceNotFound
{
return
err
return
err
...
@@ -76,9 +82,9 @@ func (dc *DatasourceProvisioner) applyChanges(configPath string) error {
...
@@ -76,9 +82,9 @@ func (dc *DatasourceProvisioner) applyChanges(configPath string) error {
return
nil
return
nil
}
}
func
(
dc
*
DatasourceProvisioner
)
deleteDatasources
(
dsToDelete
[]
*
D
eleteDatasourceConfig
)
error
{
func
(
dc
*
DatasourceProvisioner
)
deleteDatasources
(
dsToDelete
[]
*
d
eleteDatasourceConfig
)
error
{
for
_
,
ds
:=
range
dsToDelete
{
for
_
,
ds
:=
range
dsToDelete
{
cmd
:=
&
models
.
DeleteDataSourceByNameCommand
{
OrgId
:
ds
.
OrgI
d
,
Name
:
ds
.
Name
}
cmd
:=
&
models
.
DeleteDataSourceByNameCommand
{
OrgId
:
ds
.
OrgI
D
,
Name
:
ds
.
Name
}
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
if
err
:=
bus
.
Dispatch
(
cmd
);
err
!=
nil
{
return
err
return
err
}
}
...
...
pkg/services/provisioning/datasources/types.go
View file @
0fd59455
...
@@ -7,30 +7,31 @@ import (
...
@@ -7,30 +7,31 @@ import (
"github.com/grafana/grafana/pkg/services/provisioning/values"
"github.com/grafana/grafana/pkg/services/provisioning/values"
)
)
type
ConfigVersion
struct
{
// ConfigVersion is used to figure out which API version a config uses.
ApiVersion
int64
`json:"apiVersion" yaml:"apiVersion"`
type
configVersion
struct
{
APIVersion
int64
`json:"apiVersion" yaml:"apiVersion"`
}
}
type
DatasourcesAsConfig
struct
{
type
configs
struct
{
A
pi
Version
int64
A
PI
Version
int64
Datasources
[]
*
DataSourceFromConfig
Datasources
[]
*
upsert
DataSourceFromConfig
DeleteDatasources
[]
*
D
eleteDatasourceConfig
DeleteDatasources
[]
*
d
eleteDatasourceConfig
}
}
type
D
eleteDatasourceConfig
struct
{
type
d
eleteDatasourceConfig
struct
{
OrgI
d
int64
OrgI
D
int64
Name
string
Name
string
}
}
type
DataSourceFromConfig
struct
{
type
upsert
DataSourceFromConfig
struct
{
OrgI
d
int64
OrgI
D
int64
Version
int
Version
int
Name
string
Name
string
Type
string
Type
string
Access
string
Access
string
U
rl
string
U
RL
string
Password
string
Password
string
User
string
User
string
Database
string
Database
string
...
@@ -39,43 +40,43 @@ type DataSourceFromConfig struct {
...
@@ -39,43 +40,43 @@ type DataSourceFromConfig struct {
BasicAuthPassword
string
BasicAuthPassword
string
WithCredentials
bool
WithCredentials
bool
IsDefault
bool
IsDefault
bool
J
son
Data
map
[
string
]
interface
{}
J
SON
Data
map
[
string
]
interface
{}
SecureJ
son
Data
map
[
string
]
string
SecureJ
SON
Data
map
[
string
]
string
Editable
bool
Editable
bool
}
}
type
DatasourcesAsConfig
V0
struct
{
type
configs
V0
struct
{
C
onfigVersion
c
onfigVersion
Datasources
[]
*
DataSourceFromConfigV0
`json:"datasources" yaml:"datasources"`
Datasources
[]
*
upsertDataSourceFromConfigV0
`json:"datasources" yaml:"datasources"`
DeleteDatasources
[]
*
DeleteDatasourceConfigV0
`json:"delete_datasources" yaml:"delete_datasources"`
DeleteDatasources
[]
*
deleteDatasourceConfigV0
`json:"delete_datasources" yaml:"delete_datasources"`
}
}
type
DatasourcesAsConfig
V1
struct
{
type
configs
V1
struct
{
C
onfigVersion
c
onfigVersion
log
log
.
Logger
log
log
.
Logger
Datasources
[]
*
DataSourceFromConfigV1
`json:"datasources" yaml:"datasources"`
Datasources
[]
*
upsertDataSourceFromConfigV1
`json:"datasources" yaml:"datasources"`
DeleteDatasources
[]
*
DeleteDatasourceConfigV1
`json:"deleteDatasources" yaml:"deleteDatasources"`
DeleteDatasources
[]
*
deleteDatasourceConfigV1
`json:"deleteDatasources" yaml:"deleteDatasources"`
}
}
type
D
eleteDatasourceConfigV0
struct
{
type
d
eleteDatasourceConfigV0
struct
{
OrgI
d
int64
`json:"org_id" yaml:"org_id"`
OrgI
D
int64
`json:"org_id" yaml:"org_id"`
Name
string
`json:"name" yaml:"name"`
Name
string
`json:"name" yaml:"name"`
}
}
type
D
eleteDatasourceConfigV1
struct
{
type
d
eleteDatasourceConfigV1
struct
{
OrgI
d
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
OrgI
D
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
Name
values
.
StringValue
`json:"name" yaml:"name"`
}
}
type
DataSourceFromConfigV0
struct
{
type
upsert
DataSourceFromConfigV0
struct
{
OrgI
d
int64
`json:"org_id" yaml:"org_id"`
OrgI
D
int64
`json:"org_id" yaml:"org_id"`
Version
int
`json:"version" yaml:"version"`
Version
int
`json:"version" yaml:"version"`
Name
string
`json:"name" yaml:"name"`
Name
string
`json:"name" yaml:"name"`
Type
string
`json:"type" yaml:"type"`
Type
string
`json:"type" yaml:"type"`
Access
string
`json:"access" yaml:"access"`
Access
string
`json:"access" yaml:"access"`
U
rl
string
`json:"url" yaml:"url"`
U
RL
string
`json:"url" yaml:"url"`
Password
string
`json:"password" yaml:"password"`
Password
string
`json:"password" yaml:"password"`
User
string
`json:"user" yaml:"user"`
User
string
`json:"user" yaml:"user"`
Database
string
`json:"database" yaml:"database"`
Database
string
`json:"database" yaml:"database"`
...
@@ -84,18 +85,18 @@ type DataSourceFromConfigV0 struct {
...
@@ -84,18 +85,18 @@ type DataSourceFromConfigV0 struct {
BasicAuthPassword
string
`json:"basic_auth_password" yaml:"basic_auth_password"`
BasicAuthPassword
string
`json:"basic_auth_password" yaml:"basic_auth_password"`
WithCredentials
bool
`json:"with_credentials" yaml:"with_credentials"`
WithCredentials
bool
`json:"with_credentials" yaml:"with_credentials"`
IsDefault
bool
`json:"is_default" yaml:"is_default"`
IsDefault
bool
`json:"is_default" yaml:"is_default"`
J
son
Data
map
[
string
]
interface
{}
`json:"json_data" yaml:"json_data"`
J
SON
Data
map
[
string
]
interface
{}
`json:"json_data" yaml:"json_data"`
SecureJ
son
Data
map
[
string
]
string
`json:"secure_json_data" yaml:"secure_json_data"`
SecureJ
SON
Data
map
[
string
]
string
`json:"secure_json_data" yaml:"secure_json_data"`
Editable
bool
`json:"editable" yaml:"editable"`
Editable
bool
`json:"editable" yaml:"editable"`
}
}
type
DataSourceFromConfigV1
struct
{
type
upsert
DataSourceFromConfigV1
struct
{
OrgI
d
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
OrgI
D
values
.
Int64Value
`json:"orgId" yaml:"orgId"`
Version
values
.
IntValue
`json:"version" yaml:"version"`
Version
values
.
IntValue
`json:"version" yaml:"version"`
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"`
Access
values
.
StringValue
`json:"access" yaml:"access"`
Access
values
.
StringValue
`json:"access" yaml:"access"`
U
rl
values
.
StringValue
`json:"url" yaml:"url"`
U
RL
values
.
StringValue
`json:"url" yaml:"url"`
Password
values
.
StringValue
`json:"password" yaml:"password"`
Password
values
.
StringValue
`json:"password" yaml:"password"`
User
values
.
StringValue
`json:"user" yaml:"user"`
User
values
.
StringValue
`json:"user" yaml:"user"`
Database
values
.
StringValue
`json:"database" yaml:"database"`
Database
values
.
StringValue
`json:"database" yaml:"database"`
...
@@ -104,27 +105,27 @@ type DataSourceFromConfigV1 struct {
...
@@ -104,27 +105,27 @@ type DataSourceFromConfigV1 struct {
BasicAuthPassword
values
.
StringValue
`json:"basicAuthPassword" yaml:"basicAuthPassword"`
BasicAuthPassword
values
.
StringValue
`json:"basicAuthPassword" yaml:"basicAuthPassword"`
WithCredentials
values
.
BoolValue
`json:"withCredentials" yaml:"withCredentials"`
WithCredentials
values
.
BoolValue
`json:"withCredentials" yaml:"withCredentials"`
IsDefault
values
.
BoolValue
`json:"isDefault" yaml:"isDefault"`
IsDefault
values
.
BoolValue
`json:"isDefault" yaml:"isDefault"`
J
son
Data
values
.
JSONValue
`json:"jsonData" yaml:"jsonData"`
J
SON
Data
values
.
JSONValue
`json:"jsonData" yaml:"jsonData"`
SecureJ
son
Data
values
.
StringMapValue
`json:"secureJsonData" yaml:"secureJsonData"`
SecureJ
SON
Data
values
.
StringMapValue
`json:"secureJsonData" yaml:"secureJsonData"`
Editable
values
.
BoolValue
`json:"editable" yaml:"editable"`
Editable
values
.
BoolValue
`json:"editable" yaml:"editable"`
}
}
func
(
cfg
*
DatasourcesAsConfigV1
)
mapToDatasourceFromConfig
(
apiVersion
int64
)
*
DatasourcesAsConfig
{
func
(
cfg
*
configsV1
)
mapToDatasourceFromConfig
(
apiVersion
int64
)
*
configs
{
r
:=
&
DatasourcesAsConfig
{}
r
:=
&
configs
{}
r
.
A
pi
Version
=
apiVersion
r
.
A
PI
Version
=
apiVersion
if
cfg
==
nil
{
if
cfg
==
nil
{
return
r
return
r
}
}
for
_
,
ds
:=
range
cfg
.
Datasources
{
for
_
,
ds
:=
range
cfg
.
Datasources
{
r
.
Datasources
=
append
(
r
.
Datasources
,
&
DataSourceFromConfig
{
r
.
Datasources
=
append
(
r
.
Datasources
,
&
upsert
DataSourceFromConfig
{
OrgI
d
:
ds
.
OrgId
.
Value
(),
OrgI
D
:
ds
.
OrgID
.
Value
(),
Name
:
ds
.
Name
.
Value
(),
Name
:
ds
.
Name
.
Value
(),
Type
:
ds
.
Type
.
Value
(),
Type
:
ds
.
Type
.
Value
(),
Access
:
ds
.
Access
.
Value
(),
Access
:
ds
.
Access
.
Value
(),
U
rl
:
ds
.
Url
.
Value
(),
U
RL
:
ds
.
URL
.
Value
(),
Password
:
ds
.
Password
.
Value
(),
Password
:
ds
.
Password
.
Value
(),
User
:
ds
.
User
.
Value
(),
User
:
ds
.
User
.
Value
(),
Database
:
ds
.
Database
.
Value
(),
Database
:
ds
.
Database
.
Value
(),
...
@@ -133,8 +134,8 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
...
@@ -133,8 +134,8 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
BasicAuthPassword
:
ds
.
BasicAuthPassword
.
Value
(),
BasicAuthPassword
:
ds
.
BasicAuthPassword
.
Value
(),
WithCredentials
:
ds
.
WithCredentials
.
Value
(),
WithCredentials
:
ds
.
WithCredentials
.
Value
(),
IsDefault
:
ds
.
IsDefault
.
Value
(),
IsDefault
:
ds
.
IsDefault
.
Value
(),
J
sonData
:
ds
.
Json
Data
.
Value
(),
J
SONData
:
ds
.
JSON
Data
.
Value
(),
SecureJ
sonData
:
ds
.
SecureJson
Data
.
Value
(),
SecureJ
SONData
:
ds
.
SecureJSON
Data
.
Value
(),
Editable
:
ds
.
Editable
.
Value
(),
Editable
:
ds
.
Editable
.
Value
(),
Version
:
ds
.
Version
.
Value
(),
Version
:
ds
.
Version
.
Value
(),
})
})
...
@@ -158,8 +159,8 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
...
@@ -158,8 +159,8 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
}
}
for
_
,
ds
:=
range
cfg
.
DeleteDatasources
{
for
_
,
ds
:=
range
cfg
.
DeleteDatasources
{
r
.
DeleteDatasources
=
append
(
r
.
DeleteDatasources
,
&
D
eleteDatasourceConfig
{
r
.
DeleteDatasources
=
append
(
r
.
DeleteDatasources
,
&
d
eleteDatasourceConfig
{
OrgI
d
:
ds
.
OrgId
.
Value
(),
OrgI
D
:
ds
.
OrgID
.
Value
(),
Name
:
ds
.
Name
.
Value
(),
Name
:
ds
.
Name
.
Value
(),
})
})
}
}
...
@@ -167,22 +168,22 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
...
@@ -167,22 +168,22 @@ func (cfg *DatasourcesAsConfigV1) mapToDatasourceFromConfig(apiVersion int64) *D
return
r
return
r
}
}
func
(
cfg
*
DatasourcesAsConfigV0
)
mapToDatasourceFromConfig
(
apiVersion
int64
)
*
DatasourcesAsConfig
{
func
(
cfg
*
configsV0
)
mapToDatasourceFromConfig
(
apiVersion
int64
)
*
configs
{
r
:=
&
DatasourcesAsConfig
{}
r
:=
&
configs
{}
r
.
A
pi
Version
=
apiVersion
r
.
A
PI
Version
=
apiVersion
if
cfg
==
nil
{
if
cfg
==
nil
{
return
r
return
r
}
}
for
_
,
ds
:=
range
cfg
.
Datasources
{
for
_
,
ds
:=
range
cfg
.
Datasources
{
r
.
Datasources
=
append
(
r
.
Datasources
,
&
DataSourceFromConfig
{
r
.
Datasources
=
append
(
r
.
Datasources
,
&
upsert
DataSourceFromConfig
{
OrgI
d
:
ds
.
OrgId
,
OrgI
D
:
ds
.
OrgID
,
Name
:
ds
.
Name
,
Name
:
ds
.
Name
,
Type
:
ds
.
Type
,
Type
:
ds
.
Type
,
Access
:
ds
.
Access
,
Access
:
ds
.
Access
,
U
rl
:
ds
.
Url
,
U
RL
:
ds
.
URL
,
Password
:
ds
.
Password
,
Password
:
ds
.
Password
,
User
:
ds
.
User
,
User
:
ds
.
User
,
Database
:
ds
.
Database
,
Database
:
ds
.
Database
,
...
@@ -191,16 +192,16 @@ func (cfg *DatasourcesAsConfigV0) mapToDatasourceFromConfig(apiVersion int64) *D
...
@@ -191,16 +192,16 @@ func (cfg *DatasourcesAsConfigV0) mapToDatasourceFromConfig(apiVersion int64) *D
BasicAuthPassword
:
ds
.
BasicAuthPassword
,
BasicAuthPassword
:
ds
.
BasicAuthPassword
,
WithCredentials
:
ds
.
WithCredentials
,
WithCredentials
:
ds
.
WithCredentials
,
IsDefault
:
ds
.
IsDefault
,
IsDefault
:
ds
.
IsDefault
,
J
sonData
:
ds
.
Json
Data
,
J
SONData
:
ds
.
JSON
Data
,
SecureJ
sonData
:
ds
.
SecureJson
Data
,
SecureJ
SONData
:
ds
.
SecureJSON
Data
,
Editable
:
ds
.
Editable
,
Editable
:
ds
.
Editable
,
Version
:
ds
.
Version
,
Version
:
ds
.
Version
,
})
})
}
}
for
_
,
ds
:=
range
cfg
.
DeleteDatasources
{
for
_
,
ds
:=
range
cfg
.
DeleteDatasources
{
r
.
DeleteDatasources
=
append
(
r
.
DeleteDatasources
,
&
D
eleteDatasourceConfig
{
r
.
DeleteDatasources
=
append
(
r
.
DeleteDatasources
,
&
d
eleteDatasourceConfig
{
OrgI
d
:
ds
.
OrgId
,
OrgI
D
:
ds
.
OrgID
,
Name
:
ds
.
Name
,
Name
:
ds
.
Name
,
})
})
}
}
...
@@ -208,20 +209,20 @@ func (cfg *DatasourcesAsConfigV0) mapToDatasourceFromConfig(apiVersion int64) *D
...
@@ -208,20 +209,20 @@ func (cfg *DatasourcesAsConfigV0) mapToDatasourceFromConfig(apiVersion int64) *D
return
r
return
r
}
}
func
createInsertCommand
(
ds
*
DataSourceFromConfig
)
*
models
.
AddDataSourceCommand
{
func
createInsertCommand
(
ds
*
upsert
DataSourceFromConfig
)
*
models
.
AddDataSourceCommand
{
jsonData
:=
simplejson
.
New
()
jsonData
:=
simplejson
.
New
()
if
len
(
ds
.
J
son
Data
)
>
0
{
if
len
(
ds
.
J
SON
Data
)
>
0
{
for
k
,
v
:=
range
ds
.
J
son
Data
{
for
k
,
v
:=
range
ds
.
J
SON
Data
{
jsonData
.
Set
(
k
,
v
)
jsonData
.
Set
(
k
,
v
)
}
}
}
}
return
&
models
.
AddDataSourceCommand
{
return
&
models
.
AddDataSourceCommand
{
OrgId
:
ds
.
OrgI
d
,
OrgId
:
ds
.
OrgI
D
,
Name
:
ds
.
Name
,
Name
:
ds
.
Name
,
Type
:
ds
.
Type
,
Type
:
ds
.
Type
,
Access
:
models
.
DsAccess
(
ds
.
Access
),
Access
:
models
.
DsAccess
(
ds
.
Access
),
Url
:
ds
.
U
rl
,
Url
:
ds
.
U
RL
,
Password
:
ds
.
Password
,
Password
:
ds
.
Password
,
User
:
ds
.
User
,
User
:
ds
.
User
,
Database
:
ds
.
Database
,
Database
:
ds
.
Database
,
...
@@ -231,26 +232,26 @@ func createInsertCommand(ds *DataSourceFromConfig) *models.AddDataSourceCommand
...
@@ -231,26 +232,26 @@ func createInsertCommand(ds *DataSourceFromConfig) *models.AddDataSourceCommand
WithCredentials
:
ds
.
WithCredentials
,
WithCredentials
:
ds
.
WithCredentials
,
IsDefault
:
ds
.
IsDefault
,
IsDefault
:
ds
.
IsDefault
,
JsonData
:
jsonData
,
JsonData
:
jsonData
,
SecureJsonData
:
ds
.
SecureJ
son
Data
,
SecureJsonData
:
ds
.
SecureJ
SON
Data
,
ReadOnly
:
!
ds
.
Editable
,
ReadOnly
:
!
ds
.
Editable
,
}
}
}
}
func
createUpdateCommand
(
ds
*
DataSourceFromConfig
,
id
int64
)
*
models
.
UpdateDataSourceCommand
{
func
createUpdateCommand
(
ds
*
upsert
DataSourceFromConfig
,
id
int64
)
*
models
.
UpdateDataSourceCommand
{
jsonData
:=
simplejson
.
New
()
jsonData
:=
simplejson
.
New
()
if
len
(
ds
.
J
son
Data
)
>
0
{
if
len
(
ds
.
J
SON
Data
)
>
0
{
for
k
,
v
:=
range
ds
.
J
son
Data
{
for
k
,
v
:=
range
ds
.
J
SON
Data
{
jsonData
.
Set
(
k
,
v
)
jsonData
.
Set
(
k
,
v
)
}
}
}
}
return
&
models
.
UpdateDataSourceCommand
{
return
&
models
.
UpdateDataSourceCommand
{
Id
:
id
,
Id
:
id
,
OrgId
:
ds
.
OrgI
d
,
OrgId
:
ds
.
OrgI
D
,
Name
:
ds
.
Name
,
Name
:
ds
.
Name
,
Type
:
ds
.
Type
,
Type
:
ds
.
Type
,
Access
:
models
.
DsAccess
(
ds
.
Access
),
Access
:
models
.
DsAccess
(
ds
.
Access
),
Url
:
ds
.
U
rl
,
Url
:
ds
.
U
RL
,
Password
:
ds
.
Password
,
Password
:
ds
.
Password
,
User
:
ds
.
User
,
User
:
ds
.
User
,
Database
:
ds
.
Database
,
Database
:
ds
.
Database
,
...
@@ -260,7 +261,7 @@ func createUpdateCommand(ds *DataSourceFromConfig, id int64) *models.UpdateDataS
...
@@ -260,7 +261,7 @@ func createUpdateCommand(ds *DataSourceFromConfig, id int64) *models.UpdateDataS
WithCredentials
:
ds
.
WithCredentials
,
WithCredentials
:
ds
.
WithCredentials
,
IsDefault
:
ds
.
IsDefault
,
IsDefault
:
ds
.
IsDefault
,
JsonData
:
jsonData
,
JsonData
:
jsonData
,
SecureJsonData
:
ds
.
SecureJ
son
Data
,
SecureJsonData
:
ds
.
SecureJ
SON
Data
,
ReadOnly
:
!
ds
.
Editable
,
ReadOnly
:
!
ds
.
Editable
,
}
}
}
}
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