"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
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 {
// 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{}
// 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
return
}
c.JSON(http.StatusOK, string(body))
-
}