Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: ignore extra fields in yaml #107

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func readSlices(release *Release, baseDir, dirName string) error {

type yamlRelease struct {
Format string `yaml:"format"`
Archives map[string]yamlArchive `yaml:"archives`
Archives map[string]yamlArchive `yaml:"archives"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed.

Keyrings map[string]string `yaml:"public-keys"`
}

Expand Down Expand Up @@ -406,7 +406,7 @@ func parseRelease(baseDir, filePath string, data []byte) (*Release, error) {

yamlVar := yamlRelease{}
dec := yaml.NewDecoder(bytes.NewBuffer(data))
dec.KnownFields(true)
dec.KnownFields(false)
err := dec.Decode(&yamlVar)
if err != nil {
return nil, fmt.Errorf("%s: cannot parse release definition: %v", fileName, err)
Expand Down Expand Up @@ -479,7 +479,7 @@ func parsePackage(baseDir, pkgName, pkgPath string, data []byte) (*Package, erro

yamlPkg := yamlPackage{}
dec := yaml.NewDecoder(bytes.NewBuffer(data))
dec.KnownFields(true)
dec.KnownFields(false)
err := dec.Decode(&yamlPkg)
if err != nil {
return nil, fmt.Errorf("cannot parse package %q slice definitions: %v", pkgName, err)
Expand Down
51 changes: 51 additions & 0 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,57 @@ var setupTests = []setupTest{{
`,
},
relerror: `chisel.yaml: cannot parse keyring "ubuntu-master": openpgp: invalid argument: no armored data found`,
}, {
summary: "Extra fields in YAML are ignored (necessary for forward compatibility)",
input: map[string]string{
"chisel.yaml": `
format: chisel-v1
archives:
ubuntu:
version: 22.04
components: [main, other]
suites: [jammy, jammy-security]
madeUpKey1: whatever
madeUpKey2: whatever
`,
"slices/mydir/mypkg.yaml": `
package: mypkg
madeUpKey3: whatever
slices:
myslice:
madeUpKey4: whatever
contents:
/path: {madeUpKey5: whatever}
`,
},
release: &setup.Release{
DefaultArchive: "ubuntu",

Archives: map[string]*setup.Archive{
"ubuntu": {
Name: "ubuntu",
Version: "22.04",
Suites: []string{"jammy", "jammy-security"},
Components: []string{"main", "other"},
},
},
Packages: map[string]*setup.Package{
"mypkg": {
Archive: "ubuntu",
Name: "mypkg",
Path: "slices/mydir/mypkg.yaml",
Slices: map[string]*setup.Slice{
"myslice": {
Package: "mypkg",
Name: "myslice",
Contents: map[string]setup.PathInfo{
"/path": {Kind: "copy"},
},
},
},
},
},
},
}}

const defaultChiselYaml = `
Expand Down
Loading