Skip to content

Commit

Permalink
Use strict unmarshalling for YAML configs
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed Sep 4, 2023
1 parent 1339ea7 commit 5597ea1
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func rootCmd(o *root.Options) error {
logrus.WithError(err).Fatal("Could not read --config-path file")
}

if err := yaml.Unmarshal(raw, &cfg); err != nil {
if err := yaml.UnmarshalStrict(raw, &cfg); err != nil {
logrus.WithError(err).Fatal("Failed to load configuration")
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/restrictions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func unmarshalPathToRestrictionsConfig(path string) (*Config, error) {
return nil, fmt.Errorf("read restrictions config: %v", err)
}
var restrictionsCfg Config
if err := yaml.Unmarshal(buf, &restrictionsCfg); err != nil {
if err := yaml.UnmarshalStrict(buf, &restrictionsCfg); err != nil {
return nil, fmt.Errorf("unmarshal restrictions config: %v", err)
}
return &restrictionsCfg, nil
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestMain(m *testing.M) {
os.Exit(1)
}
if err := yaml.Unmarshal(raw, &cfg); err != nil {
if err := yaml.UnmarshalStrict(raw, &cfg); err != nil {
fmt.Printf("cannot unmarshal generated config.yaml from %s: %v\n", *configPath, err)
os.Exit(1)
}
Expand All @@ -68,7 +68,7 @@ func readInto(path string, i interface{}) error {
if err != nil {
return fmt.Errorf("read: %v", err)
}
if err := yaml.Unmarshal(buf, i); err != nil {
if err := yaml.UnmarshalStrict(buf, i); err != nil {
return fmt.Errorf("unmarshal: %v", err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/helpers/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func UnmarshalPathToOrgConfig(path string) (*org.Config, error) {
return nil, fmt.Errorf("read: %v", err)
}
var cfg org.Config
if err := yaml.Unmarshal(buf, &cfg); err != nil {
if err := yaml.UnmarshalStrict(buf, &cfg); err != nil {
return nil, fmt.Errorf("unmarshal: %v", err)
}
return &cfg, nil
Expand Down
2 changes: 1 addition & 1 deletion options/merge/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func unmarshal(path string) (*org.Config, error) {
return nil, fmt.Errorf("read: %v", err)
}
var cfg org.Config
if err := yaml.Unmarshal(buf, &cfg); err != nil {
if err := yaml.UnmarshalStrict(buf, &cfg); err != nil {
return nil, fmt.Errorf("unmarshal: %v", err)
}
return &cfg, nil
Expand Down

0 comments on commit 5597ea1

Please sign in to comment.