Skip to content

Commit f7a824b

Browse files
Update to yaml.v3
Also, modify `empty_config_yml` because with yaml.v3 reading empty file causes Decode to return EOF error, as described in go-yaml/yaml#805 issue. Signed-off-by: Mikel Olasagasti Uranga <[email protected]>
1 parent 2f4150c commit f7a824b

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/prometheus/common v0.44.0
1010
golang.org/x/crypto v0.10.0
1111
golang.org/x/sync v0.3.0
12-
gopkg.in/yaml.v2 v2.4.0
12+
gopkg.in/yaml.v3 v3.0.1
1313
)
1414

1515
require (
@@ -32,4 +32,5 @@ require (
3232
golang.org/x/text v0.10.0 // indirect
3333
google.golang.org/appengine v1.6.7 // indirect
3434
google.golang.org/protobuf v1.30.0 // indirect
35+
gopkg.in/yaml.v2 v2.4.0 // indirect
3536
)

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,4 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
8080
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
8181
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
8282
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
83+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

web/tls_config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
package web
1515

1616
import (
17+
"bytes"
18+
"io"
1719
"crypto/tls"
1820
"crypto/x509"
1921
"errors"
@@ -28,7 +30,7 @@ import (
2830
"github.com/go-kit/log/level"
2931
config_util "github.com/prometheus/common/config"
3032
"golang.org/x/sync/errgroup"
31-
"gopkg.in/yaml.v2"
33+
"gopkg.in/yaml.v3"
3234
)
3335

3436
var (
@@ -119,8 +121,10 @@ func getConfig(configPath string) (*Config, error) {
119121
},
120122
HTTPConfig: HTTPConfig{HTTP2: true},
121123
}
122-
err = yaml.UnmarshalStrict(content, c)
123-
if err == nil {
124+
decoder := yaml.NewDecoder(bytes.NewReader(content))
125+
decoder.KnownFields(true)
126+
err = decoder.Decode(c)
127+
if err == nil && !errors.Is(err, io.EOF) {
124128
err = validateHeaderConfig(c.HTTPConfig.Header)
125129
}
126130
c.TLSConfig.SetDirectory(filepath.Dir(configPath))

web/tls_config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var (
4444
testlogger = &testLogger{}
4545

4646
ErrorMap = map[string]*regexp.Regexp{
47+
"End of file": regexp.MustCompile(`EOF`),
4748
"HTTP Response to HTTPS": regexp.MustCompile(`server gave HTTP response to HTTPS client`),
4849
"No such file": regexp.MustCompile(`no such file`),
4950
"Invalid argument": regexp.MustCompile(`invalid argument`),
@@ -112,7 +113,7 @@ func TestYAMLFiles(t *testing.T) {
112113
{
113114
Name: `empty config yml`,
114115
YAMLConfigPath: "testdata/web_config_empty.yml",
115-
ExpectedError: nil,
116+
ExpectedError: ErrorMap["End of file"],
116117
},
117118
{
118119
Name: `invalid config yml (invalid structure)`,

0 commit comments

Comments
 (0)