From 2280487ec010799c66e5354a7aeaca42920b8430 Mon Sep 17 00:00:00 2001 From: Toan Nguyen Date: Mon, 2 Dec 2024 12:42:59 +0700 Subject: [PATCH] fix(cli): wrong subgraph directory discovery and remove confirmation (#36) --- connector/connector_test.go | 1 - ndc-http-schema/command/update.go | 11 ++------- ndc-http-schema/command/update_test.go | 2 -- .../connector/{ => http}/config.yaml | 2 +- .../connector/{ => http}/schema.yaml | 0 .../connector/{ => http}/config.yaml | 2 +- .../connector/{ => http}/connector.yaml | 0 .../connector/{ => http}/schema.yaml | 2 +- .../connector/{ => http}/schema2.yaml | 2 +- .../testdata/validation/expected.tpl | 4 ++-- ndc-http-schema/configuration/validate.go | 23 +------------------ .../configuration/validate_test.go | 2 +- 12 files changed, 10 insertions(+), 41 deletions(-) rename ndc-http-schema/configuration/testdata/server_empty/connector/{ => http}/config.yaml (68%) rename ndc-http-schema/configuration/testdata/server_empty/connector/{ => http}/schema.yaml (100%) rename ndc-http-schema/configuration/testdata/validation/connector/{ => http}/config.yaml (72%) rename ndc-http-schema/configuration/testdata/validation/connector/{ => http}/connector.yaml (100%) rename ndc-http-schema/configuration/testdata/validation/connector/{ => http}/schema.yaml (99%) rename ndc-http-schema/configuration/testdata/validation/connector/{ => http}/schema2.yaml (96%) diff --git a/connector/connector_test.go b/connector/connector_test.go index 08fa13f..f27bff3 100644 --- a/connector/connector_test.go +++ b/connector/connector_test.go @@ -1438,7 +1438,6 @@ func TestConnectorTLS(t *testing.T) { }) }() - time.Sleep(2 * time.Second) assert.Equal(t, 1, mockServer.Count()) assert.Equal(t, 1, mockServer1.Count()) } diff --git a/ndc-http-schema/command/update.go b/ndc-http-schema/command/update.go index 75be4db..8d145af 100644 --- a/ndc-http-schema/command/update.go +++ b/ndc-http-schema/command/update.go @@ -11,8 +11,7 @@ import ( // UpdateCommandArguments represent input arguments of the `update` command type UpdateCommandArguments struct { - Dir string `default:"." env:"HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" help:"The directory where the config.yaml file is present" short:"d"` - Yes bool `default:"false" help:"Skip the continue confirmation prompt" short:"y"` + Dir string `default:"." env:"HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH" help:"The directory where the config.yaml file is present" short:"d"` } // UpdateConfiguration updates the configuration for the HTTP connector @@ -37,13 +36,7 @@ func UpdateConfiguration(args *UpdateCommandArguments, logger *slog.Logger, noCo return errors.New("Detected configuration errors. Update your configuration and try again.") } - if !args.Yes { - if err := validStatus.PrintWarningConfirmation(); err != nil { - return err - } - } - - logger.Info("updated successfully", slog.Duration("exec_time", time.Since(start))) + logger.Info("Updated successfully", slog.Duration("exec_time", time.Since(start))) return nil } diff --git a/ndc-http-schema/command/update_test.go b/ndc-http-schema/command/update_test.go index 46fddda..5a13c81 100644 --- a/ndc-http-schema/command/update_test.go +++ b/ndc-http-schema/command/update_test.go @@ -23,7 +23,6 @@ func TestUpdateCommand(t *testing.T) { { Argument: UpdateCommandArguments{ Dir: "testdata/patch", - Yes: true, }, Expected: "testdata/patch/expected.json", }, @@ -31,7 +30,6 @@ func TestUpdateCommand(t *testing.T) { { Argument: UpdateCommandArguments{ Dir: "testdata/auth", - Yes: true, }, Expected: "testdata/auth/expected.json", }, diff --git a/ndc-http-schema/configuration/testdata/server_empty/connector/config.yaml b/ndc-http-schema/configuration/testdata/server_empty/connector/http/config.yaml similarity index 68% rename from ndc-http-schema/configuration/testdata/server_empty/connector/config.yaml rename to ndc-http-schema/configuration/testdata/server_empty/connector/http/config.yaml index 3564c08..fe73cd2 100644 --- a/ndc-http-schema/configuration/testdata/server_empty/connector/config.yaml +++ b/ndc-http-schema/configuration/testdata/server_empty/connector/http/config.yaml @@ -1,4 +1,4 @@ -# yaml-language-server: $schema=../../../../jsonschema/configuration.schema.json +# yaml-language-server: $schema=../../../../../jsonschema/configuration.schema.json strict: true forwardHeaders: enabled: false diff --git a/ndc-http-schema/configuration/testdata/server_empty/connector/schema.yaml b/ndc-http-schema/configuration/testdata/server_empty/connector/http/schema.yaml similarity index 100% rename from ndc-http-schema/configuration/testdata/server_empty/connector/schema.yaml rename to ndc-http-schema/configuration/testdata/server_empty/connector/http/schema.yaml diff --git a/ndc-http-schema/configuration/testdata/validation/connector/config.yaml b/ndc-http-schema/configuration/testdata/validation/connector/http/config.yaml similarity index 72% rename from ndc-http-schema/configuration/testdata/validation/connector/config.yaml rename to ndc-http-schema/configuration/testdata/validation/connector/http/config.yaml index 82013c4..9f66597 100644 --- a/ndc-http-schema/configuration/testdata/validation/connector/config.yaml +++ b/ndc-http-schema/configuration/testdata/validation/connector/http/config.yaml @@ -1,4 +1,4 @@ -# yaml-language-server: $schema=../../../../jsonschema/configuration.schema.json +# yaml-language-server: $schema=../../../../../jsonschema/configuration.schema.json strict: true forwardHeaders: enabled: false diff --git a/ndc-http-schema/configuration/testdata/validation/connector/connector.yaml b/ndc-http-schema/configuration/testdata/validation/connector/http/connector.yaml similarity index 100% rename from ndc-http-schema/configuration/testdata/validation/connector/connector.yaml rename to ndc-http-schema/configuration/testdata/validation/connector/http/connector.yaml diff --git a/ndc-http-schema/configuration/testdata/validation/connector/schema.yaml b/ndc-http-schema/configuration/testdata/validation/connector/http/schema.yaml similarity index 99% rename from ndc-http-schema/configuration/testdata/validation/connector/schema.yaml rename to ndc-http-schema/configuration/testdata/validation/connector/http/schema.yaml index 1409268..8c643b6 100644 --- a/ndc-http-schema/configuration/testdata/validation/connector/schema.yaml +++ b/ndc-http-schema/configuration/testdata/validation/connector/http/schema.yaml @@ -1,4 +1,4 @@ -# yaml-language-server: $schema=../../../../jsonschema/ndc-http-schema.schema.json +# yaml-language-server: $schema=../../../../../jsonschema/ndc-http-schema.schema.json settings: servers: - url: diff --git a/ndc-http-schema/configuration/testdata/validation/connector/schema2.yaml b/ndc-http-schema/configuration/testdata/validation/connector/http/schema2.yaml similarity index 96% rename from ndc-http-schema/configuration/testdata/validation/connector/schema2.yaml rename to ndc-http-schema/configuration/testdata/validation/connector/http/schema2.yaml index 9be5c12..c07d494 100644 --- a/ndc-http-schema/configuration/testdata/validation/connector/schema2.yaml +++ b/ndc-http-schema/configuration/testdata/validation/connector/http/schema2.yaml @@ -1,4 +1,4 @@ -# yaml-language-server: $schema=../../../../jsonschema/ndc-http-schema.schema.json +# yaml-language-server: $schema=../../../../../jsonschema/ndc-http-schema.schema.json settings: servers: - url: diff --git a/ndc-http-schema/configuration/testdata/validation/expected.tpl b/ndc-http-schema/configuration/testdata/validation/expected.tpl index eb3ef73..4cd2270 100644 --- a/ndc-http-schema/configuration/testdata/validation/expected.tpl +++ b/ndc-http-schema/configuration/testdata/validation/expected.tpl @@ -6,7 +6,7 @@ WARNING: Environment Variables: Make sure that the following environment variables were added to your subgraph configuration: - ``` testdata/validation/connector/docker.yaml + ``` testdata/validation/connector/http/docker.yaml services: app_myapi: environment: @@ -28,7 +28,7 @@ Environment Variables: ``` - ``` testdata/validation/connector/connector.yaml + ``` testdata/validation/connector/http/connector.yaml envMapping: CAT_PET_HEADER fromEnv: APP_MYAPI_CAT_PET_HEADER diff --git a/ndc-http-schema/configuration/validate.go b/ndc-http-schema/configuration/validate.go index 1e351a1..69390c9 100644 --- a/ndc-http-schema/configuration/validate.go +++ b/ndc-http-schema/configuration/validate.go @@ -2,13 +2,11 @@ package configuration import ( "bytes" - "errors" "fmt" "io" "log/slog" "os" "path/filepath" - "slices" "strings" "text/template" @@ -398,7 +396,7 @@ func (cv *ConfigValidator) findSubgraphName() string { return "" } - connectorPath := filepath.Join(cv.contextPath, "..", "subgraph.yaml") + connectorPath := filepath.Join(cv.contextPath, "..", "..", "subgraph.yaml") rawBytes, err := os.ReadFile(connectorPath) if err != nil { cv.logger.Error(fmt.Sprintf("failed to read the subgraph manifest: %s", err)) @@ -442,22 +440,3 @@ func (cv *ConfigValidator) addError(namespace string, value string) { cv.errors[namespace] = append(cv.errors[namespace], value) } } - -// PrintWarningConfirmation prints the warning confirmation prompt. -func (cv *ConfigValidator) PrintWarningConfirmation() error { - fmt.Fprint(os.Stderr, "\nDetected configuration warnings. Check your configuration and continue [Y/n]: ") - var shouldContinue string - _, err := fmt.Scan(&shouldContinue) - if err != nil { - return err - } - - if !slices.Contains([]string{"y", "yes"}, strings.ToLower(shouldContinue)) { - err := errors.New("stop the introspection.") - fmt.Fprint(os.Stderr, err.Error()+"\n") - - return err - } - - return nil -} diff --git a/ndc-http-schema/configuration/validate_test.go b/ndc-http-schema/configuration/validate_test.go index 3900257..d433868 100644 --- a/ndc-http-schema/configuration/validate_test.go +++ b/ndc-http-schema/configuration/validate_test.go @@ -31,7 +31,7 @@ func TestConfigValidator(t *testing.T) { for _, tc := range testCases { t.Run(tc.Dir, func(t *testing.T) { - connectorDir := filepath.Join(tc.Dir, "connector") + connectorDir := filepath.Join(tc.Dir, "connector", "http") expectedBytes, err := os.ReadFile(filepath.Join(tc.Dir, "expected.tpl")) config, schemas, err := UpdateHTTPConfiguration(connectorDir, slog.Default()) if tc.ErrorMsg != "" {