class Wright::Provider::Group::DarwinDirectoryService

Darwin DirectoryService group provider. Used as a provider for {Resource::Group} on OS X systems.

Private Instance Methods

create_group() click to toggle source
# File lib/wright/provider/group/darwin_directory_service.rb, line 12
def create_group
  target_gid = gid
  target_gid ||= next_system_gid if system_group?
  options = target_gid.nil? ? [] : ['-i', target_gid.to_s]
  cmd = 'dseditgroup'
  args = ['-o', 'create', *options, group_name]
  exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
end
group_data() click to toggle source

Overrides Provider::Group#group_data to work around caching issues with getgrnam(3) on OS X.

# File lib/wright/provider/group/darwin_directory_service.rb, line 44
def group_data
  Etc.group { |g| break g if g.name == group_name }
end
next_system_gid() click to toggle source
# File lib/wright/provider/group/darwin_directory_service.rb, line 48
def next_system_gid
  system_gid_range = (1...500)
  Wright::Util::User.next_free_gid(system_gid_range)
end
remove_group() click to toggle source
# File lib/wright/provider/group/darwin_directory_service.rb, line 21
def remove_group
  cmd = 'dseditgroup'
  args = ['-o', 'delete', group_name]
  exec_or_fail(cmd, args, "cannot remove group '#{group_name}'")
end
set_gid() click to toggle source
# File lib/wright/provider/group/darwin_directory_service.rb, line 34
def set_gid
  cmd = 'dseditgroup'
  args = ['-o', 'edit',
          '-i', gid.to_s,
          group_name]
  exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
end
set_members() click to toggle source
# File lib/wright/provider/group/darwin_directory_service.rb, line 27
def set_members
  options = ['GroupMembership', *members]
  cmd = 'dscl'
  args = ['.', 'create', "/Groups/#{group_name}", *options]
  exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
end