8 "github.com/Sirupsen/logrus"
9 "github.com/codegangsta/cli"
10 common "github.com/iotbzh/xds-common/golib"
13 // Config parameters (json format) of /config command
15 Version string `json:"version"`
16 APIVersion string `json:"apiVersion"`
17 VersionGitTag string `json:"gitTag"`
18 Builder BuilderConfig `json:"builder"`
20 // Private (un-exported fields in REST GET /config route)
21 Options Options `json:"-"`
22 FileConf FileConfig `json:"-"`
23 Log *logrus.Logger `json:"-"`
24 LogVerboseOut io.Writer `json:"-"`
27 // Options set at the command line
35 // Config default values
37 DefaultAPIVersion = "1"
39 DefaultShareDir = "/mnt/share"
40 DefaultSdkRootDir = "/xdt/sdk"
43 // Init loads the configuration on start-up
44 func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
47 // Define default configuration
49 Version: cliCtx.App.Metadata["version"].(string),
50 APIVersion: DefaultAPIVersion,
51 VersionGitTag: cliCtx.App.Metadata["git-tag"].(string),
52 Builder: BuilderConfig{},
55 ConfigFile: cliCtx.GlobalString("config"),
56 LogLevel: cliCtx.GlobalString("log"),
57 LogFile: cliCtx.GlobalString("logfile"),
58 NoFolderConfig: cliCtx.GlobalBool("no-folderconfig"),
61 WebAppDir: "webapp/dist",
62 ShareRootDir: DefaultShareDir,
63 SdkRootDir: DefaultSdkRootDir,
64 HTTPPort: DefaultPort,
69 // config file settings overwrite default config
70 err = readGlobalConfig(&c, c.Options.ConfigFile)
75 // Update location of shared dir if needed
76 if !common.Exists(c.FileConf.ShareRootDir) {
77 if err := os.MkdirAll(c.FileConf.ShareRootDir, 0770); err != nil {
78 return nil, fmt.Errorf("No valid shared directory found: %v", err)
81 c.Log.Infoln("Share root directory: ", c.FileConf.ShareRootDir)
83 if c.FileConf.LogsDir != "" && !common.Exists(c.FileConf.LogsDir) {
84 if err := os.MkdirAll(c.FileConf.LogsDir, 0770); err != nil {
85 return nil, fmt.Errorf("Cannot create logs dir: %v", err)
88 c.Log.Infoln("Logs directory: ", c.FileConf.LogsDir)