Skip to content

Commit

Permalink
Refactor and Logic Testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronoftheages committed Jun 26, 2024
1 parent 53a4b49 commit 2af7880
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions lib/facter/pe_status_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,43 +249,42 @@
if File.exist?(suite_license_file)
# Presence of file satisfy check
validity = true
# Approve with only suite-license.liu
{ S0022: validity }
elsif 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
else
elsif File.exist?(license_file)

Check failure on line 253 in lib/facter/pe_status_check.rb

View workflow job for this annotation

GitHub Actions / Spec testing / Spec Tests (Puppet: ~> 7.24, Ruby Ver: 2.7)

Lint/Syntax: unexpected token kELSIF (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)

Check failure on line 253 in lib/facter/pe_status_check.rb

View workflow job for this annotation

GitHub Actions / Spec testing / Spec Tests (Puppet: ~> 8.0, Ruby Ver: 3.2)

Lint/Syntax: unexpected token kELSIF (Using Ruby 2.6 parser; configure using `TargetRubyVersion` parameter, under `AllCops`)
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
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
# Neither suite-license.lic nor license.key exist
validity = false
end

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

chunk(:S0023) do
# Is the CA_CRL expiring in the next 90 days
Expand Down

0 comments on commit 2af7880

Please sign in to comment.