diff options
Diffstat (limited to 'lib/apiv1')
-rw-r--r-- | lib/apiv1/apiv1.go | 8 | ||||
-rw-r--r-- | lib/apiv1/make.go | 12 | ||||
-rw-r--r-- | lib/apiv1/sdks.go | 31 |
3 files changed, 45 insertions, 6 deletions
diff --git a/lib/apiv1/apiv1.go b/lib/apiv1/apiv1.go index c94849d..7359266 100644 --- a/lib/apiv1/apiv1.go +++ b/lib/apiv1/apiv1.go @@ -4,6 +4,7 @@ import ( "github.com/Sirupsen/logrus" "github.com/gin-gonic/gin" + "github.com/iotbzh/xds-server/lib/crosssdk" "github.com/iotbzh/xds-server/lib/model" "github.com/iotbzh/xds-server/lib/session" "github.com/iotbzh/xds-server/lib/xdsconfig" @@ -16,17 +17,19 @@ type APIService struct { sessions *session.Sessions cfg *xdsconfig.Config mfolder *model.Folder + sdks *crosssdk.SDKs log *logrus.Logger } // New creates a new instance of API service -func New(sess *session.Sessions, cfg *xdsconfig.Config, mfolder *model.Folder, r *gin.Engine) *APIService { +func New(r *gin.Engine, sess *session.Sessions, cfg *xdsconfig.Config, mfolder *model.Folder, sdks *crosssdk.SDKs) *APIService { s := &APIService{ router: r, sessions: sess, apiRouter: r.Group("/api/v1"), cfg: cfg, mfolder: mfolder, + sdks: sdks, log: cfg.Log, } @@ -40,6 +43,9 @@ func New(sess *session.Sessions, cfg *xdsconfig.Config, mfolder *model.Folder, r s.apiRouter.POST("/folder", s.addFolder) s.apiRouter.DELETE("/folder/:id", s.delFolder) + s.apiRouter.GET("/sdks", s.getSdks) + s.apiRouter.GET("/sdk/:id", s.getSdk) + s.apiRouter.POST("/make", s.buildMake) s.apiRouter.POST("/make/:id", s.buildMake) diff --git a/lib/apiv1/make.go b/lib/apiv1/make.go index 1e6d937..fb6435e 100644 --- a/lib/apiv1/make.go +++ b/lib/apiv1/make.go @@ -14,8 +14,9 @@ import ( // MakeArgs is the parameters (json format) of /make command type MakeArgs struct { ID string `json:"id"` - RPath string `json:"rpath"` // relative path into project - Args string `json:"args"` + RPath string `json:"rpath"` // relative path into project + Args string `json:"args"` // args to pass to make command + SdkID string `json:"sdkid"` // sdk ID to use for setting env CmdTimeout int `json:"timeout"` // command completion timeout in Second } @@ -138,9 +139,10 @@ func (s *APIService) buildMake(c *gin.Context) { cmdID := makeCommandID makeCommandID++ - /* SEB TODO . /opt/poky-agl/3.90.0+snapshot/environment-setup-aarch64-agl-linux - env := os.Environ() - */ + // Retrieve env command regarding Sdk ID + if envCmd := s.sdks.GetEnvCmd(args.SdkID, prj.DefaultSdk); envCmd != "" { + cmd = envCmd + " && " + cmd + } s.log.Debugf("Execute [Cmd ID %d]: %v", cmdID, cmd) err := common.ExecPipeWs(cmd, sop, sess.ID, cmdID, execTmo, s.log, oCB, eCB) diff --git a/lib/apiv1/sdks.go b/lib/apiv1/sdks.go new file mode 100644 index 0000000..5ae2b03 --- /dev/null +++ b/lib/apiv1/sdks.go @@ -0,0 +1,31 @@ +package apiv1 + +import ( + "net/http" + "strconv" + + "github.com/gin-gonic/gin" + "github.com/iotbzh/xds-server/lib/common" +) + +// getSdks returns all SDKs configuration +func (s *APIService) getSdks(c *gin.Context) { + c.JSON(http.StatusOK, s.sdks.GetAll()) +} + +// getSdk returns a specific Sdk configuration +func (s *APIService) getSdk(c *gin.Context) { + id, err := strconv.Atoi(c.Param("id")) + if err != nil { + common.APIError(c, "Invalid id") + return + } + + sdk := s.sdks.Get(id) + if sdk.Profile == "" { + common.APIError(c, "Invalid id") + return + } + + c.JSON(http.StatusOK, sdk) +} |