X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/faf8ae12e85eabb050b0f5eceb2cb67ad1de5261..a0858dce1ce11c24de0103a341bc0ea8f75154ea:/cookbooks/mysql/providers/user.rb diff --git a/cookbooks/mysql/providers/user.rb b/cookbooks/mysql/providers/user.rb index e027b4f5c..c2f5e58d2 100644 --- a/cookbooks/mysql/providers/user.rb +++ b/cookbooks/mysql/providers/user.rb @@ -17,12 +17,14 @@ # limitations under the License. # +use_inline_resources + def load_current_resource @mysql = Chef::MySQL.new @current_resource = Chef::Resource::MysqlUser.new(new_resource.name) @current_resource.user(new_resource.user) - if mysql_user = @mysql.users[@current_resource.user] + if (mysql_user = @mysql.users[@current_resource.user]) Chef::MySQL::USER_PRIVILEGES.each do |privilege| @current_resource.send(privilege, mysql_user[privilege]) end @@ -42,17 +44,17 @@ action :create do end Chef::MySQL::USER_PRIVILEGES.each do |privilege| - if new_resource.send(privilege) != @current_resource.send(privilege) - if new_resource.send(privilege) - converge_by("grant #{privilege} for #{new_resource}") do - Chef::Log.info("Granting #{privilege} for #{new_resource}") - @mysql.execute(:command => "GRANT #{@mysql.privilege_name(privilege)} ON *.* TO #{user}") - end - else - converge_by("revoke #{privilege} for #{new_resource}") do - Chef::Log.info("Revoking #{privilege} for #{new_resource}") - @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON *.* FROM #{user}") - end + next if new_resource.send(privilege) == @current_resource.send(privilege) + + if new_resource.send(privilege) + converge_by("grant #{privilege} for #{new_resource}") do + Chef::Log.info("Granting #{privilege} for #{new_resource}") + @mysql.execute(:command => "GRANT #{@mysql.privilege_name(privilege)} ON *.* TO #{user}") + end + else + converge_by("revoke #{privilege} for #{new_resource}") do + Chef::Log.info("Revoking #{privilege} for #{new_resource}") + @mysql.execute(:command => "REVOKE #{@mysql.privilege_name(privilege)} ON *.* FROM #{user}") end end end