Class: Inspec::Resources::EtcGroup
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from FileReader
#read_file_content
#parse_comment_line
Methods included from Converter
#convert_to_i, to_boolean
Constructor Details
#initialize(path = nil) ⇒ EtcGroup
Returns a new instance of EtcGroup.
43
44
45
46
|
# File 'lib/inspec/resources/etc_group.rb', line 43
def initialize(path = nil)
@path = path || "/etc/group"
@entries = parse_group(@path)
end
|
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
42
43
44
|
# File 'lib/inspec/resources/etc_group.rb', line 42
def entries
@entries
end
|
#gid ⇒ Object
Returns the value of attribute gid.
42
43
44
|
# File 'lib/inspec/resources/etc_group.rb', line 42
def gid
@gid
end
|
Instance Method Details
#gids(filter = nil) ⇒ Object
52
53
54
|
# File 'lib/inspec/resources/etc_group.rb', line 52
def gids(filter = nil)
(filter || @entries)&.map { |x| x["gid"] }
end
|
#groups(filter = nil) ⇒ Object
48
49
50
|
# File 'lib/inspec/resources/etc_group.rb', line 48
def groups(filter = nil)
(filter || @entries)&.map { |x| x["name"] }
end
|
#resource_id ⇒ Object
98
99
100
|
# File 'lib/inspec/resources/etc_group.rb', line 98
def resource_id
@path
end
|
#to_s ⇒ Object
94
95
96
|
# File 'lib/inspec/resources/etc_group.rb', line 94
def to_s
"/etc/group"
end
|
#users(filter = nil) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/inspec/resources/etc_group.rb', line 56
def users(filter = nil)
entries = filter || @entries
return nil if entries.nil?
res = entries.map do |x|
x["members"].split(",") if !x.nil? && !x["members"].nil?
end.flatten
res.reject { |x| x.nil? || x.empty? }
end
|
#where(conditions = {}) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
# File 'lib/inspec/resources/etc_group.rb', line 68
def where(conditions = {})
return if conditions.empty?
fields = {
name: "name",
group_name: "name",
password: "password",
gid: "gid",
group_id: "gid",
users: "members",
members: "members",
}
res = entries
unless res.nil?
conditions.each do |k, v|
idx = fields[k.to_sym]
next if idx.nil?
res = res.select { |x| x[idx].to_s == v.to_s }
end
end
EtcGroupView.new(self, res)
end
|