Class: Inspec::Resources::Group

Inherits:
Object
  • Object
show all
Includes:
GroupManagementSelector
Defined in:
lib/inspec/resources/groups.rb

Overview

Usage: describe group(‘root’) do

it { should exist }
its('gid') { should eq 0 }

end

Instance Method Summary collapse

Methods included from GroupManagementSelector

#select_group_manager

Constructor Details

#initialize(groupname) ⇒ Group

Returns a new instance of Group.



116
117
118
119
120
121
122
# File 'lib/inspec/resources/groups.rb', line 116

def initialize(groupname)
  @group = groupname

  # select group manager
  @group_provider = select_group_manager(inspec.os)
  return skip_resource "The `group` resource is not supported on your OS yet." if @group_provider.nil?
end

Instance Method Details

#exists?Boolean

verifies if a group exists

Returns:

  • (Boolean)


125
126
127
# File 'lib/inspec/resources/groups.rb', line 125

def exists?
  !group_info.entries.empty?
end

#gidObject



129
130
131
# File 'lib/inspec/resources/groups.rb', line 129

def gid
  flatten_entry(group_info, "gid")
end

#has_gid?(gid_value) ⇒ Boolean

matcher equivalent to gid property.

Returns:

  • (Boolean)


149
150
151
# File 'lib/inspec/resources/groups.rb', line 149

def has_gid?(gid_value)
  gid_value == gid
end

#localObject



143
144
145
146
# File 'lib/inspec/resources/groups.rb', line 143

def local
  # at this point the implementation only returns local groups
  true
end

#membersObject



133
134
135
136
# File 'lib/inspec/resources/groups.rb', line 133

def members
  members_list = flatten_entry(group_info, "members") || empty_value_for_members
  inspec.os.windows? ? Members.new(members_list) : members_list
end

#members_arrayObject



138
139
140
141
# File 'lib/inspec/resources/groups.rb', line 138

def members_array
  members_list = flatten_entry(group_info, "members_array") || []
  inspec.os.windows? ? Members.new(members_list) : members_list
end

#resource_idObject



157
158
159
# File 'lib/inspec/resources/groups.rb', line 157

def resource_id
  gid ? "#{@group}-#{gid}" : ""
end

#to_sObject



153
154
155
# File 'lib/inspec/resources/groups.rb', line 153

def to_s
  "Group #{@group}"
end