Class: Inspec::Resources::EtcGroup
- Inherits:
-
Object
- Object
- Inspec::Resources::EtcGroup
- Includes:
- CommentParser, Converter
- Defined in:
- lib/resources/etc_group.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
Returns the value of attribute entries.
-
#gid ⇒ Object
Returns the value of attribute gid.
Instance Method Summary collapse
- #gids(filter = nil) ⇒ Object
- #groups(filter = nil) ⇒ Object
-
#initialize(path = nil) ⇒ EtcGroup
constructor
A new instance of EtcGroup.
- #to_s ⇒ Object
- #users(filter = nil) ⇒ Object
- #where(conditions = {}) ⇒ Object
Methods included from CommentParser
Methods included from Converter
Constructor Details
#initialize(path = nil) ⇒ EtcGroup
Returns a new instance of EtcGroup.
43 44 45 46 47 48 49 50 |
# File 'lib/resources/etc_group.rb', line 43 def initialize(path = nil) @path = path || '/etc/group' @entries = parse_group(@path) # skip resource if it is not supported on current OS return skip_resource 'The `etc_group` resource is not supported on your OS.' \ unless inspec.os.unix? end |
Instance Attribute Details
#entries ⇒ Object
Returns the value of attribute entries.
42 43 44 |
# File 'lib/resources/etc_group.rb', line 42 def entries @entries end |
#gid ⇒ Object
Returns the value of attribute gid.
42 43 44 |
# File 'lib/resources/etc_group.rb', line 42 def gid @gid end |
Instance Method Details
#gids(filter = nil) ⇒ Object
57 58 59 60 |
# File 'lib/resources/etc_group.rb', line 57 def gids(filter = nil) entries = filter || @entries entries.map { |x| x['gid'] } if !entries.nil? end |
#groups(filter = nil) ⇒ Object
52 53 54 55 |
# File 'lib/resources/etc_group.rb', line 52 def groups(filter = nil) entries = filter || @entries entries.map { |x| x['name'] } if !entries.nil? end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/resources/etc_group.rb', line 95 def to_s '/etc/group' end |
#users(filter = nil) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/resources/etc_group.rb', line 62 def users(filter = nil) entries = filter || @entries return nil if entries.nil? # filter the user entry res = entries.map { |x| x['members'].split(',') if !x.nil? && !x['members'].nil? }.flatten # filter nil elements res.reject { |x| x.nil? || x.empty? } end |
#where(conditions = {}) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/resources/etc_group.rb', line 73 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 conditions.each do |k, v| idx = fields[k.to_sym] next if idx.nil? res = res.select { |x| x[idx] == v.to_s } end EtcGroupView.new(self, res) end |