summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/xdsconfig/config.go2
-rw-r--r--lib/xdsconfig/fileconfig.go4
-rw-r--r--lib/xdsserver/sdk.go20
-rw-r--r--lib/xdsserver/sdks.go9
4 files changed, 33 insertions, 2 deletions
diff --git a/lib/xdsconfig/config.go b/lib/xdsconfig/config.go
index 11960c9..335c116 100644
--- a/lib/xdsconfig/config.go
+++ b/lib/xdsconfig/config.go
@@ -56,6 +56,7 @@ const (
DefaultShareDir = "${HOME}/.xds/server/projects"
DefaultSTHomeDir = "${HOME}/.xds/server/syncthing-config"
DefaultSdkScriptsDir = "${EXEPATH}/sdks"
+ DefaultSdkDbUpdate = "startup"
)
// Init loads the configuration on start-up
@@ -98,6 +99,7 @@ func Init(cliCtx *cli.Context, log *logrus.Logger) (*Config, error) {
WebAppDir: "webapp/dist",
ShareRootDir: dfltShareDir,
SdkScriptsDir: DefaultSdkScriptsDir,
+ SdkDbUpdate: DefaultSdkDbUpdate,
HTTPPort: DefaultPort,
SThgConf: &SyncThingConf{Home: dfltSTHomeDir},
LogsDir: "",
diff --git a/lib/xdsconfig/fileconfig.go b/lib/xdsconfig/fileconfig.go
index 69467b4..ef207ec 100644
--- a/lib/xdsconfig/fileconfig.go
+++ b/lib/xdsconfig/fileconfig.go
@@ -54,6 +54,7 @@ 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"`
@@ -139,6 +140,9 @@ func readGlobalConfig(c *Config, confFile string) error {
if fCfg.SdkScriptsDir == "" {
fCfg.SdkScriptsDir = c.FileConf.SdkScriptsDir
}
+ if fCfg.SdkDbUpdate == "" {
+ fCfg.SdkDbUpdate = c.FileConf.SdkDbUpdate
+ }
if fCfg.HTTPPort == "" {
fCfg.HTTPPort = c.FileConf.HTTPPort
}
diff --git a/lib/xdsserver/sdk.go b/lib/xdsserver/sdk.go
index 2736246..374fb12 100644
--- a/lib/xdsserver/sdk.go
+++ b/lib/xdsserver/sdk.go
@@ -64,9 +64,18 @@ type CrossSDK struct {
}
// ListCrossSDK List all available and installed SDK (call "db-dump" script)
-func ListCrossSDK(scriptDir string, log *logrus.Logger) ([]xsapiv1.SDK, error) {
+func ListCrossSDK(scriptDir string, update bool, log *logrus.Logger) ([]xsapiv1.SDK, error) {
sdksList := []xsapiv1.SDK{}
+ // First update sdk DB when requested
+ if update {
+ out, err := UpdateSDKDb(scriptDir, log)
+ if err != nil {
+ log.Errorf("SDK DB update failure (%v): %v", err, out)
+ return sdksList, fmt.Errorf("Error while updating SDK DB (%v)", err)
+ }
+ }
+
// Retrieve SDKs list and info
cmd := exec.Command(path.Join(scriptDir, scriptDbDump))
stdout, err := cmd.CombinedOutput()
@@ -111,6 +120,15 @@ func GetSDKInfo(scriptDir, url, filename, md5sum string, log *logrus.Logger) (xs
return sdk, nil
}
+// UpdateSDKDb Used db-update script to update SDK database
+func UpdateSDKDb(scriptDir string, log *logrus.Logger) (string, error) {
+ args := []string{}
+ cmd := exec.Command(path.Join(scriptDir, scriptDbUpdate), args...)
+ stdout, err := cmd.CombinedOutput()
+
+ return string(stdout), err
+}
+
// NewCrossSDK creates a new instance of CrossSDK
func NewCrossSDK(ctx *Context, sdk xsapiv1.SDK, scriptDir string) (*CrossSDK, error) {
s := CrossSDK{
diff --git a/lib/xdsserver/sdks.go b/lib/xdsserver/sdks.go
index c006861..6094045 100644
--- a/lib/xdsserver/sdks.go
+++ b/lib/xdsserver/sdks.go
@@ -63,6 +63,12 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
return &s, err
}
+ // Update SDK DB on startup by default (can be disable using config file)
+ update := true
+ if s.Config.FileConf.SdkDbUpdate != "startup" {
+ update = false
+ }
+
s.mutex.Lock()
defer s.mutex.Unlock()
@@ -73,10 +79,11 @@ func NewSDKs(ctx *Context) (*SDKs, error) {
continue
}
- sdksList, err := ListCrossSDK(d, s.Log)
+ sdksList, err := ListCrossSDK(d, update, s.Log)
if err != nil {
// allow to use XDS even if error on list
s.Log.Errorf("Cannot retrieve SDK list: %v", err)
+ sdksList, _ = ListCrossSDK(d, false, s.Log)
}
s.LogSillyf("'%s' SDKs list: %v", d, sdksList)