Skip to content

Commit ee2bccc

Browse files
committed
Read the gateway from stack.yaml in logs
deploy, describe and list all resolve the gateway from the stack file before falling back to the default, but logs passed an empty string for the YAML gateway and so always fell back to http://127.0.0.1:8080. Against a remote gateway this meant logs quietly queried localhost and reported the result as "Unauthorized access, run faas-cli login", which reads as an expired token or a missing permission rather than a gateway mix-up. Passing -f stack.yaml did not help. Resolve the YAML gateway the same way describe does. Explicit --gateway and OPENFAAS_URL continue to take precedence. Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 873635d commit ee2bccc

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

commands/logs.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/openfaas/faas-provider/logs"
1717

1818
"github.com/openfaas/faas-cli/proxy"
19+
"github.com/openfaas/go-sdk/stack"
1920
"github.com/spf13/cobra"
2021
)
2122

@@ -92,7 +93,22 @@ func initLogCmdFlags(cmd *cobra.Command) {
9293

9394
func runLogs(cmd *cobra.Command, args []string) error {
9495

95-
gatewayAddress := getGatewayURL(gateway, defaultGateway, "", os.Getenv(openFaaSURLEnvironment))
96+
// Honour the gateway set in stack.yaml, as deploy, describe and list do,
97+
// otherwise this falls back to localhost and reports the resulting failure
98+
// as an authentication error against the wrong gateway.
99+
var yamlGateway string
100+
if len(yamlFile) > 0 {
101+
parsedServices, err := stack.ParseYAMLFile(yamlFile, regex, filter, envsubst)
102+
if err != nil {
103+
return err
104+
}
105+
106+
if parsedServices != nil {
107+
yamlGateway = parsedServices.Provider.GatewayURL
108+
}
109+
}
110+
111+
gatewayAddress := getGatewayURL(gateway, defaultGateway, yamlGateway, os.Getenv(openFaaSURLEnvironment))
96112
jsonLogs := jsonOutput || logFlagValues.logFormat == flags.JSONLogFormat
97113
if msg := checkTLSInsecure(gatewayAddress, tlsInsecure); len(msg) > 0 && !jsonLogs {
98114
fmt.Println(msg)

0 commit comments

Comments
 (0)