X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/3a4b1c2078cd515e93a5f1bf8967f380fbd1646f..3d3fad5515ff453e5d60dd012e20f130639ee61d:/cookbooks/mysql/libraries/mysql.rb diff --git a/cookbooks/mysql/libraries/mysql.rb b/cookbooks/mysql/libraries/mysql.rb index bc5dd3350..61d600f1d 100644 --- a/cookbooks/mysql/libraries/mysql.rb +++ b/cookbooks/mysql/libraries/mysql.rb @@ -11,14 +11,14 @@ class Chef :show_db, :super, :create_tmp_table, :lock_tables, :execute, :repl_slave, :repl_client, :create_view, :show_view, :create_routine, :alter_routine, :create_user, :event, :trigger, :create_tablespace - ] + ].freeze DATABASE_PRIVILEGES = [ :select, :insert, :update, :delete, :create, :drop, :grant, :references, :index, :alter, :create_tmp_table, :lock_tables, :create_view, :show_view, :create_routine, :alter_routine, :execute, :event, :trigger - ] + ].freeze def execute(options) # Create argument array @@ -87,34 +87,31 @@ class Chef end def users - @users ||= query("SELECT * FROM user").inject({}) do |users, user| + @users ||= query("SELECT * FROM user").each_with_object({}) do |user, users| name = "'#{user[:user]}'@'#{user[:host]}'" - users[name] = USER_PRIVILEGES.inject({}) do |privileges, privilege| + users[name] = USER_PRIVILEGES.each_with_object({}) do |privilege, privileges| privileges[privilege] = user["#{privilege}_priv".to_sym] == "Y" - privileges end - - users end end def databases - @databases ||= query("SHOW databases").inject({}) do |databases, database| + @databases ||= query("SHOW databases").each_with_object({}) do |database, databases| databases[database[:database]] = { :permissions => {} } - databases end query("SELECT * FROM db").each do |record| - if database = @databases[record[:db]] - user = "'#{record[:user]}'@'#{record[:host]}'" + database = @databases[record[:db]] + + next unless database + + user = "'#{record[:user]}'@'#{record[:host]}'" - database[:permissions][user] = DATABASE_PRIVILEGES.inject([]) do |privileges, privilege| - privileges << privilege if record["#{privilege}_priv".to_sym] == "Y" - privileges - end + database[:permissions][user] = DATABASE_PRIVILEGES.each_with_object([]) do |privilege, privileges| + privileges << privilege if record["#{privilege}_priv".to_sym] == "Y" end end