Class: Wright::Provider::Group::DarwinDirectoryService

Inherits:
Wright::Provider::Group show all
Defined in:
lib/wright/provider/group/darwin_directory_service.rb

Overview

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

Constant Summary

Constants inherited from Wright::Provider

PROVIDER_DIR

Instance Method Summary collapse

Methods inherited from Wright::Provider::Group

#add_member, #create, #ensure_group_exists, #gid, #gid_uptodate?, #group_exists?, #group_name, #members, #members_uptodate?, #remove, #remove_member, #system_group?, #uptodate?

Methods inherited from Wright::Provider

#env, #exec_or_fail, #initialize, #unless_dry_run, #unless_uptodate, #updated?

Constructor Details

This class inherits a constructor from Wright::Provider

Instance Method Details

#create_groupObject (private)


12
13
14
15
16
17
18
19
# 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_dataObject (private)

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


44
45
46
# 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_gidObject (private)


48
49
50
51
# 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_groupObject (private)


21
22
23
24
25
# 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_gidObject (private)


34
35
36
37
38
39
40
# 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_membersObject (private)


27
28
29
30
31
32
# 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