aboutsummaryrefslogtreecommitdiffstats
path: root/lib/xdsserver/sdk.go
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-02-06 17:07:30 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-02-06 17:11:30 +0100
commit0a53346ecd92e1281587c724631fdf76dc756fc7 (patch)
treedd9996613a7f4237fd996be9a54949369cd064f4 /lib/xdsserver/sdk.go
parent60a59bcfdb3c2404a468cc314b7afde85ee35e1b (diff)
Auto update SDK DB on startup.
Auto update db is enable by default (setting sdkDbUpdate = "startup") but it can be disable by setting sdkDbUpdate to "disable" in server config file. Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
Diffstat (limited to 'lib/xdsserver/sdk.go')
-rw-r--r--lib/xdsserver/sdk.go20
1 files changed, 19 insertions, 1 deletions
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{