Class: Inspec::Resources::Group

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

Overview

Usage: describe group(‘root’) do

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

end

deprecated has matcher describe group(‘root’) do

it { should have_gid 0 }

end

Instance Method Summary collapse

Methods included from GroupManagementSelector

#select_group_manager

Constructor Details

#initialize(groupname) ⇒ Group

Returns a new instance of Group.



98
99
100
101
102
103
104
# File 'lib/resources/groups.rb', line 98

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)


107
108
109
# File 'lib/resources/groups.rb', line 107

def exists?
  !group_info.entries.empty?
end

#gidObject



111
112
113
# File 'lib/resources/groups.rb', line 111

def gid
  flatten_entry(group_info, 'gid')
end

#has_gid?(compare_gid) ⇒ Boolean

implements rspec has matcher, to be compatible with serverspec

Returns:

  • (Boolean)


116
117
118
# File 'lib/resources/groups.rb', line 116

def has_gid?(compare_gid)
  gid == compare_gid
end

#localObject



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

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

#membersObject



120
121
122
123
# File 'lib/resources/groups.rb', line 120

def members
  return unless inspec.os.windows?
  flatten_entry(group_info, 'members')
end

#to_sObject



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

def to_s
  "Group #{@group}"
end