cli: fix regression with --address flag of hasura console command

GITHUB_PR_NUMBER: 8039
GITHUB_PR_URL: https://github.com/hasura/graphql-engine/pull/8039
closes https://github.com/hasura/graphql-engine/issues/8005

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/3381
Co-authored-by: Shoki Hata <37888628+sho-hata@users.noreply.github.com>
Co-authored-by: Aravind K P <8335904+scriptonist@users.noreply.github.com>
GitOrigin-RevId: 6ca7c091ebf7c240e97b65fbfc1713cccb5a5b82
This commit is contained in:
hasura-bot 2022-01-20 12:09:58 +05:30
parent 137b81c84f
commit f530b3ac6f
4 changed files with 32 additions and 4 deletions

View File

@ -36,6 +36,7 @@ count (
- cli: fix `metadata diff --type json | unified-json` behaving incorrectly and showing diff in YAML format.
- cli: fix regression in `migrate create` command (#7971)
- cli: stop using `/healthz` endpoint to determine server health
- cli: fix regression with `--address` flag of `hasura console` command (#8005)
## v2.1.1

View File

@ -1,6 +1,8 @@
package commands
import (
"fmt"
"net/url"
"os"
"github.com/hasura/graphql-engine/cli/v2/internal/scripts"
@ -16,6 +18,7 @@ import (
// NewConsoleCmd returns the console command
func NewConsoleCmd(ec *cli.ExecutionContext) *cobra.Command {
var apiHost string
v := viper.New()
opts := &ConsoleOptions{
EC: ec,
@ -51,13 +54,25 @@ func NewConsoleCmd(ec *cli.ExecutionContext) *cobra.Command {
return scripts.CheckIfUpdateToConfigV3IsRequired(ec)
},
RunE: func(cmd *cobra.Command, args []string) error {
if cmd.Flags().Changed("api-host") {
var err error
opts.APIHost, err = url.ParseRequestURI(apiHost)
if err != nil {
return fmt.Errorf("expected a valid url for --api-host, parsing error: %w", err)
}
} else {
opts.APIHost = &url.URL{
Scheme: "http",
Host: opts.Address,
}
}
return opts.Run()
},
}
f := consoleCmd.Flags()
f.StringVar(&opts.APIPort, "api-port", "9693", "port for serving migrate api")
f.StringVar(&opts.APIHost, "api-host", "http://localhost", "(PREVIEW: usage may change in future) host serving migrate api")
f.StringVar(&apiHost, "api-host", "http://localhost", "(PREVIEW: usage may change in future) host serving migrate api")
f.StringVar(&opts.ConsolePort, "console-port", "9695", "port for serving console")
f.StringVar(&opts.Address, "address", "localhost", "address to serve console and migration API from")
f.BoolVar(&opts.DontOpenBrowser, "no-browser", false, "do not automatically open console in browser")
@ -88,7 +103,7 @@ type ConsoleOptions struct {
EC *cli.ExecutionContext
APIPort string
APIHost string
APIHost *url.URL
ConsolePort string
Address string
@ -107,7 +122,7 @@ func (o *ConsoleOptions) Run() error {
return errors.New("cannot validate version, object is nil")
}
apiServer, err := console.NewAPIServer(o.Address, o.APIPort, o.EC)
apiServer, err := console.NewAPIServer(o.APIHost.Host, o.APIPort, o.EC)
if err != nil {
return err
}
@ -126,7 +141,7 @@ func (o *ConsoleOptions) Run() error {
}
consoleRouter, err := console.BuildConsoleRouter(templateProvider, consoleTemplateVersion, o.StaticDir, gin.H{
"apiHost": o.APIHost,
"apiHost": o.APIHost.String(),
"apiPort": o.APIPort,
"cliVersion": o.EC.Version.GetCLIVersion(),
"serverVersion": o.EC.Version.GetServerVersion(),

View File

@ -3,6 +3,7 @@ package v2
import (
"fmt"
"net"
"net/url"
"os"
"sync"
"testing"
@ -15,9 +16,14 @@ import (
)
func TestConsoleCmd(t *testing.T, ec *cli.ExecutionContext) {
apiHost := &url.URL{
Host: "localhost",
Scheme: "http",
}
opts := &commands.ConsoleOptions{
EC: ec,
APIPort: "9693",
APIHost: apiHost,
ConsolePort: "9695",
Address: "localhost",
DontOpenBrowser: true,

View File

@ -3,6 +3,7 @@ package v3
import (
"fmt"
"net"
"net/url"
"os"
"sync"
"testing"
@ -15,9 +16,14 @@ import (
)
func TestConsoleCmd(t *testing.T, ec *cli.ExecutionContext) {
apiHost := &url.URL{
Host: "localhost",
Scheme: "http",
}
opts := &commands.ConsoleOptions{
EC: ec,
APIPort: "9693",
APIHost: apiHost,
ConsolePort: "9695",
Address: "localhost",
DontOpenBrowser: true,