Skip to content

Commit

Permalink
disallow unknown config fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nxcc committed Jan 11, 2023
1 parent 3f20f64 commit f0191d6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ changelog:
exclude:
- "^docs:"
- "^test:"
archives:
- files:
- LICENSE*
- README*
- examples/**/*
8 changes: 5 additions & 3 deletions internal/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,15 @@ func loadConfig(file string) (string, cuegen.Config, error) {
if fileInfo.IsDir() {
file = filepath.Join(file, defaultCuegenFile)
}
data, err := os.ReadFile(file)
fh, err := os.Open(file)
if err != nil {
return "", cuegen.Config{}, err
}
config := cuegen.Config{}
if err := yaml.Unmarshal(data, &config); err != nil {
return "", cuegen.Config{}, fmt.Errorf("unmarshal config: %v", err)
decoder := yaml.NewDecoder(fh)
decoder.KnownFields(true)
if err := decoder.Decode(&config); err != nil {
return "", cuegen.Config{}, err
}
return file, config, nil
}
7 changes: 7 additions & 0 deletions tests/local/config-objectsPath.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,21 @@ stdout 'a: b'
exec cuegen chart/cuegen3.yaml
stdout 'c: d'

# config: no objectsPath
! exec cuegen chart/cuegen4.yaml
stderr 'loadconfig: EOF'

-- chart/cuegen1.yaml --
debug: false

-- chart/cuegen2.yaml --
objectsPath: objects

-- chart/cuegen3.yaml --
objectsPath: otherPath

-- chart/cuegen4.yaml --

-- chart/a.cue --
package kube

Expand Down

0 comments on commit f0191d6

Please sign in to comment.