summaryrefslogtreecommitdiffstats
path: root/lib/apiv1
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-06 14:50:03 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-11-06 16:00:04 +0100
commitebf38065f8a0c0c3d1a3a7ce2a4caaaad712432c (patch)
tree00ca89c63f4ce48566202c6c32f76fe1ad3de4d3 /lib/apiv1
parent8d3f51e52894d46a4a92a944bc09f4ceaa1abf51 (diff)
Added short project ID name support if not ambiguous.
Diffstat (limited to 'lib/apiv1')
-rw-r--r--lib/apiv1/events.go6
-rw-r--r--lib/apiv1/exec.go14
-rw-r--r--lib/apiv1/folders.go22
-rw-r--r--lib/apiv1/make.go16
4 files changed, 41 insertions, 17 deletions
diff --git a/lib/apiv1/events.go b/lib/apiv1/events.go
index 8f92ae0..9444262 100644
--- a/lib/apiv1/events.go
+++ b/lib/apiv1/events.go
@@ -122,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 0167196..8ffad07 100644
--- a/lib/apiv1/exec.go
+++ b/lib/apiv1/exec.go
@@ -105,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")
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 223d4bf..6e0c7d6 100644
--- a/lib/apiv1/make.go
+++ b/lib/apiv1/make.go
@@ -68,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")
@@ -197,7 +201,7 @@ func (s *APIService) buildMake(c *gin.Context) {
data["RootPath"] = prj.RootPath
data["ExitImmediate"] = args.ExitImmediate
- err := common.ExecPipeWs(cmd, args.Env, sop, sess.ID, args.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