Make strict mode a param (#1054)

So, a wrapping config (like cloud) can skip the strict mode check.
This commit is contained in:
Raja Subramanian
2022-09-29 13:07:32 +05:30
committed by GitHub
parent c93df27329
commit 33f5dbc501
7 changed files with 13 additions and 13 deletions
+2 -2
View File
@@ -205,7 +205,7 @@ type IngressConfig struct {
RTMPBaseURL string `yaml:"rtmp_base_url"`
}
func NewConfig(confString string, c *cli.Context) (*Config, error) {
func NewConfig(confString string, strictMode bool, c *cli.Context) (*Config, error) {
// start with defaults
conf := &Config{
Port: 7880,
@@ -266,7 +266,7 @@ func NewConfig(confString string, c *cli.Context) (*Config, error) {
}
if confString != "" {
decoder := yaml.NewDecoder(strings.NewReader(confString))
decoder.KnownFields(true)
decoder.KnownFields(strictMode)
if err := decoder.Decode(conf); err != nil {
return nil, fmt.Errorf("could not parse config: %v", err)
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
)
func TestConfig_UnmarshalKeys(t *testing.T) {
conf, err := NewConfig("", nil)
conf, err := NewConfig("", true, nil)
require.NoError(t, err)
require.NoError(t, conf.unmarshalKeys("key1: secret1"))
@@ -17,7 +17,7 @@ func TestConfig_UnmarshalKeys(t *testing.T) {
func TestConfig_DefaultsKept(t *testing.T) {
const content = `room:
empty_timeout: 10`
conf, err := NewConfig(content, nil)
conf, err := NewConfig(content, true, nil)
require.NoError(t, err)
require.Equal(t, true, conf.Room.AutoCreate)
require.Equal(t, uint32(10), conf.Room.EmptyTimeout)
@@ -27,6 +27,6 @@ func TestConfig_UnknownKeys(t *testing.T) {
const content = `unknown: 10
room:
empty_timeout: 10`
_, err := NewConfig(content, nil)
_, err := NewConfig(content, true, nil)
require.Error(t, err)
}