File tree Expand file tree Collapse file tree 4 files changed +12
-5
lines changed Expand file tree Collapse file tree 4 files changed +12
-5
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ require (
9
9
github.com/prometheus/common v0.44.0
10
10
golang.org/x/crypto v0.10.0
11
11
golang.org/x/sync v0.3.0
12
- gopkg.in/yaml.v2 v2.4.0
12
+ gopkg.in/yaml.v3 v3.0.1
13
13
)
14
14
15
15
require (
@@ -32,4 +32,5 @@ require (
32
32
golang.org/x/text v0.10.0 // indirect
33
33
google.golang.org/appengine v1.6.7 // indirect
34
34
google.golang.org/protobuf v1.30.0 // indirect
35
+ gopkg.in/yaml.v2 v2.4.0 // indirect
35
36
)
Original file line number Diff line number Diff line change @@ -80,3 +80,4 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
80
80
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY =
81
81
gopkg.in/yaml.v2 v2.4.0 /go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ =
82
82
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
83
+ gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
Original file line number Diff line number Diff line change 14
14
package web
15
15
16
16
import (
17
+ "bytes"
18
+ "io"
17
19
"crypto/tls"
18
20
"crypto/x509"
19
21
"errors"
@@ -28,7 +30,7 @@ import (
28
30
"github.com/go-kit/log/level"
29
31
config_util "github.com/prometheus/common/config"
30
32
"golang.org/x/sync/errgroup"
31
- "gopkg.in/yaml.v2 "
33
+ "gopkg.in/yaml.v3 "
32
34
)
33
35
34
36
var (
@@ -119,8 +121,10 @@ func getConfig(configPath string) (*Config, error) {
119
121
},
120
122
HTTPConfig : HTTPConfig {HTTP2 : true },
121
123
}
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 ) {
124
128
err = validateHeaderConfig (c .HTTPConfig .Header )
125
129
}
126
130
c .TLSConfig .SetDirectory (filepath .Dir (configPath ))
Original file line number Diff line number Diff line change 44
44
testlogger = & testLogger {}
45
45
46
46
ErrorMap = map [string ]* regexp.Regexp {
47
+ "End of file" : regexp .MustCompile (`EOF` ),
47
48
"HTTP Response to HTTPS" : regexp .MustCompile (`server gave HTTP response to HTTPS client` ),
48
49
"No such file" : regexp .MustCompile (`no such file` ),
49
50
"Invalid argument" : regexp .MustCompile (`invalid argument` ),
@@ -112,7 +113,7 @@ func TestYAMLFiles(t *testing.T) {
112
113
{
113
114
Name : `empty config yml` ,
114
115
YAMLConfigPath : "testdata/web_config_empty.yml" ,
115
- ExpectedError : nil ,
116
+ ExpectedError : ErrorMap [ "End of file" ] ,
116
117
},
117
118
{
118
119
Name : `invalid config yml (invalid structure)` ,
You can’t perform that action at this time.
0 commit comments