class Chef::Resource::InspecWaiver

Public Instance Methods

build_source() click to toggle source
# File lib/chef/resource/inspec_waiver.rb, line 153
def build_source
  return new_resource.source unless new_resource.source.nil?
  return nil unless new_resource.control.count(::File::SEPARATOR) > 0 || (::File::ALT_SEPARATOR && new_resource.control.count(::File::ALT_SEPARATOR) > 0 )
  return nil unless ::File.exist?(new_resource.control)

  new_resource.control
end
source() click to toggle source

If the source is nil and the control / name_property contains a file separator and is a string of a file that exists, then use that as the file (similar to the package provider automatic source property). Otherwise just return the source.

@api private

# File lib/chef/resource/inspec_waiver.rb, line 149
def source
  @source ||= build_source
end
waiver_hash() click to toggle source
# File lib/chef/resource/inspec_waiver.rb, line 161
def waiver_hash
  case source
  when Hash
    source
  when String
    parse_file(source)
  when nil
    if new_resource.justification.nil? || new_resource.justification == ""
      raise Chef::Exceptions::ValidationFailed, "Entries for an InSpec waiver must have a justification given, this parameter must have a value."
    end

    control_hash = {}
    control_hash["expiration_date"] = new_resource.expiration.to_s unless new_resource.expiration.nil?
    control_hash["run"] = new_resource.run_test unless new_resource.run_test.nil?
    control_hash["justification"] = new_resource.justification.to_s

    { new_resource.control => control_hash }
  end
end