99 "github.com/hydrocode-de/gorun/internal/cache"
1010 "github.com/hydrocode-de/gorun/internal/db"
1111 "github.com/hydrocode-de/gorun/internal/tool"
12- "github.com/hydrocode-de/tool-spec-go"
12+ toolspec "github.com/hydrocode-de/tool-spec-go"
13+ "github.com/hydrocode-de/tool-spec-go/validate"
1314 "github.com/spf13/viper"
1415)
1516
@@ -73,14 +74,14 @@ func GetToolSpec(w http.ResponseWriter, r *http.Request) {
7374 if ! wasFound {
7475 RespondWithError (w , http .StatusNotFound , "tool not found" )
7576 }
76- ResondWithJSON (w , http .StatusOK , spec )
77+ RespondWithJSON (w , http .StatusOK , spec )
7778}
7879
7980func ListToolSpecs (w http.ResponseWriter , r * http.Request ) {
8081 Cache := viper .Get ("cache" ).(* cache.Cache )
8182 specs := Cache .ListToolSpecs ()
8283
83- ResondWithJSON (w , http .StatusOK , ListToolSpecResponse {
84+ RespondWithJSON (w , http .StatusOK , ListToolSpecResponse {
8485 Count : len (specs ),
8586 Tools : specs ,
8687 })
@@ -100,6 +101,25 @@ func CreateRun(w http.ResponseWriter, r *http.Request) {
100101 return
101102 }
102103
104+ Cache := viper .Get ("cache" ).(* cache.Cache )
105+ toolSlug := fmt .Sprintf ("%s::%s" , payload .DockerImage , payload .ToolName )
106+ toolSpec , wasFound := Cache .GetToolSpec (toolSlug )
107+ if ! wasFound {
108+ RespondWithError (w , http .StatusNotFound , fmt .Sprintf ("a tool %s was not found in the cache" , toolSlug ))
109+ return
110+ }
111+ hasErrors , errs := validate .ValidateInputs (* toolSpec , toolspec.ToolInput {
112+ Parameters : payload .Parameters ,
113+ Datasets : payload .DataPaths ,
114+ })
115+ if hasErrors {
116+ RespondWithJSON (w , http .StatusBadRequest , map [string ]interface {}{
117+ "message" : fmt .Sprintf ("the provided payload is invalid for the tool %s" , toolSlug ),
118+ "errors" : errs ,
119+ })
120+ return
121+ }
122+
103123 // create the mount paths with random strategy
104124 opts := tool.CreateRunOptions {
105125 Name : payload .ToolName ,
@@ -112,5 +132,5 @@ func CreateRun(w http.ResponseWriter, r *http.Request) {
112132 RespondWithError (w , http .StatusInternalServerError , err .Error ())
113133 }
114134
115- ResondWithJSON (w , http .StatusCreated , runData )
135+ RespondWithJSON (w , http .StatusCreated , runData )
116136}
0 commit comments