Add HTTP route create params to function create command
This allows users to add --method and --url params to their "fission fn create" command line. It sets up the route to call the latest version of the function; user can edit the route with the "fission route update" command, if they want to.
This commit is contained in:
@@ -23,6 +23,7 @@ import (
|
||||
"os/exec"
|
||||
"text/tabwriter"
|
||||
|
||||
"github.com/satori/go.uuid"
|
||||
"github.com/urfave/cli"
|
||||
|
||||
"github.com/platform9/fission"
|
||||
@@ -59,6 +60,31 @@ func fnCreate(c *cli.Context) error {
|
||||
checkErr(err, "create function")
|
||||
|
||||
fmt.Printf("function '%v' created\n", fnName)
|
||||
|
||||
// Allow the user to specify an HTTP trigger while creating a function.
|
||||
triggerUrl := c.String("url")
|
||||
if len(triggerUrl) == 0 {
|
||||
return nil
|
||||
}
|
||||
method := c.String("method")
|
||||
if len(method) == 0 {
|
||||
method = "GET"
|
||||
}
|
||||
triggerName := uuid.NewV4().String()
|
||||
ht := &fission.HTTPTrigger{
|
||||
Metadata: fission.Metadata{
|
||||
Name: triggerName,
|
||||
},
|
||||
UrlPattern: triggerUrl,
|
||||
Method: getMethod(method),
|
||||
Function: fission.Metadata{
|
||||
Name: fnName,
|
||||
},
|
||||
}
|
||||
_, err = client.HTTPTriggerCreate(ht)
|
||||
checkErr(err, "create HTTP trigger")
|
||||
fmt.Printf("route created: %v %v -> %v\n", method, triggerUrl, fnName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
+5
-3
@@ -31,13 +31,17 @@ func main() {
|
||||
cli.StringFlag{Name: "server", Usage: "Fission server URL", EnvVar: "FISSION_URL"},
|
||||
}
|
||||
|
||||
// trigger method and url flags (used in function and route CLIs)
|
||||
htMethodFlag := cli.StringFlag{Name: "method", Usage: "HTTP Method: GET|POST|PUT|DELETE|HEAD; defaults to GET"}
|
||||
htUrlFlag := cli.StringFlag{Name: "url", Usage: "URL pattern (See gorilla/mux supported patterns)"}
|
||||
|
||||
// functions
|
||||
fnNameFlag := cli.StringFlag{Name: "name", Usage: "function name"}
|
||||
fnEnvNameFlag := cli.StringFlag{Name: "env", Usage: "environment name for function"}
|
||||
fnCodeFlag := cli.StringFlag{Name: "code", Usage: "file containing source code, or - for stdin"}
|
||||
fnUidFlag := cli.StringFlag{Name: "uid", Usage: "function uid, optional (use latest if unspecified)"}
|
||||
fnSubcommands := []cli.Command{
|
||||
{Name: "create", Usage: "Create new function", Flags: []cli.Flag{fnNameFlag, fnEnvNameFlag, fnCodeFlag}, Action: fnCreate},
|
||||
{Name: "create", Usage: "Create new function (and optionally, an HTTP route to it)", Flags: []cli.Flag{fnNameFlag, fnEnvNameFlag, fnCodeFlag, htUrlFlag, htMethodFlag}, Action: fnCreate},
|
||||
{Name: "get", Usage: "Get function source code", Flags: []cli.Flag{fnNameFlag, fnUidFlag}, Action: fnGet},
|
||||
{Name: "edit", Usage: "Edit function source code in $EDITOR", Flags: []cli.Flag{fnNameFlag, fnUidFlag}, Action: fnEdit},
|
||||
{Name: "getmeta", Usage: "Get function metadata", Flags: []cli.Flag{fnNameFlag, fnUidFlag}, Action: fnGetMeta},
|
||||
@@ -48,8 +52,6 @@ func main() {
|
||||
|
||||
// httptriggers
|
||||
htNameFlag := cli.StringFlag{Name: "name", Usage: "HTTP Trigger name"}
|
||||
htMethodFlag := cli.StringFlag{Name: "method", Usage: "HTTP Method: GET|POST|PUT|DELETE|HEAD; defaults to GET"}
|
||||
htUrlFlag := cli.StringFlag{Name: "url", Usage: "URL pattern (See gorilla/mux supported patterns)"}
|
||||
htFnNameFlag := cli.StringFlag{Name: "function", Usage: "Function name"}
|
||||
htFnUidFlag := cli.StringFlag{Name: "uid", Usage: "Function UID (optional; uses latest if unspecified)"}
|
||||
htSubcommands := []cli.Command{
|
||||
|
||||
Reference in New Issue
Block a user