From 549be9f9a60e41fd0fadf634b984158a31d35f57 Mon Sep 17 00:00:00 2001 From: Tobias Baube Date: Mon, 14 Nov 2022 10:01:07 +0100 Subject: [PATCH] Version Bump gopkg.in/yaml.v2 v2.4.0 --> gopkg.in/yaml.v3 v3.0.1 --- config/http_config.go | 3 ++- config/http_config_test.go | 12 +++++++++--- config/tls_config_test.go | 9 +++++++-- go.mod | 2 +- go.sum | 1 - promlog/log_test.go | 2 +- sigv4/go.mod | 2 +- sigv4/go.sum | 2 ++ 8 files changed, 23 insertions(+), 10 deletions(-) diff --git a/config/http_config.go b/config/http_config.go index 69c0b671..79a87c12 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -21,6 +21,7 @@ import ( "crypto/x509" "encoding/json" "fmt" + "io/ioutil" "net" "net/http" "net/url" @@ -33,7 +34,7 @@ import ( "golang.org/x/net/http2" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) var ( diff --git a/config/http_config_test.go b/config/http_config_test.go index 036fd2dc..3787faca 100644 --- a/config/http_config_test.go +++ b/config/http_config_test.go @@ -14,6 +14,7 @@ package config import ( + "bytes" "context" "crypto/tls" "crypto/x509" @@ -21,6 +22,7 @@ import ( "errors" "fmt" "io" + "io/ioutil" "net" "net/http" "net/http/httptest" @@ -35,7 +37,7 @@ import ( "testing" "time" - yaml "gopkg.in/yaml.v2" + yaml "gopkg.in/yaml.v3" ) const ( @@ -1128,8 +1130,12 @@ func TestInvalidHTTPConfigs(t *testing.T) { // LoadHTTPConfig parses the YAML input s into a HTTPClientConfig. func LoadHTTPConfig(s string) (*HTTPClientConfig, error) { cfg := &HTTPClientConfig{} - err := yaml.UnmarshalStrict([]byte(s), cfg) - if err != nil { + + // In yaml.v3 UnmarschalStrict was removed + // https://github.com/go-yaml/yaml/issues/639#issuecomment-666935833 + decoder := yaml.NewDecoder(bytes.NewReader([]byte(s))) + decoder.KnownFields(true) + if err := decoder.Decode(&cfg); err != nil && err != io.EOF { return nil, err } return cfg, nil diff --git a/config/tls_config_test.go b/config/tls_config_test.go index 8799d7eb..f86200ab 100644 --- a/config/tls_config_test.go +++ b/config/tls_config_test.go @@ -17,6 +17,7 @@ import ( "bytes" "crypto/tls" "fmt" + "io" "os" "path/filepath" "reflect" @@ -24,7 +25,7 @@ import ( "encoding/json" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // LoadTLSConfig parses the given file into a tls.Config. @@ -36,7 +37,11 @@ func LoadTLSConfig(filename string) (*tls.Config, error) { cfg := TLSConfig{} switch filepath.Ext(filename) { case ".yml": - if err = yaml.UnmarshalStrict(content, &cfg); err != nil { + // In yaml.v3 UnmarschalStrict was removed + // https://github.com/go-yaml/yaml/issues/639#issuecomment-666935833 + decoder := yaml.NewDecoder(bytes.NewReader(content)) + decoder.KnownFields(true) + if err := decoder.Decode(&cfg); err != nil && err != io.EOF { return nil, err } case ".json": diff --git a/go.mod b/go.mod index f3914717..aad62be2 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( golang.org/x/net v0.0.0-20220805013720-a33c5aa5df48 golang.org/x/oauth2 v0.0.0-20220722155238-128564f6959c gopkg.in/alecthomas/kingpin.v2 v2.2.6 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) require ( diff --git a/go.sum b/go.sum index 41413eae..d6775d52 100644 --- a/go.sum +++ b/go.sum @@ -745,7 +745,6 @@ gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/promlog/log_test.go b/promlog/log_test.go index 00567083..983e3fde 100644 --- a/promlog/log_test.go +++ b/promlog/log_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/go-kit/log/level" - "gopkg.in/yaml.v2" + "gopkg.in/yaml.v3" ) // Make sure creating and using a logger with an empty configuration doesn't diff --git a/sigv4/go.mod b/sigv4/go.mod index aa40b797..9a099b91 100644 --- a/sigv4/go.mod +++ b/sigv4/go.mod @@ -5,7 +5,7 @@ require ( github.com/prometheus/client_golang v1.12.1 github.com/prometheus/common v0.32.1 github.com/stretchr/testify v1.7.1 - gopkg.in/yaml.v2 v2.4.0 + gopkg.in/yaml.v3 v3.0.1 ) go 1.16 diff --git a/sigv4/go.sum b/sigv4/go.sum index d368112d..0ca42083 100644 --- a/sigv4/go.sum +++ b/sigv4/go.sum @@ -479,6 +479,8 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=