mirror of
https://github.com/inspec/inspec
synced 2024-11-23 13:13:22 +00:00
externalize passwd parser
This commit is contained in:
parent
535fc10b5d
commit
57676d88a1
2 changed files with 28 additions and 0 deletions
|
@ -23,9 +23,13 @@
|
|||
# its(:count) { should eq 1 }
|
||||
# end
|
||||
|
||||
require 'utils/parser'
|
||||
|
||||
class Passwd < Vulcano.resource(1)
|
||||
name 'passwd'
|
||||
|
||||
include ContentParser
|
||||
|
||||
attr_reader :uid
|
||||
attr_reader :parsed
|
||||
|
||||
|
|
24
lib/utils/parser.rb
Normal file
24
lib/utils/parser.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
# encoding: utf-8
|
||||
|
||||
module ContentParser
|
||||
# parse etc/passwd file
|
||||
def parse_passwd(content)
|
||||
content.split("\n").map do |line|
|
||||
parse_passwd_line(line)
|
||||
end
|
||||
end
|
||||
|
||||
# parse a etc/passwd line
|
||||
def parse_passwd_line(line)
|
||||
x = line.split(':')
|
||||
{
|
||||
'name' => x.at(0),
|
||||
'password' => x.at(1),
|
||||
'uid' => x.at(2),
|
||||
'gid' => x.at(3),
|
||||
'desc' => x.at(4),
|
||||
'home' => x.at(5),
|
||||
'shell' => x.at(6),
|
||||
}
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue