Skip to content

Commit

Permalink
Fix default sdk client gateway url
Browse files Browse the repository at this point in the history
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) <[email protected]>
  • Loading branch information
welteki authored and alexellis committed Jun 19, 2024
1 parent a2a42ee commit 2602152
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion commands/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/openfaas/faas-cli/config"
"github.com/openfaas/faas-cli/stack"
"github.com/openfaas/go-sdk"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 2602152

Please sign in to comment.