summaryrefslogtreecommitdiffstats
path: root/lib/xdsconfig/config.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-09-25 14:15:16 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-06 18:25:04 +0200
commit97ca1f277dc8b6973d6fa67add5593a9c395ce60 (patch)
tree761649d7771e8699a67567476c17fb2fa0e28e57 /lib/xdsconfig/config.go
parent12a20d0905b0d3e7e0f4c9ec8ee619f683256d71 (diff)
Added webapp Dashboard + logic to interact with server.
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsconfig/config.go')
-rw-r--r--lib/xdsconfig/config.go78
1 files changed, 61 insertions, 17 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go
index 854d383..9cff862 100644
--- a/lib/xdsconfig/config.go
+++ b/lib/xdsconfig/config.go
@@ -2,6 +2,8 @@ package xdsconfig
import (
"fmt"
+ "io"
+ "path/filepath"
"os"
@@ -12,14 +14,20 @@ import (
// Config parameters (json format) of /config command
type Config struct {
- Version string `json:"version"`
- APIVersion string `json:"apiVersion"`
- VersionGitTag string `json:"gitTag"`
+ Version string
+ APIVersion string
+ VersionGitTag string
+ Options Options
+ FileConf FileConfig
+ Log *logrus.Logger
+ LogVerboseOut io.Writer
+}
- // Private / un-exported fields
- HTTPPort string `json:"-"`
- FileConf *FileConfig `json:"-"`
- Log *logrus.Logger `json:"-"`
+// Options set at the command line
+type Options struct {
+ ConfigFile string
+ LogLevel string
+ LogFile string
}
// Config default values
@@ -32,39 +40,75 @@ const (
func Init(ctx *cli.Context, log *logrus.Logger) (*Config, error) {
var err error
+ defaultWebAppDir := "${EXEPATH}/www"
+ defaultSTHomeDir := "${HOME}/.xds/agent/syncthing-config"
+
// Define default configuration
c := Config{
Version: ctx.App.Metadata["version"].(string),
APIVersion: DefaultAPIVersion,
VersionGitTag: ctx.App.Metadata["git-tag"].(string),
- HTTPPort: "8010",
- FileConf: &FileConfig{
- LogsDir: "/tmp/logs",
+ Options: Options{
+ ConfigFile: ctx.GlobalString("config"),
+ LogLevel: ctx.GlobalString("log"),
+ LogFile: ctx.GlobalString("logfile"),
+ },
+
+ FileConf: FileConfig{
+ HTTPPort: "8800",
+ WebAppDir: defaultWebAppDir,
+ LogsDir: "/tmp/logs",
+ // SEB XDSAPIKey: "1234abcezam",
+ ServersConf: []XDSServerConf{
+ XDSServerConf{
+ URL: "http://localhost:8000",
+ ConnRetry: 10,
+ },
+ },
SThgConf: &SyncThingConf{
- Home: "${HOME}/.xds/agent/syncthing-config",
+ Home: defaultSTHomeDir,
},
},
Log: log,
}
// config file settings overwrite default config
- c.FileConf, err = updateConfigFromFile(&c, ctx.GlobalString("config"))
+ err = readGlobalConfig(&c, c.Options.ConfigFile)
if err != nil {
return nil, err
}
+ // Handle where Logs are redirected:
+ // default 'stdout' (logfile option default value)
+ // else use file (or filepath) set by --logfile option
+ // that may be overwritten by LogsDir field of config file
+ logF := c.Options.LogFile
+ logD := c.FileConf.LogsDir
+ if logF != "stdout" {
+ if logD != "" {
+ lf := filepath.Base(logF)
+ if lf == "" || lf == "." {
+ lf = "xds-agent.log"
+ }
+ logF = filepath.Join(logD, lf)
+ } else {
+ logD = filepath.Dir(logF)
+ }
+ }
+ if logD == "" || logD == "." {
+ logD = "/tmp/xds/logs"
+ }
+ c.Options.LogFile = logF
+ c.FileConf.LogsDir = logD
+
if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
return nil, fmt.Errorf("Cannot create logs dir: %v", err)
}
}
+ c.Log.Infoln("Logs file: ", c.Options.LogFile)
c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)
return &c, nil
}
-
-// UpdateAll Update the current configuration
-func (c *Config) UpdateAll(newCfg Config) error {
- return fmt.Errorf("Not Supported")
-}