aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-17 22:07:59 +0200
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-10-17 22:13:09 +0200
commitaf37768226c17b39b16c4b29f7262e9a86526246 (patch)
treeedd219b48f7eca217c39f53525d4454d44f1530c /lib
parent4feb29ac401c7f8416e55ae51ba16cc6819f6a2c (diff)
Create xds-project.conf file on folder creation.
Diffstat (limited to 'lib')
-rw-r--r--lib/apiv1/folders.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/apiv1/folders.go b/lib/apiv1/folders.go
index cf56c3f..a231b86 100644
--- a/lib/apiv1/folders.go
+++ b/lib/apiv1/folders.go
@@ -2,6 +2,7 @@ package apiv1
import (
"net/http"
+ "os"
"github.com/gin-gonic/gin"
common "github.com/iotbzh/xds-common/golib"
@@ -40,6 +41,27 @@ func (s *APIService) addFolder(c *gin.Context) {
return
}
+ // Create xds-project.conf file
+ // FIXME: move to folders.createUpdate func (but gin context needed)
+ fld := s.mfolders.Get(newFld.ID)
+ prjConfFile := (*fld).GetFullPath("xds-project.conf")
+ if !common.Exists(prjConfFile) {
+ fd, err := os.OpenFile(prjConfFile, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, 0666)
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
+ fd.WriteString("# XDS project settings\n")
+ fd.WriteString("export XDS_SERVER_URL=" + c.Request.Host + "\n")
+ fd.WriteString("export XDS_PROJECT_ID=" + newFld.ID + "\n")
+ if newFld.DefaultSdk == "" {
+ sdks := s.sdks.GetAll()
+ newFld.DefaultSdk = sdks[0].ID
+ }
+ fd.WriteString("export XDS_SDK_ID=" + newFld.DefaultSdk + "\n")
+ fd.Close()
+ }
+
c.JSON(http.StatusOK, newFld)
}