Skip to content

Commit b1c9745

Browse files
committed
moved from local toolspec to shared package
1 parent e188d02 commit b1c9745

File tree

12 files changed

+40
-108
lines changed

12 files changed

+40
-108
lines changed

api/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func RespondWithError(w http.ResponseWriter, status int, err string) {
8080
w.Write([]byte(err))
8181
}
8282

83-
func ResondWithJSON(w http.ResponseWriter, status int, data interface{}) {
83+
func RespondWithJSON(w http.ResponseWriter, status int, data interface{}) {
8484
w.Header().Set("Content-Type", "application/json")
8585
w.WriteHeader(status)
8686
err := json.NewEncoder(w).Encode(data)

api/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func HandleRefreshToken(w http.ResponseWriter, r *http.Request) {
2828
RespondWithError(w, http.StatusUnauthorized, fmt.Sprintf("Invalid refresh token: %v", err))
2929
}
3030

31-
ResondWithJSON(w, http.StatusOK, response)
31+
RespondWithJSON(w, http.StatusOK, response)
3232
}
3333

3434
func HandleLogin(w http.ResponseWriter, r *http.Request) {
@@ -50,5 +50,5 @@ func HandleLogin(w http.ResponseWriter, r *http.Request) {
5050
return
5151
}
5252

53-
ResondWithJSON(w, http.StatusOK, response)
53+
RespondWithJSON(w, http.StatusOK, response)
5454
}

api/files.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func HandleFileUpload(w http.ResponseWriter, r *http.Request) {
5252
RespondWithError(w, 500, fmt.Sprintf("error writing to target file: %s", err))
5353
}
5454

55-
ResondWithJSON(w, http.StatusCreated, map[string]interface{}{
55+
RespondWithJSON(w, http.StatusCreated, map[string]interface{}{
5656
"path": targetPath,
5757
"size": writtenBytes,
5858
"name": handler.Filename,
@@ -83,7 +83,7 @@ func FindFile(w http.ResponseWriter, r *http.Request) {
8383
return
8484
}
8585

86-
ResondWithJSON(w, http.StatusOK, FindFilesResponse{
86+
RespondWithJSON(w, http.StatusOK, FindFilesResponse{
8787
Count: len(matches),
8888
Files: matches,
8989
})

api/results.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func ListRunResults(w http.ResponseWriter, r *http.Request, tool tool.Tool) {
1919
RespondWithError(w, http.StatusInternalServerError, err.Error())
2020
}
2121

22-
ResondWithJSON(w, http.StatusOK, ListRunResultsResponse{
22+
RespondWithJSON(w, http.StatusOK, ListRunResultsResponse{
2323
Count: len(results),
2424
Files: results,
2525
})

api/run_specs.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
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

7980
func 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
}

api/runs_state.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func GetAllRuns(w http.ResponseWriter, r *http.Request) {
6969
toolRuns = append(toolRuns, toolRun)
7070
}
7171

72-
ResondWithJSON(w, http.StatusOK, RunsResponse{
72+
RespondWithJSON(w, http.StatusOK, RunsResponse{
7373
Count: len(runs),
7474
Status: filter,
7575
Runs: toolRuns,
@@ -102,14 +102,14 @@ func DeleteRun(w http.ResponseWriter, r *http.Request, tool tool.Tool) {
102102
if err != nil {
103103
RespondWithError(w, http.StatusInternalServerError, err.Error())
104104
}
105-
ResondWithJSON(w, http.StatusOK, map[string]string{
105+
RespondWithJSON(w, http.StatusOK, map[string]string{
106106
"message": "Run deleted",
107107
})
108108

109109
}
110110

111111
func GetRunStatus(w http.ResponseWriter, r *http.Request, run tool.Tool) {
112-
ResondWithJSON(w, http.StatusOK, run)
112+
RespondWithJSON(w, http.StatusOK, run)
113113
}
114114

115115
func HandleRunStart(w http.ResponseWriter, r *http.Request, run tool.Tool) {
@@ -139,5 +139,5 @@ func HandleRunStart(w http.ResponseWriter, r *http.Request, run tool.Tool) {
139139
if err != nil {
140140
RespondWithError(w, http.StatusInternalServerError, err.Error())
141141
}
142-
ResondWithJSON(w, http.StatusProcessing, started)
142+
RespondWithJSON(w, http.StatusProcessing, started)
143143
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/docker/docker v28.3.1+incompatible
1010
github.com/golang-jwt/jwt/v5 v5.2.2
1111
github.com/google/uuid v1.6.0
12-
github.com/hydrocode-de/tool-spec-go v0.0.0-20251123064647-3a7cc964f7b2
12+
github.com/hydrocode-de/tool-spec-go v0.1.0
1313
github.com/jedib0t/go-pretty/v6 v6.6.7
1414
github.com/joho/godotenv v1.5.1
1515
github.com/pressly/goose/v3 v3.24.3

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5151
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5252
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 h1:X5VWvz21y3gzm9Nw/kaUeku/1+uBhcekkmy4IkffJww=
5353
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1/go.mod h1:Zanoh4+gvIgluNqcfMVTJueD4wSS5hT7zTt4Mrutd90=
54-
github.com/hydrocode-de/tool-spec-go v0.0.0-20251123064647-3a7cc964f7b2 h1:nfApKsi6KJxffNVlkSsIAVcSbc9i6dnKMHr+hIHSi7g=
55-
github.com/hydrocode-de/tool-spec-go v0.0.0-20251123064647-3a7cc964f7b2/go.mod h1:jM1nE1DBIPNCenBbNj6OCbEIImMCza/ANsUzec6trk0=
54+
github.com/hydrocode-de/tool-spec-go v0.1.0 h1:GnAlPDylTmz5n8wIZegYJ5cLzh9MqLAr7hm5fxl+bQU=
55+
github.com/hydrocode-de/tool-spec-go v0.1.0/go.mod h1:jM1nE1DBIPNCenBbNj6OCbEIImMCza/ANsUzec6trk0=
5656
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
5757
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
5858
github.com/jedib0t/go-pretty/v6 v6.6.7 h1:m+LbHpm0aIAPLzLbMfn8dc3Ht8MW7lsSO4MPItz/Uuo=

internal/cache/cache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cache
22

33
import (
4-
"github.com/hydrocode-de/tool-spec-go"
4+
toolspec "github.com/hydrocode-de/tool-spec-go"
55
)
66

77
type Cache struct {

internal/tool/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/hydrocode-de/gorun/internal/files"
1313
"github.com/hydrocode-de/gorun/internal/helper"
1414
"github.com/hydrocode-de/gorun/internal/toolImage"
15-
"github.com/hydrocode-de/tool-spec-go"
15+
toolspec "github.com/hydrocode-de/tool-spec-go"
1616
"github.com/spf13/viper"
1717
)
1818

0 commit comments

Comments
 (0)