Class: Inspec::Resources::LoginDef

Inherits:
Object
  • Object
show all
Defined in:
lib/resources/login_def.rb

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ LoginDef

Returns a new instance of LoginDef.



31
32
33
# File 'lib/resources/login_def.rb', line 31

def initialize(path = nil)
  @conf_path = path || '/etc/login.defs'
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



35
36
37
# File 'lib/resources/login_def.rb', line 35

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

Instance Method Details

#read_paramsObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/resources/login_def.rb', line 39

def read_params
  return @params if defined?(@params)

  # read the file
  file = inspec.file(@conf_path)
  if !file.file?
    skip_resource "Can't find file \"#{@conf_path}\""
    return @params = {}
  end

  content = file.content
  if content.empty? && !file.empty?
    skip_resource "Can't read file \"#{@conf_path}\""
    return @params = {}
  end

  # parse the file
  conf = SimpleConfig.new(
    content,
    assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
    multiple_values: false,
  )
  @params = conf.params
end

#to_sObject



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

def to_s
  'login.defs'
end