Class: Chef::Provider::Database::PostgresqlUser
- Inherits:
-
Postgresql
- Object
- Chef::Provider
- Postgresql
- Chef::Provider::Database::PostgresqlUser
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/cookbooks/database/libraries/provider_database_postgresql_user.rb
Instance Method Summary collapse
- #action_create ⇒ Object
- #action_drop ⇒ Object
- #action_grant ⇒ Object
- #load_current_resource ⇒ Object
Methods inherited from Postgresql
Instance Method Details
#action_create ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/cookbooks/database/libraries/provider_database_postgresql_user.rb', line 36 def action_create unless exists? begin db("template1").query("CREATE USER #{@new_resource.username} WITH PASSWORD '#{@new_resource.password}'") @new_resource.updated_by_last_action(true) ensure close end end end |
#action_drop ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/cookbooks/database/libraries/provider_database_postgresql_user.rb', line 47 def action_drop if exists? begin db("template1").query("DROP USER #{@new_resource.username}") @new_resource.updated_by_last_action(true) ensure close end end end |
#action_grant ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cookbooks/database/libraries/provider_database_postgresql_user.rb', line 58 def action_grant begin # FIXME: grants on individual tables grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON DATABASE #{@new_resource.database_name} TO #{@new_resource.username}" Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]") db(@new_resource.database_name).query(grant_statement) @new_resource.updated_by_last_action(true) ensure close end end |
#load_current_resource ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/cookbooks/database/libraries/provider_database_postgresql_user.rb', line 28 def load_current_resource Gem.clear_paths require 'pg' @current_resource = Chef::Resource::DatabaseUser.new(@new_resource.name) @current_resource.username(@new_resource.name) @current_resource end |