summaryrefslogtreecommitdiffstats
path: root/lib/apiv1
diff options
context:
space:
mode:
Diffstat (limited to 'lib/apiv1')
-rw-r--r--lib/apiv1/agent.go70
-rw-r--r--lib/apiv1/apiv1.go11
-rw-r--r--lib/apiv1/events.go9
-rw-r--r--lib/apiv1/exec.go25
-rw-r--r--lib/apiv1/folders.go22
-rw-r--r--lib/apiv1/make.go30
-rw-r--r--lib/apiv1/sdks.go6
-rw-r--r--lib/apiv1/version.go2
8 files changed, 69 insertions, 106 deletions
diff --git a/lib/apiv1/agent.go b/lib/apiv1/agent.go
deleted file mode 100644
index 925f12b..0000000
--- a/lib/apiv1/agent.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package apiv1
-
-import (
- "net/http"
- "path"
- "strings"
-
- "path/filepath"
-
- "github.com/gin-gonic/gin"
- common "github.com/iotbzh/xds-common/golib"
-)
-
-// XDSAgentTarball .
-type XDSAgentTarball struct {
- OS string `json:"os"`
- Arch string `json:"arch"`
- Version string `json:"version"`
- RawVersion string `json:"raw-version"`
- FileURL string `json:"fileUrl"`
-}
-
-// XDSAgentInfo .
-type XDSAgentInfo struct {
- Tarballs []XDSAgentTarball `json:"tarballs"`
-}
-
-// getXdsAgentInfo : return various information about Xds Agent
-func (s *APIService) getXdsAgentInfo(c *gin.Context) {
-
- res := XDSAgentInfo{}
- tarballURL := "assets/xds-agent-tarballs"
- tarballDir := filepath.Join(s.cfg.FileConf.WebAppDir, "assets", "xds-agent-tarballs")
- if common.Exists(tarballDir) {
- files, err := filepath.Glob(path.Join(tarballDir, "xds-agent_*.zip"))
- if err != nil {
- s.log.Debugf("Error while retrieving xds-agent tarballs: dir=%s, error=%v", tarballDir, err)
- }
- for _, ff := range files {
- file := filepath.Base(ff)
- // Assume that tarball name format is: xds-agent_OS-ARCH-RAWVERSION.zip
- fs := strings.TrimSuffix(strings.TrimPrefix(file, "xds-agent_"), ".zip")
- f := strings.Split(fs, "-")
-
- if len(f) >= 3 {
- vers := strings.Split(f[2], "_")
- ver := f[2]
- if len(vers) > 1 {
- ver = vers[0]
- }
-
- newT := XDSAgentTarball{
- OS: f[0],
- Arch: f[1],
- Version: ver,
- RawVersion: f[2],
- FileURL: filepath.Join(tarballURL, file),
- }
-
- s.log.Infof("Added XDS-Agent tarball: %s", file)
- res.Tarballs = append(res.Tarballs, newT)
-
- } else {
- s.log.Debugf("Error while retrieving xds-agent, decoding failure: file:%v", ff)
- }
- }
- }
-
- c.JSON(http.StatusOK, res)
-}
diff --git a/lib/apiv1/apiv1.go b/lib/apiv1/apiv1.go
index 262f513..d10a08e 100644
--- a/lib/apiv1/apiv1.go
+++ b/lib/apiv1/apiv1.go
@@ -34,19 +34,18 @@ func New(r *gin.Engine, sess *session.Sessions, cfg *xdsconfig.Config, mfolders
}
s.apiRouter.GET("/version", s.getVersion)
- s.apiRouter.GET("/xdsagent/info", s.getXdsAgentInfo)
s.apiRouter.GET("/config", s.getConfig)
s.apiRouter.POST("/config", s.setConfig)
s.apiRouter.GET("/folders", s.getFolders)
- s.apiRouter.GET("/folder/:id", s.getFolder)
- s.apiRouter.POST("/folder", s.addFolder)
- s.apiRouter.POST("/folder/sync/:id", s.syncFolder)
- s.apiRouter.DELETE("/folder/:id", s.delFolder)
+ s.apiRouter.GET("/folders/:id", s.getFolder)
+ s.apiRouter.POST("/folders", s.addFolder)
+ s.apiRouter.POST("/folders/sync/:id", s.syncFolder)
+ s.apiRouter.DELETE("/folders/:id", s.delFolder)
s.apiRouter.GET("/sdks", s.getSdks)
- s.apiRouter.GET("/sdk/:id", s.getSdk)
+ s.apiRouter.GET("/sdks/:id", s.getSdk)
s.apiRouter.POST("/make", s.buildMake)
s.apiRouter.POST("/make/:id", s.buildMake)
diff --git a/lib/apiv1/events.go b/lib/apiv1/events.go
index da8298c..9444262 100644
--- a/lib/apiv1/events.go
+++ b/lib/apiv1/events.go
@@ -112,6 +112,9 @@ func (s *APIService) eventsRegister(c *gin.Context) {
Folder: *cfg,
}
+ s.log.Debugf("WS Emit %s - Status=%10s, IsInSync=%6v, ID=%s",
+ EventEventType+evType, cfg.Status, cfg.IsInSync, cfg.ID)
+
if err := (*so).Emit(EventEventType+evType, msg); err != nil {
s.log.Errorf("WS Emit Folder StateChanged event : %v", err)
}
@@ -119,11 +122,15 @@ func (s *APIService) eventsRegister(c *gin.Context) {
data := make(folder.EventCBData)
data["sid"] = sess.ID
- err := s.mfolders.RegisterEventChange(args.ProjectID, &cbFunc, &data)
+ prjID, err := s.mfolders.ResolveID(args.ProjectID)
if err != nil {
common.APIError(c, err.Error())
return
}
+ if err = s.mfolders.RegisterEventChange(prjID, &cbFunc, &data); err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
c.JSON(http.StatusOK, gin.H{"status": "OK"})
}
diff --git a/lib/apiv1/exec.go b/lib/apiv1/exec.go
index de40c70..30444c1 100644
--- a/lib/apiv1/exec.go
+++ b/lib/apiv1/exec.go
@@ -19,7 +19,8 @@ type (
// ExecArgs JSON parameters of /exec command
ExecArgs struct {
ID string `json:"id" binding:"required"`
- SdkID string `json:"sdkid"` // sdk ID to use for setting env
+ SdkID string `json:"sdkID"` // sdk ID to use for setting env
+ CmdID string `json:"cmdID"` // command unique ID
Cmd string `json:"cmd" binding:"required"`
Args []string `json:"args"`
Env []string `json:"env"`
@@ -104,15 +105,19 @@ func (s *APIService) execCmd(c *gin.Context) {
}
// Allow to pass id in url (/exec/:id) or as JSON argument
- id := c.Param("id")
- if id == "" {
- id = args.ID
+ idArg := c.Param("id")
+ if idArg == "" {
+ idArg = args.ID
}
- if id == "" {
+ if idArg == "" {
common.APIError(c, "Invalid id")
return
}
-
+ id, err := s.mfolders.ResolveID(idArg)
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
f := s.mfolders.Get(id)
if f == nil {
common.APIError(c, "Unknown id")
@@ -168,11 +173,13 @@ func (s *APIService) execCmd(c *gin.Context) {
}
// Unique ID for each commands
- cmdID := strconv.Itoa(execCommandID)
- execCommandID++
+ if args.CmdID == "" {
+ args.CmdID = s.cfg.ServerUID[:18] + "_" + strconv.Itoa(execCommandID)
+ execCommandID++
+ }
// Create new execution over WS context
- execWS := eows.New(strings.Join(cmd, " "), cmdArgs, sop, sess.ID, cmdID)
+ execWS := eows.New(strings.Join(cmd, " "), cmdArgs, sop, sess.ID, args.CmdID)
execWS.Log = s.log
// Append client project dir to environment
diff --git a/lib/apiv1/folders.go b/lib/apiv1/folders.go
index a231b86..398e21c 100644
--- a/lib/apiv1/folders.go
+++ b/lib/apiv1/folders.go
@@ -16,7 +16,12 @@ func (s *APIService) getFolders(c *gin.Context) {
// getFolder returns a specific folder configuration
func (s *APIService) getFolder(c *gin.Context) {
- f := s.mfolders.Get(c.Param("id"))
+ id, err := s.mfolders.ResolveID(c.Param("id"))
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
+ f := s.mfolders.Get(id)
if f == nil {
common.APIError(c, "Invalid id")
return
@@ -67,11 +72,14 @@ func (s *APIService) addFolder(c *gin.Context) {
// syncFolder force synchronization of folder files
func (s *APIService) syncFolder(c *gin.Context) {
- id := c.Param("id")
-
+ id, err := s.mfolders.ResolveID(c.Param("id"))
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
s.log.Debugln("Sync folder id: ", id)
- err := s.mfolders.ForceSync(id)
+ err = s.mfolders.ForceSync(id)
if err != nil {
common.APIError(c, err.Error())
return
@@ -82,7 +90,11 @@ func (s *APIService) syncFolder(c *gin.Context) {
// delFolder deletes folder from server config
func (s *APIService) delFolder(c *gin.Context) {
- id := c.Param("id")
+ id, err := s.mfolders.ResolveID(c.Param("id"))
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
s.log.Debugln("Delete folder id ", id)
diff --git a/lib/apiv1/make.go b/lib/apiv1/make.go
index cf76476..6e0c7d6 100644
--- a/lib/apiv1/make.go
+++ b/lib/apiv1/make.go
@@ -15,7 +15,8 @@ import (
// MakeArgs is the parameters (json format) of /make command
type MakeArgs struct {
ID string `json:"id"`
- SdkID string `json:"sdkid"` // sdk ID to use for setting env
+ SdkID string `json:"sdkID"` // sdk ID to use for setting env
+ CmdID string `json:"cmdID"` // command unique ID
Args []string `json:"args"` // args to pass to make command
Env []string `json:"env"`
RPath string `json:"rpath"` // relative path into project
@@ -67,15 +68,19 @@ func (s *APIService) buildMake(c *gin.Context) {
}
// Allow to pass id in url (/make/:id) or as JSON argument
- id := c.Param("id")
- if id == "" {
- id = args.ID
+ idArg := c.Param("id")
+ if idArg == "" {
+ idArg = args.ID
}
- if id == "" {
+ if idArg == "" {
common.APIError(c, "Invalid id")
return
}
-
+ id, err := s.mfolders.ResolveID(idArg)
+ if err != nil {
+ common.APIError(c, err.Error())
+ return
+ }
pf := s.mfolders.Get(id)
if pf == nil {
common.APIError(c, "Unknown id")
@@ -171,8 +176,11 @@ func (s *APIService) buildMake(c *gin.Context) {
}
}
- cmdID := strconv.Itoa(makeCommandID)
- makeCommandID++
+ // Unique ID for each commands
+ if args.CmdID == "" {
+ args.CmdID = s.cfg.ServerUID[:18] + "_" + strconv.Itoa(makeCommandID)
+ makeCommandID++
+ }
cmd := []string{}
// Retrieve env command regarding Sdk ID
@@ -186,14 +194,14 @@ func (s *APIService) buildMake(c *gin.Context) {
cmd = append(cmd, args.Args...)
}
- s.log.Debugf("Execute [Cmd ID %d]: %v", cmdID, cmd)
+ s.log.Debugf("Execute [Cmd ID %d]: %v", args.CmdID, cmd)
data := make(map[string]interface{})
data["ID"] = prj.ID
data["RootPath"] = prj.RootPath
data["ExitImmediate"] = args.ExitImmediate
- err := common.ExecPipeWs(cmd, args.Env, sop, sess.ID, cmdID, execTmo, s.log, oCB, eCB, &data)
+ err = common.ExecPipeWs(cmd, args.Env, sop, sess.ID, args.CmdID, execTmo, s.log, oCB, eCB, &data)
if err != nil {
common.APIError(c, err.Error())
return
@@ -202,6 +210,6 @@ func (s *APIService) buildMake(c *gin.Context) {
c.JSON(http.StatusOK,
gin.H{
"status": "OK",
- "cmdID": cmdID,
+ "cmdID": args.CmdID,
})
}
diff --git a/lib/apiv1/sdks.go b/lib/apiv1/sdks.go
index 52af506..f67a0ef 100644
--- a/lib/apiv1/sdks.go
+++ b/lib/apiv1/sdks.go
@@ -2,7 +2,6 @@ package apiv1
import (
"net/http"
- "strconv"
"github.com/gin-gonic/gin"
common "github.com/iotbzh/xds-common/golib"
@@ -15,12 +14,11 @@ func (s *APIService) getSdks(c *gin.Context) {
// getSdk returns a specific Sdk configuration
func (s *APIService) getSdk(c *gin.Context) {
- id, err := strconv.Atoi(c.Param("id"))
+ id, err := s.sdks.ResolveID(c.Param("id"))
if err != nil {
- common.APIError(c, "Invalid id")
+ common.APIError(c, err.Error())
return
}
-
sdk := s.sdks.Get(id)
if sdk.Profile == "" {
common.APIError(c, "Invalid id")
diff --git a/lib/apiv1/version.go b/lib/apiv1/version.go
index e022441..8f928ec 100644
--- a/lib/apiv1/version.go
+++ b/lib/apiv1/version.go
@@ -7,6 +7,7 @@ import (
)
type version struct {
+ ID string `json:"id"`
Version string `json:"version"`
APIVersion string `json:"apiVersion"`
VersionGitTag string `json:"gitTag"`
@@ -15,6 +16,7 @@ type version struct {
// getInfo : return various information about server
func (s *APIService) getVersion(c *gin.Context) {
response := version{
+ ID: s.cfg.ServerUID,
Version: s.cfg.Version,
APIVersion: s.cfg.APIVersion,
VersionGitTag: s.cfg.VersionGitTag,