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:
Soam Vasani
2016-12-20 17:42:23 -08:00
parent f0b31564f0
commit a5d96b928c
2 changed files with 31 additions and 3 deletions
+26
View File
@@ -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
}