Skip to content

Commit

Permalink
Merge pull request #138 from puppetlabs/bugfix-legacy_fact_corrector
Browse files Browse the repository at this point in the history
(CAT-1167) Fix failing legacy fact autocorrector
  • Loading branch information
GSPatton authored Jul 28, 2023
2 parents 751d30e + bea0e5a commit 03bb0ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 48 deletions.
12 changes: 11 additions & 1 deletion lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,17 @@

PuppetLint.new_check(:top_scope_facts) do
def check
whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || [])
whitelist = ['trusted', 'facts', 'architecture', 'augeasversion', 'bios_release_date', 'bios_vendor', 'bios_version',
'boardassettag', 'boardmanufacturer', 'boardproductname', 'boardserialnumber', 'chassisassettag', 'chassistype', 'domain',
'fqdn', 'gid', 'hardwareisa', 'hardwaremodel', 'hostname', 'id', 'ipaddress', 'ipaddress6', 'lsbdistcodename',
'lsbdistdescription', 'lsbdistid', 'lsbdistrelease', 'lsbmajdistrelease', 'lsbminordistrelease', 'lsbrelease',
'macaddress', 'macosx_buildversion', 'macosx_productname', 'macosx_productversion', 'macosx_productversion_major',
'macosx_productversion_minor', 'manufacturer', 'memoryfree', 'memorysize', 'netmask', 'netmask6', 'network', 'network6',
'operatingsystem', 'operatingsystemmajrelease', 'operatingsystemrelease', 'osfamily', 'physicalprocessorcount',
'processorcount', 'productname', 'rubyplatform', 'rubysitedir', 'rubyversion', 'selinux', 'selinux_config_mode',
'selinux_config_policy', 'selinux_current_mode', 'selinux_enforced', 'selinux_policyversion', 'serialnumber',
'swapencrypted', 'swapfree', 'swapsize', 'system32', 'uptime', 'uptime_days', 'uptime_hours', 'uptime_seconds',
'uuid', 'xendomains', 'zonename'] + (PuppetLint.configuration.top_scope_variables || [])
whitelist = whitelist.join('|')
tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
next unless %r{^::}.match?(token.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,10 @@
end

context 'fact variable using top scope' do
let(:code) { '$::operatingsystem' }
let(:code) { '$::fqdn' }

it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'creates a warning' do
expect(problems).to contain_warning(msg).on_line(1).in_column(1)
end
end

context 'fact variable using top scope with curly braces in double quote' do
let(:code) { '"${::operatingsystem}"' }

it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'creates a warning' do
expect(problems).to contain_warning(msg).on_line(1).in_column(4)
it 'does not detect a single problem' do
expect(problems).to have(0).problem
end
end

Expand Down Expand Up @@ -126,34 +110,6 @@
end
end

context 'fact variable using top scope' do
let(:code) { '$::operatingsystem' }

it 'onlies detect a single problem' do
expect(problems).to have(1).problem
end

it 'fixes the problem' do
expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
end

it 'shoulds use the facts hash' do
expect(manifest).to eq("$facts['operatingsystem']")
end
end

context 'fact variable using top scope with curly braces in double quote' do
let(:code) { '"${::operatingsystem}"' }

it 'fixes the problem' do
expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
end

it 'shoulds use the facts hash' do
expect(manifest).to eq('"${facts[\'operatingsystem\']}"')
end
end

context 'with custom top scope fact variables' do
before(:each) do
PuppetLint.configuration.top_scope_variables = ['location', 'role']
Expand Down

0 comments on commit 03bb0ea

Please sign in to comment.