Skip to content

Commit

Permalink
Update S0022 check to Ingest .liu files
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronoftheages committed Jun 26, 2024
1 parent 1186753 commit 2958d5a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 28 deletions.
69 changes: 41 additions & 28 deletions lib/facter/pe_status_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,41 +237,54 @@
# Also takes into account if the license type is Perpetual
next unless ['primary'].include?(Facter.value('pe_status_check_role'))

# Check for suite license file
suite_license_file = '/etc/puppetlabs/suite-license.lic'

# Check for license key file
license_file = '/etc/puppetlabs/license.key'
if File.exist?(license_file)
begin
license_type = File.readlines(license_file).grep(%r{license_type:}).first
if license_type.nil?
validity = true
elsif license_type.include? 'Perpetual'
validity = true
elsif license_type.include? 'Subscription'
require 'date'
begin
end_date = Date.parse(File.readlines(license_file).grep(%r{end:}).first)
today_date = Date.today
daysexp = (end_date - today_date).to_i
validity = ((today_date <= end_date) && (daysexp >= 90)) ? true : false
rescue StandardError => e
Facter.warn("Error in fact 'pe_status_check.S0022' when checking license end date: #{e.message}")
Facter.debug(e.backtrace)
# license file has missing or invalid end date

# Initialize validity as false
validity = false

if File.exist?(suite_license_file)
# Presence of file satisfy check
validity = true
else
if File.exist?(license_file)
begin
license_type = File.readlines(license_file).grep(%r{license_type:}).first
if license_type.nil?
validity = true
elsif license_type.include? 'Perpetual'
validity = true
elsif license_type.include? 'Subscription'
require 'date'
begin
end_date = Date.parse(File.readlines(license_file).grep(%r{end:}).first)
today_date = Date.today
daysexp = (end_date - today_date).to_i
validity = ((today_date <= end_date) && (daysexp >= 90)) ? true : false
rescue StandardError => e
Facter.warn("Error in fact 'pe_status_check.S0022' when checking license end date: #{e.message}")
Facter.debug(e.backtrace)
# license file has missing or invalid end date
validity = false
end
else
# license file has invalid license_type
validity = false
end
else
# license file has invalid license_type
end
rescue StandardError => e
Facter.warn("Error in fact 'pe_status_check.S0022' when checking license type: #{e.message}")
validity = false
end
rescue StandardError => e
Facter.warn("Error in fact 'pe_status_check.S0022' when checking license type: #{e.message}")
else
# Neither suite-license.lic nor license.key exist
validity = false
end
else
# license file doesn't exist
validity = false

{ S0022: validity }
end
{ S0022: validity }
end

chunk(:S0023) do
# Is the CA_CRL expiring in the next 90 days
Expand Down
12 changes: 12 additions & 0 deletions spec/acceptance/pe_status_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,18 @@ class {'pe_status_check':
expect(result.stdout).to match(%r{false})
run_shell('mv -f /tmp/license.key /etc/puppetlabs/license.key')
end
it 'if S0022 conditions when license.key is not present but suite-license is present to be true' do
run_shell('touch /etc/puppetlabs/suite-license.liu && mv /etc/puppetlabs/license.key /tmp/license.key')
result = run_shell('facter -p pe_status_check.S0022')
expect(result.stdout).to match(%r{true})
run_shell('mv -f /tmp/license.key /etc/puppetlabs/license.key')
end
it 'if S0022 conditions when both license files are not present to be false' do
run_shell('mv /etc/puppetlabs/license.key /tmp/license.key && touch /etc/puppetlabs/suite_license.liu && mv /etc/puppetlabs/suite_license.liu /tmp/suite_license.liu')
result = run_shell('facter -p pe_status_check.S0022')
expect(result.stdout).to match(%r{false})
run_shell('mv -f /tmp/license.key /etc/puppetlabs/license.key && mv -f /tmp/suite_license.liu /etc/puppetlabs/suite_license.liu')
end
it 'if S0024 conditions for false are met' do
run_shell('touch -d "30 minutes ago" /opt/puppetlabs/server/data/puppetdb/stockpile/discard/test.file')
result = run_shell('facter -p pe_status_check.S0024')
Expand Down

0 comments on commit 2958d5a

Please sign in to comment.