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

Allow deeper checking of hiera keys #73

Merged
merged 3 commits into from
Feb 8, 2017

Conversation

petems
Copy link
Member

@petems petems commented Feb 8, 2017

Resurrected from #57

  • Add regexes for checking hiera key formats
  • Enabled by flag 'check_hiera_keys' which is disabled by default as
    it's a breaking change
  • Adds spec to catch issues
  • Also move multiple entry arrays into separate lines to make cleaner
    git history
  • Add pry and rb-readline to the development dependancies to make
    development debugging easier

@@ -7,12 +7,22 @@
module PuppetSyntax
@exclude_paths = []
@future_parser = false
@hieradata_paths = ["**/data/**/*.*yaml", "hieradata/**/*.*yaml", "hiera*.*yaml"]
@hieradata_paths = [
Copy link
Member Author

Choose a reason for hiding this comment

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

I moved these to new lines to make the diffs nicer, but I can do it in a separate PR if needed


class << self
attr_accessor :exclude_paths, :future_parser, :hieradata_paths, :fail_on_deprecation_notices, :epp_only
attr_accessor :exclude_paths,
Copy link
Member Author

Choose a reason for hiding this comment

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

Same here: I moved these to new lines to make the diffs nicer, but I can do it in a separate PR if needed

@@ -21,5 +21,7 @@ Gem::Specification.new do |spec|
spec.add_dependency "rake"

spec.add_development_dependency "rspec"
spec.add_development_dependency "pry"
Copy link
Member Author

Choose a reason for hiding this comment

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

I added these for debugging, but can move to a seperate PR if needed

Copy link
Member

Choose a reason for hiding this comment

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

I dont think they need to be a separate PR but they should probably be separate commits within this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! 👍

Copy link
Contributor

@domcleal domcleal left a comment

Choose a reason for hiding this comment

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

I've no problem with the unrelated changes, otherwise looks good and useful.

Could you also document the new option in the README?

end
yamldata.each do |k,v|
if PuppetSyntax.check_hiera_keys
errors += Array(check_hiera_key(k)).map do |msg|
Copy link
Contributor

Choose a reason for hiding this comment

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

The Array(..).map here is a bit confusing as check_hiera_key either returns a string or nil. Perhaps better to write it simply as:

key_msg = check_heira_key(k)
errors << "WARNING: [..] #{key_msg}" if key_msg

Copy link
Member Author

Choose a reason for hiding this comment

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

Done! :


def check_hiera_key(key)
if key.is_a? Symbol
if key =~ /^:/
Copy link
Contributor

Choose a reason for hiding this comment

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

Swap this regexp for better performance. Use key.to_s.start_with(':')

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

rescue Exception => error
errors << "ERROR: Failed to parse #{hiera_file}: #{error}"
next
end
yamldata.each do |k,v|
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be a good idea to check the data type here before trying to iterate as loading an empty YAML file will return false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, added a spec around this also

@rjw1
Copy link
Member

rjw1 commented Feb 8, 2017

I'll run these against the govuk-puppet code base to see what it throws up and extract examples for further work.

@petems petems force-pushed the expand_hiera_support branch 2 times, most recently from 07791ce to fa8eb87 Compare February 8, 2017 13:23
Resurrected from voxpupuli#57

* Add regexes for checking hiera key formats
* Enabled by flag 'check_hiera_keys' which is disabled by default as
it's a breaking change
* Adds spec to catch issues
* Also move multiple entry arrays for attr_accesors
into separate lines to make cleaner git history
* Makes diffs easier to read when new added 
elements
@domcleal
Copy link
Contributor

domcleal commented Feb 8, 2017

Looks fine to me, thanks @petems. I've not tested it so I'll leave it to @rjw1 to check it's working well first.

@petems
Copy link
Member Author

petems commented Feb 8, 2017

@domcleal Cool, we're pairing on it now so should be good to merge soonish 👍

@rjw1 rjw1 merged commit b6c04c6 into voxpupuli:master Feb 8, 2017
@rjw1
Copy link
Member

rjw1 commented Feb 8, 2017

@petems petems deleted the expand_hiera_support branch February 8, 2017 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants