mirror of
https://github.com/inspec/inspec
synced 2024-11-27 15:10:44 +00:00
filter comments in /etc/group
This commit is contained in:
parent
949496776e
commit
028e7f977e
2 changed files with 23 additions and 7 deletions
|
@ -6,9 +6,9 @@
|
||||||
|
|
||||||
# The file format consists of
|
# The file format consists of
|
||||||
# - group name
|
# - group name
|
||||||
# - password
|
# - password - group's encrypted password
|
||||||
# - gid
|
# - gid - group's decimal ID
|
||||||
# - group list, comma seperated list
|
# - member list - group members, comma seperated list
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# describe etc_group do
|
# describe etc_group do
|
||||||
|
@ -21,13 +21,17 @@
|
||||||
# its('users') { should include 'my_user' }
|
# its('users') { should include 'my_user' }
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
require 'utils/parser'
|
||||||
|
|
||||||
class EtcGroup < Vulcano.resource(1)
|
class EtcGroup < Vulcano.resource(1)
|
||||||
|
include ContentParser
|
||||||
|
|
||||||
name 'etc_group'
|
name 'etc_group'
|
||||||
|
|
||||||
attr_accessor :gid, :entries
|
attr_accessor :gid, :entries
|
||||||
def initialize(path = nil)
|
def initialize(path = nil)
|
||||||
@path = path || '/etc/group'
|
@path = path || '/etc/group'
|
||||||
@entries = parse(@path)
|
@entries = parse_group(@path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
|
@ -77,12 +81,23 @@ class EtcGroup < Vulcano.resource(1)
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def parse(path)
|
def parse_group(path)
|
||||||
@content = vulcano.file(path).content
|
@content = vulcano.file(path).content
|
||||||
@content.split("\n").map do |line|
|
# iterate over each line and filter comments
|
||||||
line.split(':')
|
@content.split("\n").each_with_object([]) do |line, lines|
|
||||||
|
grp_info = parse_group_line(line)
|
||||||
|
lines.push(grp_info) if !grp_info.nil? && grp_info.size > 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def parse_group_line(line)
|
||||||
|
opts = {
|
||||||
|
comment_char: '#',
|
||||||
|
standalone_comments: false,
|
||||||
|
}
|
||||||
|
line, _idx_nl = parse_comment_line(line, opts)
|
||||||
|
line.split(':')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# object that hold a specifc view on etc group
|
# object that hold a specifc view on etc group
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
|
# comment
|
||||||
root:x:0:
|
root:x:0:
|
||||||
www-data:x:33:www-data,root
|
www-data:x:33:www-data,root
|
||||||
|
|
Loading…
Reference in a new issue