summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/config.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-07-18 15:41:51 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-07-18 17:52:00 +0200
commitb4ea2f3048518455b80262c16ebaa80d3cc7bba6 (patch)
tree73e014baac6a337610559ac5424181907128d3c6 /lib/xdsconfig/config.go
parentf63e5ae6aae50f62c82b3e8132659cb0c627c639 (diff)
Add XDS_SERVER_ROOT_CFG_DIR env var support
By default xds-server uses $HOME/.xds/server directory to save all config. This changes allows user to change this root directory by defining XDS_SERVER_ROOT_CFG_DIR environment variable. Change-Id: Iebde8dcf2d27b77671c7332bac04295d31659e24 Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsconfig/config.go')
-rw-r--r--lib/xdsconfig/config.go29
1 files changed, 23 insertions, 6 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go
index ee20bd2..ca5b5cb 100644
--- a/lib/xdsconfig/config.go
+++ b/lib/xdsconfig/config.go
@@ -21,6 +21,8 @@ import (
"fmt"
"io"
"os"
+ "os/user"
+ "path"
"path/filepath"
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
@@ -53,8 +55,8 @@ type Options struct {
const (
DefaultAPIVersion = "1"
DefaultPort = "8000"
- DefaultShareDir = "${HOME}/.xds/server/projects"
- DefaultSTHomeDir = "${HOME}/.xds/server/syncthing-config"
+ DefaultShareDir = "projects"
+ DefaultSTHomeDir = "syncthing-config"
DefaultSdkScriptsDir = "${EXEPATH}/sdks"
DefaultSdkDbUpdate = "startup"
)
@@ -63,12 +65,12 @@ const (
func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
var err error
- dfltShareDir := DefaultShareDir
- dfltSTHomeDir := DefaultSTHomeDir
- if resDir, err := common.ResolveEnvVar(DefaultShareDir); err == nil {
+ dfltShareDir := path.Join(ConfigRootDir(), DefaultShareDir)
+ dfltSTHomeDir := path.Join(ConfigRootDir(), DefaultSTHomeDir)
+ if resDir, err := common.ResolveEnvVar(dfltShareDir); err == nil {
dfltShareDir = resDir
}
- if resDir, err := common.ResolveEnvVar(DefaultSTHomeDir); err == nil {
+ if resDir, err := common.ResolveEnvVar(dfltSTHomeDir); err == nil {
dfltSTHomeDir = resDir
}
@@ -157,3 +159,18 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
return &c, nil
}
+
+// ConfigRootDir return the root directory where xds server save all config files
+func ConfigRootDir() string {
+ root := "$HOME"
+ if usr, err := user.Current(); err == nil {
+ root = usr.HomeDir
+ }
+
+ // Default $HOME/.xds/server but may be changed by an env variable
+ if envVar, envDef := os.LookupEnv("XDS_SERVER_ROOT_CFG_DIR"); envDef {
+ root = envVar
+ }
+
+ return path.Join(root, "/.xds/server")
+}