Class: Inspec::Resources::XinetdConf

Inherits:
Object
  • Object
show all
Includes:
XinetdParser
Defined in:
lib/resources/xinetd.rb

Overview

rubocop:disable Metrics/ClassLength

Instance Method Summary collapse

Methods included from XinetdParser

#parse_xinetd, #xinetd_include_dir

Constructor Details

#initialize(conf_path = '/etc/xinetd.conf', opts = {}) ⇒ XinetdConf

Returns a new instance of XinetdConf.



23
24
25
26
27
28
# File 'lib/resources/xinetd.rb', line 23

def initialize(conf_path = '/etc/xinetd.conf', opts = {})
  @conf_path = conf_path
  @params = opts[:params] unless opts[:params].nil?
  @filters = opts[:filters] || ''
  @contents = {}
end

Instance Method Details

#disabled?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/resources/xinetd.rb', line 54

def disabled?
  filter(disable: 'no').services.empty?
end

#enabled?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/resources/xinetd.rb', line 58

def enabled?
  filter(disable: 'yes').services.empty?
end

#filter(conditions = {}) ⇒ Object



78
79
80
81
82
83
84
85
86
87
# File 'lib/resources/xinetd.rb', line 78

def filter(conditions = {})
  res = params.dup
  filters = ''
  conditions.each do |k, v|
    v = v.to_s if v.is_a? Integer
    filters += " #{k} = #{v.inspect}"
    res['services'] = filter_by(res['services'], k.to_s, v)
  end
  XinetdConf.new(@conf_path, params: res, filters: filters)
end

#ids(condition = nil) ⇒ Object



38
39
40
# File 'lib/resources/xinetd.rb', line 38

def ids(condition = nil)
  condition.nil? ? services_field('id') : filter(id: condition)
end

#paramsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/resources/xinetd.rb', line 62

def params
  return @params if defined?(@params)
  return @params = {} if read_content.nil?
  flat_params = parse_xinetd(read_content)
  @params = { 'services' => {} }
  flat_params.each do |k, v|
    name = k[/^service (.+)$/, 1]
    if name.nil?
      @params[k] = v
    else
      @params['services'][name] = v
    end
  end
  @params
end

#services(condition = nil) ⇒ Object



34
35
36
# File 'lib/resources/xinetd.rb', line 34

def services(condition = nil)
  condition.nil? ? params['services'].keys : filter(service: condition)
end

#socket_types(condition = nil) ⇒ Object



42
43
44
# File 'lib/resources/xinetd.rb', line 42

def socket_types(condition = nil)
  condition.nil? ? services_field('socket_type') : filter(socket_type: condition)
end

#to_sObject



30
31
32
# File 'lib/resources/xinetd.rb', line 30

def to_s
  "Xinetd config #{@conf_path}"
end

#types(condition = nil) ⇒ Object



46
47
48
# File 'lib/resources/xinetd.rb', line 46

def types(condition = nil)
  condition.nil? ? services_field('type') : filter(type: condition)
end

#wait(condition = nil) ⇒ Object



50
51
52
# File 'lib/resources/xinetd.rb', line 50

def wait(condition = nil)
  condition.nil? ? services_field('wait') : filter(wait: condition)
end