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

When validating buildpack.toml, don't warn for keys that are actually defined #2161

Merged
merged 2 commits into from
May 20, 2024
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
11 changes: 9 additions & 2 deletions pkg/buildpack/buildpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
return nil, err
}
if len(undecodedKeys) > 0 {
logger.Warnf("Ignoring unexpected key(s) in descriptor for buildpack %s: %s", descriptor.EscapedID(), strings.Join(undecodedKeys, ","))
logger.Warnf("Ignoring unexpected key(s) in descriptor for buildpack %s: %s", descriptor.EscapedID(), strings.Join(undecodedKeys, ", "))
}
if err := detectPlatformSpecificValues(&descriptor, blob); err != nil {
return nil, err
Expand All @@ -101,7 +101,7 @@
return nil, err
}
if len(undecodedKeys) > 0 {
logger.Warnf("Ignoring unexpected key(s) in descriptor for extension %s: %s", descriptor.EscapedID(), strings.Join(undecodedKeys, ","))
logger.Warnf("Ignoring unexpected key(s) in descriptor for extension %s: %s", descriptor.EscapedID(), strings.Join(undecodedKeys, ", "))

Check warning on line 104 in pkg/buildpack/buildpack.go

View check run for this annotation

Codecov / codecov/patch

pkg/buildpack/buildpack.go#L104

Added line #L104 was not covered by tests
}
if err := validateExtensionDescriptor(descriptor); err != nil {
return nil, err
Expand Down Expand Up @@ -130,6 +130,13 @@

undecoded := md.Undecoded()
for _, k := range undecoded {
// FIXME: we should ideally update dist.ModuleInfo to expect sbom-formats, but this breaks other tests;
// it isn't possible to make [metadata] a decoded key because its type is undefined in the buildpack spec.
if k.String() == "metadata" || strings.HasPrefix(k.String(), "metadata.") ||
k.String() == "buildpack.sbom-formats" {
// buildpack.toml & extension.toml can contain [metadata] which is arbitrary
continue
}
undecodedKeys = append(undecodedKeys, k.String())
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/buildpack/buildpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ api = "0.3"
id = "bp.one"
version = "1.2.3"
homepage = "http://geocities.com/cool-bp"
sbom-formats = ["this should not warn"]

[[targets]]
os = "some-os"
Expand All @@ -524,12 +525,15 @@ version = "some-distro-version"
[[targets.distros]]
name = "some-distro-name"
versions = ["some-distro-version"]

[metadata]
this-key = "is totally allowed and should not warn"
`))
return tarBuilder.Reader(archive.DefaultTarWriterFactory())
},
}, archive.DefaultTarWriterFactory(), logger)
h.AssertNil(t, err)
h.AssertContains(t, outBuf.String(), "Warning: Ignoring unexpected key(s) in descriptor for buildpack bp.one: targets.distributions,targets.distributions.name,targets.distributions.version,targets.distros.versions")
h.AssertContains(t, outBuf.String(), "Warning: Ignoring unexpected key(s) in descriptor for buildpack bp.one: targets.distributions, targets.distributions.name, targets.distributions.version, targets.distros.versions")
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/example_fetcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,6 @@ func (f *fetcher) Fetch(_ context.Context, imageName string, _ image.FetchOption
return nil, errors.New("not implemented")
}

func (f *fetcher) CheckReadAccess(_ string, _ FetchOptions) bool {
func (f *fetcher) CheckReadAccess(_ string, _ image.FetchOptions) bool {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure how this happened...

return true
}
Loading