Class: Chef::Provider::Database::MysqlUser
- Inherits:
-
Mysql
- Object
- Chef::Provider
- Mysql
- Chef::Provider::Database::MysqlUser
- Includes:
- Mixin::ShellOut
- Defined in:
- lib/cookbooks/database/libraries/provider_database_mysql_user.rb
Instance Method Summary collapse
- #action_create ⇒ Object
- #action_drop ⇒ Object
- #action_grant ⇒ Object
- #load_current_resource ⇒ Object
Methods inherited from Mysql
Instance Method Details
#action_create ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/cookbooks/database/libraries/provider_database_mysql_user.rb', line 35 def action_create unless exists? begin db.query("CREATE USER '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'") @new_resource.updated_by_last_action(true) ensure close end end end |
#action_drop ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cookbooks/database/libraries/provider_database_mysql_user.rb', line 46 def action_drop if exists? begin db.query("DROP USER '#{@new_resource.username}'@'#{@new_resource.host}'") @new_resource.updated_by_last_action(true) ensure close end end end |
#action_grant ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cookbooks/database/libraries/provider_database_mysql_user.rb', line 57 def action_grant begin grant_statement = "GRANT #{@new_resource.privileges.join(', ')} ON #{@new_resource.database_name || "*"}.#{@new_resource.table || "*"} TO '#{@new_resource.username}'@'#{@new_resource.host}' IDENTIFIED BY '#{@new_resource.password}'" Chef::Log.info("#{@new_resource}: granting access with statement [#{grant_statement}]") db.query(grant_statement) @new_resource.updated_by_last_action(true) ensure close end end |
#load_current_resource ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/cookbooks/database/libraries/provider_database_mysql_user.rb', line 27 def load_current_resource Gem.clear_paths require 'mysql' @current_resource = Chef::Resource::DatabaseUser.new(@new_resource.name) @current_resource.username(@new_resource.name) @current_resource end |