Skip to content

Commit

Permalink
Removed 'common' from map-executor and added 'getActions' to rest-con…
Browse files Browse the repository at this point in the history
…troller

The 'common' dependency was removed from map-executor.go and the 'for-each' function is commented out. Furthermore, a 'getActions' function was added in rest-controller.go. This provides a new route '/action' that generates a JSON containing all available actions with their inputs and outputs.
  • Loading branch information
PiotrFerenc committed May 14, 2024
1 parent 61df963 commit 3d8b775
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
33 changes: 33 additions & 0 deletions internal/controllers/rest-controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package controllers
import (
"fmt"
"github.com/PiotrFerenc/mash2/api/types"
"github.com/PiotrFerenc/mash2/cmd/worker/actions"
"github.com/PiotrFerenc/mash2/internal/configuration"
Message "github.com/PiotrFerenc/mash2/internal/consts"
"github.com/PiotrFerenc/mash2/internal/executor"
"github.com/PiotrFerenc/mash2/internal/repositories"
"github.com/PiotrFerenc/mash2/internal/services"
"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -38,6 +41,7 @@ func CreateRestController(pipelineService services.PipelineService, repository r
func (controller *controller) Run(address, port string) error {
server := gin.Default()
server.GET("/process/:id", getByIdHandler(controller))
server.GET("/action", getActions(controller))
server.POST("/execute", executeHandler(controller))

err := server.Run(fmt.Sprintf(`%s:%s`, address, port))
Expand All @@ -48,6 +52,35 @@ func (controller *controller) Run(address, port string) error {

}

func getActions(c *controller) gin.HandlerFunc {
return func(c *gin.Context) {
a := executor.CreateActionMap(&configuration.Config{})
actionsList := make([]Actions, 0, len(a))
for name, action := range a {
actionsList = append(actionsList, Actions{
Name: name,
Inputs: getPropertyNames(action.Inputs()),
Outputs: getPropertyNames(action.Outputs()),
})
}
c.JSON(http.StatusOK, gin.H{"actions": actionsList})
return
}
}
func getPropertyNames(properties []actions.Property) []string {
propertyNames := make([]string, len(properties))
for i, prop := range properties {
propertyNames[i] = prop.Name
}
return propertyNames
}

type Actions struct {
Name string `json:"name,omitempty"`
Inputs []string `json:"inputs,omitempty"`
Outputs []string `json:"outputs,omitempty"`
}

// getByIdHandler is a handler function that retrieves a process by its ID and returns
// the status of the process.
// It takes a controller instance as a parameter and returns a function that has a
Expand Down
3 changes: 1 addition & 2 deletions internal/executor/map-executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/PiotrFerenc/mash2/cmd/worker/actions"
"github.com/PiotrFerenc/mash2/cmd/worker/actions/common"
"github.com/PiotrFerenc/mash2/cmd/worker/actions/docker"
"github.com/PiotrFerenc/mash2/cmd/worker/actions/file"
"github.com/PiotrFerenc/mash2/cmd/worker/actions/git"
Expand Down Expand Up @@ -124,6 +123,6 @@ func CreateActionMap(config *configuration.Config) map[string]actions.Action {
"docker-run": docker.CreateDockerRun(),
"file-delete": file.CreateDeleteFileAction(config),
"file-append": file.CreateAppendContentToFile(config),
"for-each": common.CreateForEachLoop(),
//"for-each": common.CreateForEachLoop(),
}
}

0 comments on commit 3d8b775

Please sign in to comment.