From 2602152be5560da7f55caab13417b45e5a73ad0f Mon Sep 17 00:00:00 2001 From: "Han Verstraete (OpenFaaS Ltd)" Date: Mon, 17 Jun 2024 13:18:14 +0200 Subject: [PATCH] Fix default sdk client gateway url Ensure the default sdk client reads the provider url from the stack file if the '--yaml/-f' flag is used. Signed-off-by: Han Verstraete (OpenFaaS Ltd) --- commands/general.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/commands/general.go b/commands/general.go index bee78c68..16cea8a5 100644 --- a/commands/general.go +++ b/commands/general.go @@ -10,6 +10,7 @@ import ( "time" "github.com/openfaas/faas-cli/config" + "github.com/openfaas/faas-cli/stack" "github.com/openfaas/go-sdk" ) @@ -44,7 +45,11 @@ func GetDefaultCLITransport(tlsInsecure bool, timeout *time.Duration) *http.Tran } func GetDefaultSDKClient() (*sdk.Client, error) { - gatewayAddress := getGatewayURL(gateway, defaultGateway, "", os.Getenv(openFaaSURLEnvironment)) + gatewayAddress, err := getGatewayAddress() + if err != nil { + return nil, err + } + gatewayURL, err := url.Parse(gatewayAddress) if err != nil { return nil, err @@ -102,6 +107,22 @@ func GetDefaultSDKClient() (*sdk.Client, error) { ), nil } +func getGatewayAddress() (string, error) { + var yamlUrl string + if len(yamlFile) > 0 { + parsedServices, err := stack.ParseYAMLFile(yamlFile, regex, filter, envsubst) + if err != nil { + return "", err + } + + if parsedServices != nil { + yamlUrl = parsedServices.Provider.GatewayURL + } + } + + return getGatewayURL(gateway, defaultGateway, yamlUrl, os.Getenv(openFaaSURLEnvironment)), nil +} + type StaticTokenAuth struct { token string }