Class: Inspec::Resources::GrubConfig

Inherits:
Object
  • Object
show all
Includes:
FileReader
Defined in:
lib/inspec/resources/grub_conf.rb

Defined Under Namespace

Classes: UnknownGrubConfig

Instance Method Summary collapse

Methods included from FileReader

#read_file_content

Constructor Details

#initialize(path = nil, kernel = nil) ⇒ GrubConfig

Returns a new instance of GrubConfig.



27
28
29
30
31
32
33
# File 'lib/inspec/resources/grub_conf.rb', line 27

def initialize(path = nil, kernel = nil)
  config_for_platform(path)
  @content = read_file(@conf_path)
  @kernel = kernel || "default"
rescue UnknownGrubConfig
  skip_resource "The `grub_conf` resource is not yet supported on the target OS #{inspec.os[:name]}."
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



64
65
66
# File 'lib/inspec/resources/grub_conf.rb', line 64

def method_missing(name)
  read_params[name.to_s]
end

Instance Method Details

#config_for_platform(path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/inspec/resources/grub_conf.rb', line 35

def config_for_platform(path)
  os = inspec.os
  if os.redhat? || os[:name] == "fedora"
    config_for_redhatish(path)
  elsif os.debian?
    @conf_path = path || "/boot/grub/grub.cfg"
    @defaults_path = "/etc/default/grub"
    @grubenv_path = "/boot/grub2/grubenv"
    @version = "grub2"
  elsif os[:name] == "amazon"
    @conf_path = path || "/etc/grub.conf"
    @version = "legacy"
  else
    raise UnknownGrubConfig
  end
end

#config_for_redhatish(path) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/inspec/resources/grub_conf.rb', line 52

def config_for_redhatish(path)
  if inspec.os[:release].to_f < 7
    @conf_path = path || "/etc/grub.conf"
    @version = "legacy"
  else
    @conf_path = path || "/boot/grub2/grub.cfg"
    @defaults_path = "/etc/default/grub"
    @grubenv_path = "/boot/grub2/grubenv"
    @version = "grub2"
  end
end

#resource_idObject



72
73
74
# File 'lib/inspec/resources/grub_conf.rb', line 72

def resource_id
  @conf_path
end

#to_sObject



68
69
70
# File 'lib/inspec/resources/grub_conf.rb', line 68

def to_s
  "Grub Config"
end