Created
June 25, 2013 12:58
-
-
Save deanwilson/5858235 to your computer and use it in GitHub Desktop.
Add a simple puppet lint check to alert on template calls to 'puppet://' uris
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/lib/puppet-lint/plugins/check_resources.rb b/lib/puppet-lint/plugins/check_resources.rb | |
| index 3e52c04..20c1f9d 100644 | |
| --- a/lib/puppet-lint/plugins/check_resources.rb | |
| +++ b/lib/puppet-lint/plugins/check_resources.rb | |
| @@ -183,4 +183,41 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin | |
| end | |
| end | |
| end | |
| + | |
| + # Public: Check the content line for each File resource instance for a Puppet Module | |
| + # URI inside a template call. This is almost never what you want | |
| + # | |
| + # Returns nothing. | |
| + | |
| + check 'template_path_uri' do | |
| + | |
| + resource_indexes.each do |resource| | |
| + resource_tokens = tokens[resource[:start]..resource[:end]] | |
| + prev_tokens = tokens[0..resource[:start]] | |
| + | |
| + lbrace_idx = prev_tokens.rindex { |r| | |
| + r.type == :LBRACE | |
| + } | |
| + | |
| + resource_type_token = tokens[lbrace_idx].prev_code_token | |
| + if resource_type_token.value == "file" | |
| + resource_tokens.select { |resource_token| | |
| + resource_token.type == :NAME and resource_token.value == 'content' | |
| + }.each do |resource_token| | |
| + | |
| + template_token = resource_token.next_code_token.next_code_token | |
| + path_token = template_token.next_code_token.next_code_token | |
| + | |
| + if template_token.value == 'template' and path_token.value.start_with? 'puppet://' | |
| + notify :warning, { | |
| + :message => "Templated content contains a 'puppet://' uri - #{path_token.value}", | |
| + :linenumber => path_token.line, | |
| + :column => path_token.column, | |
| + } | |
| + end | |
| + end | |
| + end | |
| + end | |
| + end | |
| + |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment