File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Expand file tree Collapse file tree 3 files changed +11
-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.58.0
10
10
golang.org/x/crypto v0.26.0
11
11
golang.org/x/sync v0.8.0
12
- gopkg.in/yaml.v2 v2.4.0
12
+ gopkg.in/yaml.v3 v3.0.1
13
13
)
14
14
15
15
require (
@@ -30,4 +30,5 @@ require (
30
30
golang.org/x/sys v0.23.0 // indirect
31
31
golang.org/x/text v0.17.0 // indirect
32
32
google.golang.org/protobuf v1.34.2 // indirect
33
+ gopkg.in/yaml.v2 v2.4.0 // indirect
33
34
)
Original file line number Diff line number Diff line change 14
14
package web
15
15
16
16
import (
17
+ "bytes"
17
18
"crypto/tls"
18
19
"crypto/x509"
19
20
"errors"
20
21
"fmt"
22
+ "io"
21
23
"log/slog"
22
24
"net"
23
25
"net/http"
@@ -31,7 +33,7 @@ import (
31
33
"github.com/mdlayher/vsock"
32
34
config_util "github.com/prometheus/common/config"
33
35
"golang.org/x/sync/errgroup"
34
- "gopkg.in/yaml.v2 "
36
+ "gopkg.in/yaml.v3 "
35
37
)
36
38
37
39
var (
@@ -122,8 +124,10 @@ func getConfig(configPath string) (*Config, error) {
122
124
},
123
125
HTTPConfig : HTTPConfig {HTTP2 : true },
124
126
}
125
- err = yaml .UnmarshalStrict (content , c )
126
- if err == nil {
127
+ decoder := yaml .NewDecoder (bytes .NewReader (content ))
128
+ decoder .KnownFields (true )
129
+ err = decoder .Decode (c )
130
+ if err == nil && ! errors .Is (err , io .EOF ) {
127
131
err = validateHeaderConfig (c .HTTPConfig .Header )
128
132
}
129
133
c .TLSConfig .SetDirectory (filepath .Dir (configPath ))
Original file line number Diff line number Diff line change 45
45
testlogger = slog .New (slog .NewTextHandler (os .Stdout , nil ))
46
46
47
47
ErrorMap = map [string ]* regexp.Regexp {
48
+ "End of file" : regexp .MustCompile (`EOF` ),
48
49
"HTTP Response to HTTPS" : regexp .MustCompile (`server gave HTTP response to HTTPS client` ),
49
50
"No such file" : regexp .MustCompile (`no such file` ),
50
51
"Invalid argument" : regexp .MustCompile (`invalid argument` ),
@@ -110,7 +111,7 @@ func TestYAMLFiles(t *testing.T) {
110
111
{
111
112
Name : `empty config yml` ,
112
113
YAMLConfigPath : "testdata/web_config_empty.yml" ,
113
- ExpectedError : nil ,
114
+ ExpectedError : ErrorMap [ "End of file" ] ,
114
115
},
115
116
{
116
117
Name : `invalid config yml (invalid structure)` ,
You can’t perform that action at this time.
0 commit comments