feat: os-dependent default entrypoint
Co-authored-by: Roberto Abdelkader Martínez Pérez <robertomartinezp@gmail.com>
This commit is contained in:
@@ -27,10 +27,14 @@ import (
|
||||
// AddRoute will add a new route in kapow
|
||||
func AddRoute(host, path, method, entrypoint, command string, w io.Writer) error {
|
||||
url := host + "/routes"
|
||||
body, _ := json.Marshal(map[string]string{
|
||||
payload := map[string]string{
|
||||
"method": method,
|
||||
"url_pattern": path,
|
||||
"entrypoint": entrypoint,
|
||||
"command": command})
|
||||
"command": command,
|
||||
}
|
||||
if entrypoint != "" {
|
||||
payload["entrypoint"] = entrypoint
|
||||
}
|
||||
body, _ := json.Marshal(payload)
|
||||
return http.Post(url, "application/json", bytes.NewReader(body), w)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,6 @@ func TestSuccessOnCorrectRoute(t *testing.T) {
|
||||
JSON(map[string]string{
|
||||
"method": "GET",
|
||||
"url_pattern": "/hello",
|
||||
"entrypoint": "",
|
||||
"command": "echo Hello World | kapow set /response/body",
|
||||
}).
|
||||
Reply(http.StatusCreated).
|
||||
|
||||
@@ -80,7 +80,7 @@ func init() {
|
||||
// TODO: Add default values for flags and remove path flag
|
||||
routeAddCmd.Flags().String("control-url", getEnv("KAPOW_CONTROL_URL", "http://localhost:8081"), "Kapow! control interface URL")
|
||||
routeAddCmd.Flags().StringP("method", "X", "GET", "HTTP method to accept")
|
||||
routeAddCmd.Flags().StringP("entrypoint", "e", "/bin/sh -c", "Command to execute")
|
||||
routeAddCmd.Flags().StringP("entrypoint", "e", "", "Command to execute")
|
||||
routeAddCmd.Flags().StringP("command", "c", "", "Command to pass to the shell")
|
||||
|
||||
var routeRemoveCmd = &cobra.Command{
|
||||
|
||||
@@ -132,6 +132,10 @@ func addRoute(res http.ResponseWriter, req *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
if route.Entrypoint == "" {
|
||||
route.Entrypoint = defaultEntrypoint
|
||||
}
|
||||
|
||||
route.ID = id.String()
|
||||
|
||||
created := funcAdd(route)
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// +build !windows
|
||||
|
||||
package control
|
||||
|
||||
var defaultEntrypoint = "/bin/sh -c"
|
||||
@@ -0,0 +1,3 @@
|
||||
package control
|
||||
|
||||
var defaultEntrypoint = "cmd.exe /c"
|
||||
@@ -19,7 +19,7 @@ package model
|
||||
// Route contains the data needed to represent a Kapow! user route.
|
||||
type Route struct {
|
||||
// ID is the unique identifier of the Route.
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id,omitempty"`
|
||||
|
||||
// Method is the HTTP method that will match this Route.
|
||||
Method string `json:"method"`
|
||||
@@ -33,7 +33,7 @@ type Route struct {
|
||||
//
|
||||
// This string will be split according to the shell parsing rules to
|
||||
// be passed as a list to exec.Command.
|
||||
Entrypoint string `json:"entrypoint"`
|
||||
Entrypoint string `json:"entrypoint,omitempty"`
|
||||
|
||||
// Command is the last argument to be passed to exec.Command when
|
||||
// executing the Entrypoint
|
||||
@@ -43,5 +43,5 @@ type Route struct {
|
||||
// It is an output field, its value is ignored as input.
|
||||
Index int `json:"index"`
|
||||
|
||||
Debug bool `json:"debug"`
|
||||
Debug bool `json:"debug,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user