Add webhook server to tests (#2873)

* Add webhook server to tests
* fix config for webhoook service
* Fix logger in webhook manager
* Use interface for webhook manager
* single reference for router url
* Cleanup token code

---------

Signed-off-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
Sanket Sudake
2023-11-16 14:16:28 +05:30
committed by GitHub
parent 57b537f09e
commit e7d6381876
15 changed files with 346 additions and 92 deletions
+10 -20
View File
@@ -66,31 +66,21 @@ func (opts *TestSubCommand) do(input cli.Input) error {
Namespace: namespace,
}
routerURL := os.Getenv("FISSION_ROUTER_URL")
if len(routerURL) == 0 {
// Portforward to the fission router
localRouterPort, err := util.SetupPortForward(input.Context(), opts.Client(), util.GetFissionNamespace(), "application=fission-router")
if err != nil {
return err
}
routerURL = "http://127.0.0.1:" + localRouterPort
routerURL, err := util.GetRouterURL(input.Context(), opts.Client())
if err != nil {
return errors.Wrap(err, "error getting router URL")
}
fnURL := routerURL + util.UrlForFunction(m.Name, m.Namespace)
fnURI := util.UrlForFunction(m.Name, m.Namespace)
if input.IsSet(flagkey.FnSubPath) {
subPath := input.String(flagkey.FnSubPath)
if !strings.HasPrefix(subPath, "/") {
fnURL = fnURL + "/" + subPath
fnURI = fnURI + "/" + subPath
} else {
fnURL = fnURL + subPath
fnURI = fnURI + subPath
}
}
functionUrl, err := url.Parse(fnURL)
if err != nil {
return err
}
console.Verbose(2, "Function test url: %v", functionUrl.String())
fnURL := routerURL.JoinPath(fnURI)
console.Verbose(2, "Function test url: %v", fnURL.String())
queryParams := input.StringSlice(flagkey.FnTestQuery)
if len(queryParams) > 0 {
@@ -109,7 +99,7 @@ func (opts *TestSubCommand) do(input cli.Input) error {
}
query.Set(key, value)
}
functionUrl.RawQuery = query.Encode()
fnURL.RawQuery = query.Encode()
}
var (
@@ -145,7 +135,7 @@ func (opts *TestSubCommand) do(input cli.Input) error {
if err != nil {
return err
}
resp, err := doHTTPRequest(ctx, functionUrl.String(),
resp, err := doHTTPRequest(ctx, fnURL.String(),
input.StringSlice(flagkey.FnTestHeader),
method,
input.String(flagkey.FnTestBody))
+7 -14
View File
@@ -22,7 +22,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"github.com/pkg/errors"
@@ -30,6 +29,7 @@ import (
fv1 "github.com/fission/fission/pkg/apis/core/v1"
"github.com/fission/fission/pkg/fission-cli/cliwrapper/cli"
"github.com/fission/fission/pkg/fission-cli/cmd"
"github.com/fission/fission/pkg/fission-cli/console"
flagkey "github.com/fission/fission/pkg/fission-cli/flag/key"
"github.com/fission/fission/pkg/fission-cli/util"
)
@@ -64,26 +64,19 @@ func (opts *CreateSubCommand) run(input cli.Input) error {
jsonValue, _ := json.Marshal(values)
// Portforward to the fission router
localRouterPort, err := util.SetupPortForward(input.Context(), opts.Client(), util.GetFissionNamespace(), "application=fission-router")
if err != nil {
return err
}
authURI, _ := os.LookupEnv("FISSION_AUTH_URI")
if input.IsSet(flagkey.TokAuthURI) {
authURI = input.String(flagkey.TokAuthURI)
}
if len(authURI) == 0 {
authURI = util.FISSION_AUTH_URI
}
relativeURL, _ := url.Parse(authURI)
serverURL, _ := url.Parse("http://127.0.0.1:" + localRouterPort)
authAuthenticatorUrl := serverURL.ResolveReference(relativeURL)
routerURL, err := util.GetRouterURL(input.Context(), opts.Client())
if err != nil {
return errors.Wrap(err, "error getting router URL")
}
authAuthenticatorUrl := routerURL.JoinPath(authURI)
console.Verbose(2, "Auth URI: %s", authAuthenticatorUrl.String())
resp, err := http.Post(authAuthenticatorUrl.String(), "application/json", bytes.NewBuffer(jsonValue))
if err != nil {
return err