Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Add metadata to manifest & warn on unknown fields #528

Merged

Conversation

darkowlzz
Copy link
Collaborator

  • Use manifest buffer to create a map of TomlTree and find all the
    unknown fields in the tree. Raise warnings for unknown fields.
  • For "metadata" field, ensure it's of map type, else raise warning.

Fixes #506

manifest.go Outdated
}
}
if !isValidMetadata {
internal.Logf("WARNING: metadata should consist of key-value pairs")
Copy link
Member

Choose a reason for hiding this comment

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

We're probably going to end up wanting to reuse this func elsewhere, in places where it's not a good idea to log directly. So, instead of directly logging the issues, could we switch to a ([]error, error) return type, and record all the problems we detect as items in the first slice?

- Use manifest buffer to create a map of TomlTree and find all the
unknown fields in the tree. Raise warnings for unknown fields.
- For "metadata" field, ensure it's of map type, else raise warning.
@darkowlzz darkowlzz force-pushed the 506-add-metadata-warn-unknown-manifest-fields branch 2 times, most recently from 64abf1d to 90656bc Compare May 8, 2017 21:08
- Modifies ValidateManifest() to return []error, as a collection of all
the errors, instead of logging directly.
- Adds tests for ValidateManifest().
@darkowlzz darkowlzz force-pushed the 506-add-metadata-warn-unknown-manifest-fields branch from 90656bc to 8129217 Compare May 8, 2017 21:14
@darkowlzz
Copy link
Collaborator Author

  • Changed validateManifest() return type to ([]error, error).
  • Added tests for validateManifest().

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

just a bit more...

manifest_test.go Outdated
{
tomlString: `
[[dependencies]]
name = "github.com/foo/bar"
Copy link
Member

Choose a reason for hiding this comment

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

can we also validate that there aren't any extra fields within [[dependencies]] or [[overrides]] items?

@darkowlzz
Copy link
Collaborator Author

@sdboyer thanks to that extra bit, I found that the checks can be improved by just using type assertion. Once a property is TOML array of tables ([[some-name]]), TOML ensures that the content has to be map (key-value pair) :)

Added checks for invalid fields in [[dependencies]] or [[overrides]].

@darkowlzz darkowlzz force-pushed the 506-add-metadata-warn-unknown-manifest-fields branch 4 times, most recently from 1bd28e6 to 831aab0 Compare May 9, 2017 04:46
- Improves property validation by checking for TOML array of tables.
- Adds checks for invalid fields in dependencies and overrides.
@sdboyer
Copy link
Member

sdboyer commented May 9, 2017

@darkowlzz hmm - looking at the TOML spec a bit, and poking at the PR, I'm confused - array of tables isn't actually the same thing as just a plain table, because you can specify them multiple times. And we don't want that to be possible - there should be exactly one allowed [metadata] section per area - whether that's at the top-level, or within each subtable (e.g. a [[dependencies]] subtable.

Related - let's also make sure a the test exercises the possibility of nesting metadata within e.g. a [[dependencies]].

@darkowlzz darkowlzz force-pushed the 506-add-metadata-warn-unknown-manifest-fields branch from 831aab0 to e518855 Compare May 9, 2017 05:00
- Makes metadata TOML table.
- Allows metadata table in "dependencies" and "overrides".
@darkowlzz
Copy link
Collaborator Author

@sdboyer great! now that makes things more clear :)

  • metadata is now a TOML table [metadata] (map).
  • metadata can be added within subtables of [[dependencies]] and [[overrides]], only as TOML table (map). Added the tests for the same.

@sdboyer
Copy link
Member

sdboyer commented May 9, 2017

Awesome, this looks great! Thanks so much 😄 🎉

@sdboyer sdboyer merged commit b3bd16e into golang:master May 9, 2017
@mdelder
Copy link

mdelder commented May 9, 2017

It appears that this PR may have triggered a regression. Consuming the latest, I see:

# github.com/golang/dep
/go/src/github.com/golang/dep/manifest.go:109: undefined: internal.Logf
# github.com/golang/dep
/go/src/github.com/golang/dep/manifest.go:109: undefined: internal.Logf
/usr/local/bin/kube-tlssec-prep.sh: line 22: dep: not found
/usr/local/bin/kube-tlssec-prep.sh: line 23: dep: not found

From:

go get github.com/golang/dep

@sdboyer
Copy link
Member

sdboyer commented May 9, 2017

@mdelder it did indeed - thanks for responding quickly here. I'm updating things now.

ibrasho pushed a commit to ibrasho-forks/dep that referenced this pull request May 10, 2017
…known-manifest-fields

Add metadata to manifest & warn on unknown fields
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants