update xds-server package in docker
[src/xds/xds-server.git] / lib / xdsconfig / fileconfig.go
index ef207ec..0b248cd 100644 (file)
@@ -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"
@@ -38,6 +35,8 @@ const (
        ServerDataFilename = "server-data.xml"
        // FoldersConfigFilename Folders config filename
        FoldersConfigFilename = "server-config_folders.xml"
+       // TargetsConfigFilename Targets config filename
+       TargetsConfigFilename = "server-config_targets.xml"
 )
 
 // SyncThingConf definition
@@ -51,13 +50,15 @@ type SyncThingConf struct {
 
 // FileConfig is the JSON structure of xds-server config file (server-config.json)
 type FileConfig struct {
-       WebAppDir     string         `json:"webAppDir"`
-       ShareRootDir  string         `json:"shareRootDir"`
-       SdkScriptsDir string         `json:"sdkScriptsDir"`
-       SdkDbUpdate   string         `json:"sdkDbUpdate"`
-       HTTPPort      string         `json:"httpPort"`
-       SThgConf      *SyncThingConf `json:"syncthing"`
-       LogsDir       string         `json:"logsDir"`
+       WebAppDir              string         `json:"webAppDir"`
+       ShareRootDir           string         `json:"shareRootDir"`
+       SdkScriptsDir          string         `json:"sdkScriptsDir"`
+       XdsSrvUpdateScriptsDir string         `json:"xdsSrvUpdateScriptsDir"`
+       SdkDbUpdate            string         `json:"sdkDbUpdate"`
+       HTTPPort               string         `json:"httpPort"`
+       SThgConf               *SyncThingConf `json:"syncthing"`
+       LogsDir                string         `json:"logsDir"`
+       XdsSrvUpdateTime       string         `json:"xdsSrvUpdateTime"`
 }
 
 // readGlobalConfig reads configuration from a config file.
@@ -72,8 +73,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")
@@ -119,7 +120,9 @@ func readGlobalConfig(c *Config, confFile string) error {
                &fCfg.WebAppDir,
                &fCfg.ShareRootDir,
                &fCfg.SdkScriptsDir,
-               &fCfg.LogsDir}
+               &fCfg.XdsSrvUpdateScriptsDir,
+               &fCfg.LogsDir,
+               &fCfg.XdsSrvUpdateTime}
        if fCfg.SThgConf != nil {
                vars = append(vars, &fCfg.SThgConf.Home, &fCfg.SThgConf.BinDir)
        }
@@ -140,6 +143,9 @@ func readGlobalConfig(c *Config, confFile string) error {
        if fCfg.SdkScriptsDir == "" {
                fCfg.SdkScriptsDir = c.FileConf.SdkScriptsDir
        }
+       if fCfg.XdsSrvUpdateScriptsDir == "" {
+               fCfg.XdsSrvUpdateScriptsDir = c.FileConf.XdsSrvUpdateScriptsDir
+       }
        if fCfg.SdkDbUpdate == "" {
                fCfg.SdkDbUpdate = c.FileConf.SdkDbUpdate
        }
@@ -149,6 +155,9 @@ func readGlobalConfig(c *Config, confFile string) error {
        if fCfg.LogsDir == "" {
                fCfg.LogsDir = c.FileConf.LogsDir
        }
+       if fCfg.XdsSrvUpdateTime == "" {
+               fCfg.XdsSrvUpdateTime = c.FileConf.XdsSrvUpdateTime
+       }
 
        // Resolve webapp dir (support relative or full path)
        fCfg.WebAppDir = strings.Trim(fCfg.WebAppDir, " ")
@@ -170,11 +179,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
@@ -182,6 +187,11 @@ func FoldersConfigFilenameGet() (string, error) {
        return configFilenameGet(FoldersConfigFilename)
 }
 
+// TargetsConfigFilenameGet Return the TargetsConfig filename
+func TargetsConfigFilenameGet() (string, error) {
+       return configFilenameGet(TargetsConfigFilename)
+}
+
 // ServerDataFilenameGet Return the ServerData filename
 func ServerDataFilenameGet() (string, error) {
        return configFilenameGet(ServerDataFilename)