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
76d08989
Unverified
Commit
76d08989
authored
Jul 11, 2019
by
Kyle Brandt
Committed by
GitHub
Jul 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
provisioning: escape literal '$' with '$$' to avoid interpolation (#18045)
fixes #17986
parent
7ec87ee7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
docs/sources/administration/provisioning.md
+2
-0
pkg/services/provisioning/values/values.go
+8
-1
pkg/services/provisioning/values/values_test.go
+23
-2
No files found.
docs/sources/administration/provisioning.md
View file @
76d08989
...
...
@@ -45,6 +45,8 @@ datasources:
password
:
$PASSWORD
```
If you have a literal
`$`
in your value and want to avoid interpolation,
`$$`
can be used.
<hr
/>
## Configuration Management Tools
...
...
pkg/services/provisioning/values/values.go
View file @
76d08989
...
...
@@ -14,6 +14,7 @@ import (
"os"
"reflect"
"strconv"
"strings"
"github.com/grafana/grafana/pkg/util/errutil"
)
...
...
@@ -185,8 +186,14 @@ func transformMap(i map[interface{}]interface{}) interface{} {
// interpolateValue returns final value after interpolation. At the moment only env var interpolation is done
// here but in the future something like interpolation from file could be also done here.
// For a literal '$', '$$' can be used to avoid interpolation.
func
interpolateValue
(
val
string
)
string
{
return
os
.
ExpandEnv
(
val
)
parts
:=
strings
.
Split
(
val
,
"$$"
)
interpolated
:=
make
([]
string
,
len
(
parts
))
for
i
,
v
:=
range
parts
{
interpolated
[
i
]
=
os
.
ExpandEnv
(
v
)
}
return
strings
.
Join
(
interpolated
,
"$"
)
}
type
interpolated
struct
{
...
...
pkg/services/provisioning/values/values_test.go
View file @
76d08989
package
values
import
(
.
"github.com/smartystreets/goconvey/convey"
"gopkg.in/yaml.v2"
"os"
"testing"
.
"github.com/smartystreets/goconvey/convey"
"gopkg.in/yaml.v2"
)
func
TestValues
(
t
*
testing
.
T
)
{
Convey
(
"Values"
,
t
,
func
()
{
os
.
Setenv
(
"INT"
,
"1"
)
os
.
Setenv
(
"STRING"
,
"test"
)
os
.
Setenv
(
"EMPTYSTRING"
,
""
)
os
.
Setenv
(
"BOOL"
,
"true"
)
Convey
(
"IntValue"
,
func
()
{
...
...
@@ -61,6 +63,24 @@ func TestValues(t *testing.T) {
So
(
d
.
Val
.
Value
(),
ShouldEqual
,
""
)
So
(
d
.
Val
.
Raw
,
ShouldEqual
,
""
)
})
Convey
(
"empty var should have empty value"
,
func
()
{
unmarshalingTest
(
`val: $EMPTYSTRING`
,
d
)
So
(
d
.
Val
.
Value
(),
ShouldEqual
,
""
)
So
(
d
.
Val
.
Raw
,
ShouldEqual
,
"$EMPTYSTRING"
)
})
Convey
(
"$$ should be a literal $"
,
func
()
{
unmarshalingTest
(
`val: $$`
,
d
)
So
(
d
.
Val
.
Value
(),
ShouldEqual
,
"$"
)
So
(
d
.
Val
.
Raw
,
ShouldEqual
,
"$$"
)
})
Convey
(
"$$ should be a literal $ and not expanded within a string"
,
func
()
{
unmarshalingTest
(
`val: mY,Passwo$$rd`
,
d
)
So
(
d
.
Val
.
Value
(),
ShouldEqual
,
"mY,Passwo$rd"
)
So
(
d
.
Val
.
Raw
,
ShouldEqual
,
"mY,Passwo$$rd"
)
})
})
Convey
(
"BoolValue"
,
func
()
{
...
...
@@ -199,6 +219,7 @@ func TestValues(t *testing.T) {
Reset
(
func
()
{
os
.
Unsetenv
(
"INT"
)
os
.
Unsetenv
(
"STRING"
)
os
.
Unsetenv
(
"EMPTYSTRING"
)
os
.
Unsetenv
(
"BOOL"
)
})
})
...
...
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