diff --git a/README.md b/README.md index a8bd09c..a6bd5e4 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,12 @@ pg_user "myuser" do password "mypassword" end +# create a user with an MD5-encrypted password +pg_user "myuser" do + privileges :superuser => false, :createdb => false, :login => true + encrypted_password "667ff118ef6d196c96313aeaee7da519" +end + # drop a user pg_user "myuser" do action :drop @@ -453,4 +459,4 @@ Many thanks go to the following who have contributed to making this cookbook eve * Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/2012/license.html). * Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper) -* http://phlippers.net/ +* http://phlippers.net/ \ No newline at end of file diff --git a/definitions/pg_user.rb b/definitions/pg_user.rb index ea3a7e5..a7bcfee 100644 --- a/definitions/pg_user.rb +++ b/definitions/pg_user.rb @@ -7,12 +7,14 @@ :login => true } privileges.merge! params[:privileges] if params[:privileges] - + sql = [params[:name]] - + sql.push privileges.to_a.map! { |p,b| (b ? '' : 'NO') + p.to_s.upcase }.join ' ' - if params[:password] + if params[:encrypted_password] + sql.push "ENCRYPTED PASSWORD '#{params[:encrypted_password]}'" + elsif params[:password] sql.push "PASSWORD '#{params[:password]}'" end @@ -24,7 +26,7 @@ execute "altering pg user #{params[:name]}" do user "postgres" - command "psql -c \"ALTER ROLE #{sql}\"" + command "psql -c \"ALTER ROLE #{sql}\"" only_if exists, :user => "postgres" end @@ -40,4 +42,4 @@ command "psql -c \"DROP ROLE IF EXISTS #{params[:name]}\"" end end -end +end \ No newline at end of file