Support for multiple HTTP verbs in routes/HTTPTrigger (#2064)
* Support for multiple HTTP verbs in routes/HTTPTrigger Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> * Update pkg/apis/core/v1/types.go Co-authored-by: Harsh Thakur <harshthakur9030@gmail.com> * Fix fallbackurl for ingress Signed-off-by: Sanket Sudake <sanketsudake@gmail.com> Co-authored-by: Harsh Thakur <harshthakur9030@gmail.com>
This commit is contained in:
co-authored by
Harsh Thakur
parent
4038f0384b
commit
673ca25cf2
@@ -89,6 +89,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
|
||||
triggerUrl := input.String(flagkey.HtUrl)
|
||||
prefix := input.String(flagkey.HtPrefix)
|
||||
fallbackURL := ""
|
||||
|
||||
if triggerUrl == "" && prefix == "" {
|
||||
console.Error("You need to supply either Prefix or URL/RelativeURL")
|
||||
@@ -108,10 +109,22 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
if prefix != "" && !strings.HasPrefix(prefix, "/") {
|
||||
prefix = "/" + prefix
|
||||
}
|
||||
if prefix != "" {
|
||||
fallbackURL = prefix
|
||||
} else {
|
||||
fallbackURL = triggerUrl
|
||||
}
|
||||
|
||||
method, err := GetMethod(input.String(flagkey.HtMethod))
|
||||
if err != nil {
|
||||
return err
|
||||
methods := input.StringSlice(flagkey.HtMethod)
|
||||
if len(methods) == 0 {
|
||||
return errors.New("HTTP methods not mentioned")
|
||||
}
|
||||
|
||||
for _, method := range methods {
|
||||
_, err := GetMethod(method)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// For Specs, the spec validate checks for function reference
|
||||
@@ -146,7 +159,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
createIngress := input.Bool(flagkey.HtIngress)
|
||||
ingressConfig, err := GetIngressConfig(
|
||||
input.StringSlice(flagkey.HtIngressAnnotation), input.String(flagkey.HtIngressRule),
|
||||
input.String(flagkey.HtIngressTLS), triggerUrl, nil)
|
||||
input.String(flagkey.HtIngressTLS), fallbackURL, nil)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error parsing ingress configuration")
|
||||
}
|
||||
@@ -161,7 +174,7 @@ func (opts *CreateSubCommand) complete(input cli.Input) error {
|
||||
Spec: fv1.HTTPTriggerSpec{
|
||||
Host: host,
|
||||
RelativeURL: triggerUrl,
|
||||
Method: method,
|
||||
Methods: methods,
|
||||
FunctionReference: *functionRef,
|
||||
CreateIngress: createIngress,
|
||||
IngressConfig: *ingressConfig,
|
||||
@@ -220,7 +233,7 @@ func GetMethod(method string) (string, error) {
|
||||
case http.MethodTrace:
|
||||
return http.MethodTrace, nil
|
||||
default:
|
||||
return "", fmt.Errorf("invalid or unsupported HTTP Method %v", method)
|
||||
return "", fmt.Errorf("invalid or unsupported HTTP Method '%v'", method)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,8 +86,15 @@ func printHtSummary(triggers []fv1.HTTPTrigger) {
|
||||
}
|
||||
ann := strings.Join(msg, ", ")
|
||||
|
||||
methods := []string{}
|
||||
if len(trigger.Spec.Method) > 0 {
|
||||
methods = append(methods, trigger.Spec.Method)
|
||||
}
|
||||
if len(trigger.Spec.Methods) > 0 {
|
||||
methods = trigger.Spec.Methods
|
||||
}
|
||||
fmt.Fprintf(w, "%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\t%v\n",
|
||||
trigger.ObjectMeta.Name, trigger.Spec.Method, trigger.Spec.RelativeURL, function, trigger.Spec.CreateIngress, host, path, trigger.Spec.IngressConfig.TLS, ann)
|
||||
trigger.ObjectMeta.Name, methods, trigger.Spec.RelativeURL, function, trigger.Spec.CreateIngress, host, path, trigger.Spec.IngressConfig.TLS, ann)
|
||||
}
|
||||
w.Flush()
|
||||
}
|
||||
|
||||
@@ -80,8 +80,15 @@ func (opts *UpdateSubCommand) complete(input cli.Input) error {
|
||||
ht.Spec.RelativeURL = triggerUrl
|
||||
ht.Spec.Prefix = &prefix
|
||||
|
||||
if input.IsSet(flagkey.HtMethod) {
|
||||
ht.Spec.Method = input.String(flagkey.HtMethod)
|
||||
methods := input.StringSlice(flagkey.HtMethod)
|
||||
if len(methods) > 0 {
|
||||
for _, method := range methods {
|
||||
_, err := GetMethod(method)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
ht.Spec.Methods = methods
|
||||
}
|
||||
|
||||
if input.IsSet(flagkey.HtFnName) {
|
||||
|
||||
Reference in New Issue
Block a user