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

puppet-syntax: Validate hiera keys #441

Merged
merged 1 commit into from
Mar 8, 2024

Conversation

bastelfreak
Copy link
Collaborator

For a long time puppet-syntax has support to validate hiera keys and eyaml. We should use this functionality.

https://github.com/voxpupuli/puppet-syntax?tab=readme-ov-file#configuration

From my local testing. The default output:

$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml

Now that's a bug in puppet-syntax. It always prints the subtasks, even if they aren't executed.

If I break a hiera data file:

$ git diff data/common.yaml
diff --git a/data/common.yaml b/data/common.yaml
index ad8bb3d..4243024 100644
--- a/data/common.yaml
+++ b/data/common.yaml
@@ -19,5 +19,5 @@ lookup_options:
     merge: 'unique'

 # Default is currently yum path
-yum::plugin::versionlock::path: /etc/yum/pluginconf.d/versionlock.list
+::yum::plugin::versionlock::path: /etc/yum/pluginconf.d/versionlock.list
 yum::settings::mainconf: /etc/yum.conf

I get the following output:

$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
WARNING: data/common.yaml: Key ::yum::plugin::versionlock::path: Puppet automatic lookup will not use leading '::'

by default puppet-syntax uses the following paths for hiera files:

 @hieradata_paths = [
   '**/data/**/*.*{yaml,yml}',
   'hieradata/**/*.*{yaml,yml}',
   'hiera*.*{yaml,yml}',
 ]

https://github.com/voxpupuli/puppet-syntax/blob/master/lib/puppet-syntax.rb#L9-L13

For a long time puppet-syntax has support to validate hiera keys and
eyaml. We should use this functionality.

https://github.com/voxpupuli/puppet-syntax?tab=readme-ov-file#configuration

From my local testing. The default output:

```terminal
$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
```

Now that's a bug in puppet-syntax. It always prints the subtasks, even
if they aren't executed.

If I break a hiera data file:

```diff
$ git diff data/common.yaml
diff --git a/data/common.yaml b/data/common.yaml
index ad8bb3d..4243024 100644
--- a/data/common.yaml
+++ b/data/common.yaml
@@ -19,5 +19,5 @@ lookup_options:
     merge: 'unique'

 # Default is currently yum path
-yum::plugin::versionlock::path: /etc/yum/pluginconf.d/versionlock.list
+::yum::plugin::versionlock::path: /etc/yum/pluginconf.d/versionlock.list
 yum::settings::mainconf: /etc/yum.conf
 ```

 I get the following output:

 ```terminal
$ bundle exec rake syntax
---> syntax:manifests
---> syntax:templates
---> syntax:hiera:yaml
WARNING: data/common.yaml: Key ::yum::plugin::versionlock::path: Puppet automatic lookup will not use leading '::'
 ```

 by default puppet-syntax uses the following paths for hiera files:

 ```ruby
  @hieradata_paths = [
    '**/data/**/*.*{yaml,yml}',
    'hieradata/**/*.*{yaml,yml}',
    'hiera*.*{yaml,yml}',
  ]
```

https://github.com/voxpupuli/puppet-syntax/blob/master/lib/puppet-syntax.rb#L9-L13
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 41.80%. Comparing base (e3b7546) to head (f5a0016).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #441      +/-   ##
==========================================
+ Coverage   41.71%   41.80%   +0.08%     
==========================================
  Files          10       10              
  Lines         676      677       +1     
==========================================
+ Hits          282      283       +1     
  Misses        394      394              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bastelfreak
Copy link
Collaborator Author

There's also a related PR in puppet-syntax to print a warning if the hiera check is called but disabled: voxpupuli/puppet-syntax#165

Copy link
Contributor

@gavindidrichsen gavindidrichsen left a comment

Choose a reason for hiding this comment

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

Great idea!

@gavindidrichsen gavindidrichsen merged commit 7863f3f into puppetlabs:main Mar 8, 2024
11 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants