class Chef::Compliance::Profile

Constants

HIDDEN_IVARS

Attributes

cookbook_name[R]

@return [String] The name of the cookbook that the profile is in

data[R]

@api private

enabled[RW]

@return [Boolean] if the profile has been enabled

events[R]

@return [Chef::EventDispatch::Dispatcher] Event dispatcher for this run.

path[R]

@return [String] The full path on the host to the profile inspec.yml

pathname[RW]

@return [String] the pathname in the cookbook

Public Class Methods

from_file(events, filename, cookbook_name) click to toggle source

@param filename [String] full path to the inspec.yml file in the cookbook @param cookbook_name [String] cookbook that the profile is in

# File lib/chef/compliance/profile.rb, line 117
def self.from_file(events, filename, cookbook_name)
  from_yaml(events, IO.read(filename), filename, cookbook_name)
end
from_hash(events, hash, path, cookbook_name) click to toggle source

Helper to construct a profile object from a hash. Since the path and cookbook_name are required this is probably not externally useful.

# File lib/chef/compliance/profile.rb, line 103
def self.from_hash(events, hash, path, cookbook_name)
  new(events, hash, path, cookbook_name)
end
from_yaml(events, string, path, cookbook_name) click to toggle source

Helper to construct a profile object from a yaml string. Since the path and cookbook_name are required this is probably not externally useful.

# File lib/chef/compliance/profile.rb, line 110
def self.from_yaml(events, string, path, cookbook_name)
  from_hash(events, YAML.safe_load(string, permitted_classes: [Date]), path, cookbook_name)
end
new(events, data, path, cookbook_name) click to toggle source
# File lib/chef/compliance/profile.rb, line 39
def initialize(events, data, path, cookbook_name)
  @events = events
  @data = data
  @path = path
  @cookbook_name = cookbook_name
  @pathname = File.basename(File.dirname(path))
  disable!
  validate!
end

Public Instance Methods

disable!() click to toggle source

Set the profile as being disabled

# File lib/chef/compliance/profile.rb, line 79
def disable!
  @enabled = false
end
enable!() click to toggle source

Set the profile to being enabled

# File lib/chef/compliance/profile.rb, line 72
def enable!
  events.compliance_profile_enabled(self)
  @enabled = true
end
enabled?() click to toggle source

@return [Boolean] if the profile has been enabled

# File lib/chef/compliance/profile.rb, line 66
def enabled?
  !!@enabled
end
inspec_data() click to toggle source

Render the profile in a way that it can be consumed by inspec

# File lib/chef/compliance/profile.rb, line 85
def inspec_data
  { name: name, path: File.dirname(path) }
end
inspect() click to toggle source

Omit the event object from error output

# File lib/chef/compliance/profile.rb, line 93
def inspect
  ivar_string = (instance_variables.map(&:to_sym) - HIDDEN_IVARS).map do |ivar|
    "#{ivar}=#{instance_variable_get(ivar).inspect}"
  end.join(", ")
  "#<#{self.class}:#{object_id} #{ivar_string}>"
end
name() click to toggle source

@return [String] name of the inspec profile from parsing the inspec.yml

# File lib/chef/compliance/profile.rb, line 50
def name
  @data["name"]
end
validate!() click to toggle source

Raises if the inspec profile is not valid.

# File lib/chef/compliance/profile.rb, line 61
def validate!
  raise "Inspec profile at #{path} has no name" unless name
end
version() click to toggle source

@return [String] version of the inspec profile from parsing the inspec.yml

# File lib/chef/compliance/profile.rb, line 55
def version
  @data["version"]
end