provisioning: escape literal '$' with '$$' to avoid interpolation (#18045)

fixes #17986
This commit is contained in:
Kyle Brandt
2019-07-11 07:32:07 -04:00
committed by GitHub
parent 7ec87ee76b
commit 76d08989f0
3 changed files with 33 additions and 3 deletions
+8 -1
View File
@@ -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 {