Module: PuppetX::EasyType::Validation::CheckImplementation
- Defined in:
- lib/puppet_x/easy_type/validation/check_implementation.rb
Overview
The implementation for the validatio check
Instance Method Summary collapse
- #change_to_s(_current, _should) ⇒ Object
- #expected(output) ⇒ Object
- #insync?(_to) ⇒ Boolean
- #not_allowed(output) ⇒ Object
- #value_compare(output) ⇒ Object
Instance Method Details
#change_to_s(_current, _should) ⇒ Object
9 10 11 |
# File 'lib/puppet_x/easy_type/validation/check_implementation.rb', line 9 def change_to_s(_current, _should) 'The check has executed and found issues.' end |
#expected(output) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/puppet_x/easy_type/validation/check_implementation.rb', line 85 def expected(output) return true if resource[:expected_output].nil? expected_outputs = Array(resource[:expected_output]) expected_outputs.all? do | expect| if expect.is_a? Regexp if output.match?(expect) Puppet.debug "Regular expression '#{expect}' found in output." return true else Puppet.debug "Regular expression '#{expect}' NOT found in output." return false end else if output == expect Puppet.debug "String '#{expect}' found in output." return true else Puppet.debug "String '#{expect}' NOT found in output." return false end end end end |
#insync?(_to) ⇒ Boolean
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet_x/easy_type/validation/check_implementation.rb', line 13 def insync?(_to) if resource.noop Puppet.debug "#{path}: Skipping check because resource is set to noop." return true end return true if resource[:refreshonly].to_s == 'true' if !provider.validate_run? = "Executable #{provider.executable} not found or not in path. Skipping this check..." Puppet.warning "#{path}: #{}" resource.class.register_result(resource.control, 'SKIPPED', ) return true end if resource.skip.to_s == 'true' = "Skipping this check at users request." Puppet.debug "#{path}: #{}" resource.class.register_result(resource.control, 'SKIPPED', ) return true end output = provider.execute_check Puppet.debug output result = if resource.expected_value value_compare(output) else expected(output) && not_allowed(output) end = result ? resource.title : resource. resource.class.register_result(resource.control, result ? 'PASSED' : "FAILED", ) resource.report_as.to_s.downcase == 'none' ? true : result end |
#not_allowed(output) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/puppet_x/easy_type/validation/check_implementation.rb', line 60 def not_allowed(output) return true if resource[:not_allowed_output].nil? not_allowed_outputs = Array(resource[:not_allowed_output]) not_allowed_outputs.all? do | not_allowed| if not_allowed.is_a? Regexp if output.match?(not_allowed) Puppet.debug "Regular expression '#{not_allowed}' found in output." return false else Puppet.debug "Regular expression '#{not_allowed}' NOT found in output." return true end else if output == not_allowed Puppet.debug "String '#{not_allowed}' found in output." return true else Puppet.debug "String '#{not_allowed}' NOT found in output." return false end end end end |
#value_compare(output) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/puppet_x/easy_type/validation/check_implementation.rb', line 44 def value_compare(output) string_value = output.scan(resource.parse_value).flatten if string_value.size != 1 Puppet.debug "No valid value found after parsing output with #{resource.parse_value}" return false end actual_value = string_value.first.to_f Array(resource.expected_value).all? do |comparison| final_comparison = "#{actual_value} #{comparison}" final_comparison = final_comparison.gsub('$value', string_value.first) value = eval(final_comparison) Puppet.debug "Executing compare '#{final_comparison}' return a '#{value}'" value end end |