Sha256: 4e6797b612220738221eb90dc3f4a28848f9e0a9796b955d5cd341dd92fa9a0c

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

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

module Wright
  class Provider
    class Group
      # GNU passwd group provider. Used as a provider for
      # {Resource::Group} on GNU systems.
      class GnuPasswd < Wright::Provider::Group
        private

        def add_group(group_name, gid, system)
          options = []
          options << '--system' if system
          options += ['-g', gid.to_s] if gid
          cmd = 'groupadd'
          args = [*options, group_name]
          exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
        end

        def delete_group(group_name)
          cmd = 'groupdel'
          args = [group_name]
          exec_or_fail(cmd, args, "cannot remove group '#{group_name}'")
        end

        def set_members(group_name, members)
          cmd = 'gpasswd'
          args = ['-M', members.join(','), group_name]
          exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
        end

        def set_gid(group_name, gid)
          cmd = 'groupmod'
          args = ['-g', gid.to_s, group_name]
          exec_or_fail(cmd, args, "cannot create group '#{group_name}'")
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wright-0.3.2 lib/wright/provider/group/gnu_passwd.rb
wright-0.3.1 lib/wright/provider/group/gnu_passwd.rb