Sha256: 5e0590d44bb775aecee21ed49cb638c2f913d30c5d7a593efab5df649d0d13b1

Contents?: true

Size: 1.1 KB

Versions: 6

Compression:

Stored size: 1.1 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 create_group
          options = []
          options << '--system' if system_group?
          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 remove_group
          cmd = 'groupdel'
          args = [group_name]
          exec_or_fail(cmd, args, "cannot remove group '#{group_name}'")
        end

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

        def set_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

6 entries across 6 versions & 1 rubygems

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