From bcd6420db52097091d90909c4889ba8f1ea00338 Mon Sep 17 00:00:00 2001 From: Bruno Schaatsbergen Date: Thu, 31 Jul 2025 01:55:35 +0200 Subject: [PATCH] revert: "convert gopkg.in/yaml.v3 to goccy/go-yaml (#5579)" (#5683) Co-authored-by: PePe Amengual <2208324+jamengual@users.noreply.github.com> --- cmd/server_test.go | 2 +- go.mod | 3 +- go.sum | 2 -- server/core/config/parser_validator.go | 8 ++++-- server/core/config/parser_validator_test.go | 18 ++++-------- server/core/config/raw/policies_test.go | 2 +- server/core/config/raw/raw_test.go | 5 ++-- server/core/config/raw/repo_cfg_test.go | 29 ++++---------------- server/core/config/raw/step_test.go | 8 ++---- server/core/config/raw/workflow_step_test.go | 8 ++---- 10 files changed, 26 insertions(+), 59 deletions(-) diff --git a/cmd/server_test.go b/cmd/server_test.go index 273ac69b2..daef8709b 100644 --- a/cmd/server_test.go +++ b/cmd/server_test.go @@ -24,10 +24,10 @@ import ( "strings" "testing" - yaml "github.com/goccy/go-yaml" homedir "github.com/mitchellh/go-homedir" "github.com/spf13/cobra" "github.com/spf13/viper" + "gopkg.in/yaml.v3" "github.com/runatlantis/atlantis/server" "github.com/runatlantis/atlantis/server/events/vcs/testdata" diff --git a/go.mod b/go.mod index c573083de..c396ef383 100644 --- a/go.mod +++ b/go.mod @@ -14,7 +14,6 @@ require ( github.com/go-ozzo/ozzo-validation v3.6.0+incompatible github.com/go-playground/validator/v10 v10.26.0 github.com/go-test/deep v1.1.1 - github.com/goccy/go-yaml v1.17.1 github.com/gofri/go-github-ratelimit v1.1.1 github.com/golang-jwt/jwt/v5 v5.2.2 github.com/google/go-github/v71 v71.0.0 @@ -52,6 +51,7 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/term v0.31.0 golang.org/x/text v0.24.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( @@ -141,5 +141,4 @@ require ( golang.org/x/time v0.8.0 // indirect golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect google.golang.org/protobuf v1.36.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index d6306db60..e6138bf07 100644 --- a/go.sum +++ b/go.sum @@ -170,8 +170,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U= github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/go-viper/mapstructure/v2 v2.2.1 h1:ZAaOCxANMuZx5RCeg0mBdEZk7DZasvvZIxtHqx8aGss= github.com/go-viper/mapstructure/v2 v2.2.1/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM= -github.com/goccy/go-yaml v1.17.1 h1:LI34wktB2xEE3ONG/2Ar54+/HJVBriAGJ55PHls4YuY= -github.com/goccy/go-yaml v1.17.1/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA= github.com/gofri/go-github-ratelimit v1.1.1 h1:5TCOtFf45M2PjSYU17txqbiYBEzjOuK1+OhivbW69W0= github.com/gofri/go-github-ratelimit v1.1.1/go.mod h1:wGZlBbzHmIVjwDR3pZgKY7RBTV6gsQWxLVkpfwhcMJM= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= diff --git a/server/core/config/parser_validator.go b/server/core/config/parser_validator.go index b9a819091..0c12b7aeb 100644 --- a/server/core/config/parser_validator.go +++ b/server/core/config/parser_validator.go @@ -13,9 +13,9 @@ import ( validation "github.com/go-ozzo/ozzo-validation" shlex "github.com/google/shlex" - yaml "github.com/goccy/go-yaml" "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" + yaml "gopkg.in/yaml.v3" ) // ParserValidator parses and validates server-side repo config files and @@ -57,7 +57,8 @@ func (p *ParserValidator) ParseRepoCfg(absRepoDir string, globalCfg valid.Global func (p *ParserValidator) ParseRepoCfgData(repoCfgData []byte, globalCfg valid.GlobalCfg, repoID string, branch string) (valid.RepoCfg, error) { var rawConfig raw.RepoCfg - decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData), yaml.Strict()) + decoder := yaml.NewDecoder(bytes.NewReader(repoCfgData)) + decoder.KnownFields(true) err := decoder.Decode(&rawConfig) if err != nil && !errors.Is(err, io.EOF) { @@ -118,7 +119,8 @@ func (p *ParserValidator) ParseGlobalCfg(configFile string, defaultCfg valid.Glo var rawCfg raw.GlobalCfg - decoder := yaml.NewDecoder(bytes.NewReader(configData), yaml.Strict()) + decoder := yaml.NewDecoder(bytes.NewReader(configData)) + decoder.KnownFields(true) err = decoder.Decode(&rawCfg) if err != nil && !errors.Is(err, io.EOF) { diff --git a/server/core/config/parser_validator_test.go b/server/core/config/parser_validator_test.go index eef1503dc..abe6f9893 100644 --- a/server/core/config/parser_validator_test.go +++ b/server/core/config/parser_validator_test.go @@ -84,12 +84,12 @@ func TestParseCfgs_InvalidYAML(t *testing.T) { { "random characters", "slkjds", - "string was used where mapping is expected", + "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `slkjds` into", }, { "just a colon", ":", - "unexpected key name", + "yaml: did not find expected key", }, } @@ -670,12 +670,7 @@ projects: version: 3 projects: - unknown: value`, - expErr: `[4:3] unknown field "unknown" - 2 | version: 3 - 3 | projects: -> 4 | - unknown: value - ^ -`, + expErr: "yaml: unmarshal errors:\n line 4: field unknown not found in type raw.Project", }, { description: "referencing workflow that doesn't exist", @@ -1277,11 +1272,8 @@ func TestParseGlobalCfg(t *testing.T) { expErr: "file was empty", }, "invalid fields": { - input: "invalid: key", - expErr: `[1:1] unknown field "invalid" -> 1 | invalid: key - ^ -`, + input: "invalid: key", + expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.GlobalCfg", }, "no id specified": { input: `repos: diff --git a/server/core/config/raw/policies_test.go b/server/core/config/raw/policies_test.go index a04e50d4c..4f8f6a313 100644 --- a/server/core/config/raw/policies_test.go +++ b/server/core/config/raw/policies_test.go @@ -3,11 +3,11 @@ package raw_test import ( "testing" - yaml "github.com/goccy/go-yaml" "github.com/hashicorp/go-version" "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" . "github.com/runatlantis/atlantis/testing" + yaml "gopkg.in/yaml.v3" ) func TestPolicySetsConfig_YAMLMarshalling(t *testing.T) { diff --git a/server/core/config/raw/raw_test.go b/server/core/config/raw/raw_test.go index 88a16fe4c..0d8fdca9a 100644 --- a/server/core/config/raw/raw_test.go +++ b/server/core/config/raw/raw_test.go @@ -6,7 +6,7 @@ import ( "errors" - yaml "github.com/goccy/go-yaml" + "gopkg.in/yaml.v3" ) // Bool is a helper routine that allocates a new bool value @@ -23,7 +23,8 @@ func String(v string) *string { return &v } // Helper function to unmarshal from strings func unmarshalString(in string, out interface{}) error { - decoder := yaml.NewDecoder(strings.NewReader(in), yaml.Strict()) + decoder := yaml.NewDecoder(strings.NewReader(in)) + decoder.KnownFields(true) err := decoder.Decode(out) if errors.Is(err, io.EOF) { diff --git a/server/core/config/raw/repo_cfg_test.go b/server/core/config/raw/repo_cfg_test.go index 52d81203a..2c405da34 100644 --- a/server/core/config/raw/repo_cfg_test.go +++ b/server/core/config/raw/repo_cfg_test.go @@ -45,10 +45,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) { Projects: nil, Workflows: nil, }, - expErr: `[1:1] unknown field "invalid" -> 1 | invalid: key - ^ -`, + expErr: "yaml: unmarshal errors:\n line 1: field invalid not found in type raw.RepoCfg", }, { description: "version set to 2", @@ -94,11 +91,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) { Projects: nil, Workflows: nil, }, - expErr: `[2:6] mapping was used where sequence is expected - 1 | projects: -> 2 | key: value - ^ -`, + expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!map into []raw.Project", }, { description: "projects with a scalar", @@ -108,10 +101,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) { Projects: nil, Workflows: nil, }, - expErr: `[1:11] string was used where sequence is expected -> 1 | projects: value - ^ -`, + expErr: "yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `value` into []raw.Project", }, { description: "automerge not a boolean", @@ -121,11 +111,7 @@ func TestConfig_UnmarshalYAML(t *testing.T) { Projects: nil, Workflows: nil, }, - expErr: `[2:12] cannot unmarshal string into Go struct field RepoCfg.Automerge of type bool - 1 | version: 3 -> 2 | automerge: notabool - ^ -`, + expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool", }, { description: "parallel apply not a boolean", @@ -135,11 +121,8 @@ func TestConfig_UnmarshalYAML(t *testing.T) { Projects: nil, Workflows: nil, }, - expErr: `[2:17] cannot unmarshal string into Go struct field RepoCfg.ParallelApply of type bool - 1 | version: 3 -> 2 | parallel_apply: notabool - ^ -`}, + expErr: "yaml: unmarshal errors:\n line 2: cannot unmarshal !!str `notabool` into bool", + }, { description: "should use values if set", input: ` diff --git a/server/core/config/raw/step_test.go b/server/core/config/raw/step_test.go index e244c4da5..c7373ad14 100644 --- a/server/core/config/raw/step_test.go +++ b/server/core/config/raw/step_test.go @@ -3,10 +3,10 @@ package raw_test import ( "testing" - yaml "github.com/goccy/go-yaml" "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" . "github.com/runatlantis/atlantis/testing" + yaml "gopkg.in/yaml.v3" ) func TestStepConfig_YAMLMarshalling(t *testing.T) { @@ -148,11 +148,7 @@ key: value`, key: - value: another: map`, - expErr: `[3:2] sequence was used where mapping is expected - 2 | key: -> 3 | - value: - ^ - 4 | another: map`, + expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!seq into map[string]interface {}", }, } diff --git a/server/core/config/raw/workflow_step_test.go b/server/core/config/raw/workflow_step_test.go index 3d4c0c0c3..60b6f1552 100644 --- a/server/core/config/raw/workflow_step_test.go +++ b/server/core/config/raw/workflow_step_test.go @@ -3,10 +3,10 @@ package raw_test import ( "testing" - yaml "github.com/goccy/go-yaml" "github.com/runatlantis/atlantis/server/core/config/raw" "github.com/runatlantis/atlantis/server/core/config/valid" . "github.com/runatlantis/atlantis/testing" + yaml "gopkg.in/yaml.v3" ) func TestWorkflowHook_YAMLMarshalling(t *testing.T) { @@ -47,11 +47,7 @@ key: value`, key: value: another: map`, - expErr: `[3:8] cannot unmarshal map[string]interface {} into Go value of type string - 2 | key: -> 3 | value: - ^ - 4 | another: map`, + expErr: "yaml: unmarshal errors:\n line 3: cannot unmarshal !!map into string", }, }