Class: 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.



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

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)


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

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

#enabled?Boolean

Returns:

  • (Boolean)


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

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

#filter(conditions = {}) ⇒ Object



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

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



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

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

#paramsObject



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

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



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

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

#socket_types(condition = nil) ⇒ Object



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

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

#to_sObject



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

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

#types(condition = nil) ⇒ Object



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

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

#wait(condition = nil) ⇒ Object



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

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