summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/fileconfig.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-18 10:55:19 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-05-18 10:55:19 +0200
commit319c10853c1961621a0c1ae05ac95b20a0ce277e (patch)
treebae57c21562b91c0802e46537100c388fa3cba15 /lib/xdsconfig/fileconfig.go
parenta50baa7c309f7eb55fe87c71f4c688ace325b6ac (diff)
Fix ResolveEnvVar function and add support of tilde (~/...)
Diffstat (limited to 'lib/xdsconfig/fileconfig.go')
-rw-r--r--lib/xdsconfig/fileconfig.go26
1 files changed, 4 insertions, 22 deletions
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 5cf8db2..535ee59 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -2,12 +2,12 @@ package xdsconfig
import (
"encoding/json"
- "fmt"
"os"
"os/user"
"path"
"path/filepath"
- "regexp"
+
+ "github.com/iotbzh/xds-agent/lib/common"
)
type SyncThingConf struct {
@@ -79,11 +79,11 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) {
&fCfg.SThgConf.Home,
&fCfg.SThgConf.BinDir} {
- rep, err := resolveEnvVar(*field)
+ var err error
+ *field, err = common.ResolveEnvVar(*field)
if err != nil {
return nil, err
}
- *field = path.Clean(rep)
}
// Config file settings overwrite default config
@@ -93,21 +93,3 @@ func updateConfigFromFile(c *Config, confFile string) (*FileConfig, error) {
return &fCfg, nil
}
-
-// resolveEnvVar Resolved environment variable regarding the syntax ${MYVAR}
-func resolveEnvVar(s string) (string, error) {
- re := regexp.MustCompile("\\${(.*)}")
- vars := re.FindAllStringSubmatch(s, -1)
- res := s
- for _, v := range vars {
- val := os.Getenv(v[1])
- if val == "" {
- return res, fmt.Errorf("ERROR: %s env variable not defined", v[1])
- }
-
- rer := regexp.MustCompile("\\${" + v[1] + "}")
- res = rer.ReplaceAllString(res, val)
- }
-
- return res, nil
-}