Sha256: 9dd7af3eef1707560582e912845a499d1308061938123f333ea3130c32a5e694

Contents?: true

Size: 1.45 KB

Versions: 6

Compression:

Stored size: 1.45 KB

Contents

Puppet::Type.type(:pg_user).provide(:debian_postgresql) do

  desc "Manage users for a postgres database cluster"

  defaultfor :operatingsystem => [:debian, :ubuntu]

  optional_commands :psql => 'psql'
  optional_commands :su => 'su'

  def create
    stm = "create role %s encrypted password '%s'" % [\
        @resource.value(:name), @resource.value(:password) ]

    if @resource.value(:createdb) == true
        stm = stm + " createdb"
    else
        stm = stm + " nocreatedb"
    end

    if @resource.value(:inherit) == false
        stm = stm + " noinherit"
    else
        stm = stm + " inherit"
    end

    if @resource.value(:login) == false
        stm = stm + " nologin"
    else
        stm = stm + " login"
    end

    if @resource.value(:createrole) == true
        stm = stm + " createrole"
    else
        stm = stm + " nocreaterole"
    end

    if @resource.value(:superuser) == true
        stm = stm + " superuser"
    else
        stm = stm + " nosuperuser"
    end

    su("-", "postgres", "-c", "psql -c \"%s\"" % stm)
  end

  def destroy
    su("-", "postgres", "-c", "dropuser %s" % [ @resource.value(:name) ])
  end

  def exists?
    su_output = su("-", "postgres", "-c", "psql --quiet -A -t -c \"select 1 from pg_roles where rolname = '%s';\"" % @resource.value(:name))
    return false if su_output.length == 0
    su_output.each do |line|
      if line == "1\n"
        return true
      else
        return false
      end
    end
  end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
safeguard-devise-0.0.7 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb
safeguard-devise-0.0.6 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb
safeguard-devise-0.0.5 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb
safeguard-devise-0.0.4 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb
safeguard-devise-0.0.3 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb
safeguard-devise-0.0.2 puppet/modules/postgresql/lib/puppet/provider/pg_user/debian_postgresql.rb