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

(PDK-1615) Add validator for environment.conf #866

Merged

Conversation

glennsarti
Copy link
Contributor

@glennsarti glennsarti commented Mar 3, 2020

This commit adds a validator for the environment.conf file when being used
inside a control repository. The validator complies with the rules set out in
https://puppet.com/docs/puppet/latest/config_file_environment.html.

This commit also adds tests for the validator setup, and various example file
content and expected validation results.


TODO

  • Should this be in the puppet validator group OR should it be in a separate validator group e.g. controlrepo ?

@glennsarti glennsarti requested a review from a team as a code owner March 3, 2020 08:06
@coveralls
Copy link

coveralls commented Mar 3, 2020

Coverage Status

Coverage increased (+0.03%) to 91.301% when pulling 6c3881e on glennsarti:pdk-1615-add-environment-validator into 807b1b7 on puppetlabs:master.

Copy link
Contributor

@scotje scotje left a comment

Choose a reason for hiding this comment

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

Added a few minor comments/suggestions.

As for the grouping, I would lean towards a distinct controlrepo (or similarly named) group for control-repo meta validations.

env_conf = PDK::ControlRepo.environment_conf_as_config(target)

env_conf.resolve.each do |setting_name, setting_value|
setting_name = setting_name.slice(12..-1)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm guessing this is slicing off an environment. prefix? Adding a comment about that or even using gsub (performance implications should be pretty minor) would help clarify this for future us.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.

end

context 'when a target is provided that has all allowed settings and is valid' do
let(:target) { { name: 'environment.conf', content: "modulepath=foo\nmanifest=foo\nconfig_version=foo\nenvironment_timeout=0" } }
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move content to it's own var/let block and use a heredoc to make it easier to maintain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I managed to use a heredoc inside the hash which looks ok e.g.

      let(:target) do
        {
          name: 'environment.conf',
          content: <<-EOT
                   modulepath=foo
                   manifest=foo
                   config_version=foo
                   environment_timeout=0
                   EOT
        }
      end

@rodjek
Copy link
Contributor

rodjek commented Mar 4, 2020

Should this be in the puppet validator group OR should it be in a separate validator group e.g. controlrepo ?

I think this should be in a control repo validator group

@glennsarti glennsarti force-pushed the pdk-1615-add-environment-validator branch from 44ca412 to 1aa7d21 Compare March 4, 2020 01:57
This commit adds a validator for the environment.conf file when being used
inside a control repository.  The validator complies with the rules set out in
https://puppet.com/docs/puppet/latest/config_file_environment.html.

This commit also adds tests for the validator setup, and various example file
content and expected validation results.
@glennsarti glennsarti force-pushed the pdk-1615-add-environment-validator branch from 1aa7d21 to 7ffa17f Compare March 4, 2020 04:54
@glennsarti
Copy link
Contributor Author

glennsarti commented Mar 4, 2020

Moved it to it's own validator group control-repo

e.g.

ruby bin\pdk validate control-repo

and

> ruby bin\pdk validate --list
pdk (INFO): Available validators: control-repo, metadata, puppet, ruby, tasks, yaml

This commit cleans up the autoloading statements to be an alphabetical order.
@glennsarti glennsarti merged commit d51ce5e into puppetlabs:master Mar 5, 2020
@glennsarti glennsarti deleted the pdk-1615-add-environment-validator branch March 5, 2020 04:56
@scotje scotje added the feature label May 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants