Sha256: fb73988539be6b94279f1ad83be38c8edea9e5c3203353d209b9797bc2d7b7d4

Contents?: true

Size: 1.65 KB

Versions: 6

Compression:

Stored size: 1.65 KB

Contents

require 'wright/provider'
require 'wright/provider/group'

module Wright
  class Provider
    class Group
      # Darwin DirectoryService group provider. Used as a provider for
      # {Resource::Group} on OS X systems.
      class DarwinDirectoryService < Wright::Provider::Group
        private

        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

        def remove_group
          cmd = 'dseditgroup'
          args = ['-o', 'delete', group_name]
          exec_or_fail(cmd, args, "cannot remove group '#{group_name}'")
        end

        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

        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

        # Overrides Provider::Group#group_data to work around caching
        # issues with getgrnam(3) on OS X.
        def group_data
          Etc.group { |g| break g if g.name == group_name }
        end

        def next_system_gid
          system_gid_range = (1...500)
          Wright::Util::User.next_free_gid(system_gid_range)
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
wright-0.5.0 lib/wright/provider/group/darwin_directory_service.rb
wright-0.4.4 lib/wright/provider/group/darwin_directory_service.rb
wright-0.4.3 lib/wright/provider/group/darwin_directory_service.rb
wright-0.4.2 lib/wright/provider/group/darwin_directory_service.rb
wright-0.4.1 lib/wright/provider/group/darwin_directory_service.rb
wright-0.4.0 lib/wright/provider/group/darwin_directory_service.rb