X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=lib%2Fagent%2Fapiv1-exec.go;h=9c65bc2130f1aa1943483c428f21bbddecd3f8b9;hb=be13167b869161b6e19dc3e94835245cdc7911e5;hp=37070f7afab871cbef6dbf3ad447e6d9aaa3f064;hpb=459f46bc410c8641314d5f3eb39c871558b7d156;p=src%2Fxds%2Fxds-agent.git diff --git a/lib/agent/apiv1-exec.go b/lib/agent/apiv1-exec.go index 37070f7..9c65bc2 100644 --- a/lib/agent/apiv1-exec.go +++ b/lib/agent/apiv1-exec.go @@ -6,16 +6,11 @@ import ( "net/http" "github.com/gin-gonic/gin" + "github.com/iotbzh/xds-agent/lib/apiv1" common "github.com/iotbzh/xds-common/golib" uuid "github.com/satori/go.uuid" ) -// ExecArgs Only define used fields -type ExecArgs struct { - ID string `json:"id" binding:"required"` - CmdID string `json:"cmdID"` // command unique ID -} - var execCmdID = 1 // ExecCmd executes remotely a command @@ -34,7 +29,7 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { common.APIError(c, err.Error()) } - args := ExecArgs{} + args := apiv1.ExecArgs{} // XXX - we cannot use c.BindJSON, so directly unmarshall it // (see https://github.com/gin-gonic/gin/issues/1078) if err := json.Unmarshal(data, &args); err != nil { @@ -75,10 +70,10 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { // Forward XDSServer WS events to client WS // TODO removed static event name list and get it from XDSServer evtList := []string{ - "exec:input", - "exec:output", - "exec:inferior-input", - "exec:inferior-output", + apiv1.ExecInEvent, + apiv1.ExecOutEvent, + apiv1.ExecInferiorInEvent, + apiv1.ExecInferiorOutEvent, } so := *sock fwdFuncID := []uuid.UUID{} @@ -99,15 +94,15 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { // Handle Exit event separately to cleanup registered listener var exitFuncID uuid.UUID exitFunc := func(evData interface{}) { - so.Emit("exec:exit", evData) + so.Emit(apiv1.ExecExitEvent, evData) // cleanup listener for i, evName := range evtList { svr.EventOff(evName, fwdFuncID[i]) } - svr.EventOff("exec:exit", exitFuncID) + svr.EventOff(apiv1.ExecExitEvent, exitFuncID) } - exitFuncID, err = svr.EventOn("exec:exit", exitFunc) + exitFuncID, err = svr.EventOn(apiv1.ExecExitEvent, exitFunc) if err != nil { common.APIError(c, err.Error()) return @@ -127,5 +122,4 @@ func (s *APIService) _execRequest(cmd string, c *gin.Context) { return } c.JSON(http.StatusOK, string(body)) - }