Skip to content

Commit

Permalink
use screaming snake case for env placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
aliariff committed Aug 29, 2019
1 parent 5dcd05f commit bf7e987
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/gosimple/slug v1.7.0
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslC
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365 h1:ECW73yc9MY7935nNYXUkK7Dz17YuSUI9yqRqYS8aBww=
github.com/iancoleman/strcase v0.0.0-20190422225806-e506e3ef7365/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
Expand Down
4 changes: 2 additions & 2 deletions pkg/grafana/rest-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
"net/http"
"net/url"
"path"
"strings"

"github.com/gosimple/slug"
"github.com/iancoleman/strcase"
)

type RestClient struct {
Expand Down Expand Up @@ -87,7 +87,7 @@ func (r *RestClient) GetAllDatasources() ([]*DataSource, error) {
for key, value := range ds.SecureJsonFields {
if value {
sanitized := slug.Make(fmt.Sprintf("%s_%s", ds.Name, key))
placeholder := strings.ToUpper("$" + sanitized)
placeholder := strcase.ToScreamingSnake("$" + sanitized)
if existedEnv[placeholder] {
// duplicated env existed
return nil, fmt.Errorf("Duplicated ENV variable: `%s`. Rename `%s` datasource", placeholder, ds.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/grafana/rest-client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestGetAllDatasources(t *testing.T) {
assert.Equal(1, len(datasources))
actualDatasource := datasources[0]
assert.Equal(1, len(actualDatasource.SecureJsonData))
assert.Equal("$GDEV-INFLUXDB-TELEGRAF_PASSWORD", actualDatasource.SecureJsonData["password"])
assert.Equal("$GDEV_INFLUXDB_TELEGRAF_PASSWORD", actualDatasource.SecureJsonData["password"])
}

func TestIncompleteHost(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/grafana/testdata/datasources-1.golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"jsonData": {
"timeInterval": "10s"
},
"name": "gdev-influxdb-telegraf",
"name": "gdev-influxdb-telegraf😀",
"orgId": 1,
"password": "",
"readOnly": true,
Expand Down

0 comments on commit bf7e987

Please sign in to comment.