aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/xdsconfig')
-rw-r--r--lib/xdsconfig/config.go29
-rw-r--r--lib/xdsconfig/fileconfig.go13
2 files changed, 26 insertions, 16 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")
+}
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 86f39b5..b786a24 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -28,9 +28,6 @@ import (
common "gerrit.automotivelinux.org/gerrit/src/xds/xds-common.git/golib"
)
-// ConfigDir Directory in user HOME directory where xds config will be saved
-var ConfigDir = path.Join(".xds", "server")
-
const (
// GlobalConfigFilename Global config filename
GlobalConfigFilename = "server-config.json"
@@ -74,8 +71,8 @@ func readGlobalConfig(c *Config, confFile string) error {
if confFile != "" {
searchIn = append(searchIn, confFile)
}
- if usr, err := user.Current(); err == nil {
- searchIn = append(searchIn, path.Join(usr.HomeDir, ConfigDir, GlobalConfigFilename))
+ if _, err := user.Current(); err == nil {
+ searchIn = append(searchIn, path.Join(ConfigRootDir(), GlobalConfigFilename))
}
searchIn = append(searchIn, "/etc/xds/server/server-config.json")
@@ -172,11 +169,7 @@ func readGlobalConfig(c *Config, confFile string) error {
}
func configFilenameGet(cfgFile string) (string, error) {
- usr, err := user.Current()
- if err != nil {
- return "", err
- }
- return path.Join(usr.HomeDir, ConfigDir, cfgFile), nil
+ return path.Join(ConfigRootDir(), cfgFile), nil
}
// FoldersConfigFilenameGet Return the FoldersConfig filename