Skip to content

Commit

Permalink
Merge pull request #91 from reidmv/feature/master/priv_validation
Browse files Browse the repository at this point in the history
Add priv validation to database_grant provider
  • Loading branch information
Branan Purvine-Riley committed Aug 24, 2012
2 parents 606e7c5 + 8dac527 commit 796e25b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/puppet/provider/database_grant/mysql.rb
Expand Up @@ -171,7 +171,28 @@ def privileges=(privs)
# puts "set:", set
stmt = stmt << set << where

validate_privs privs, all_privs
mysql "mysql", "-Be", stmt
mysql_flush
end

def validate_privs(set_privs, all_privs)
all_privs = all_privs.collect { |p| p.downcase }
set_privs = set_privs.collect { |p| p.downcase }
invalid_privs = Array.new
hints = Array.new
# Test each of the user provided privs to see if they exist in all_privs
set_privs.each do |priv|
invalid_privs << priv unless all_privs.include?(priv)
hints << "#{priv}_priv" if all_privs.include?("#{priv}_priv")
end
unless invalid_privs.empty?
# Print a decently helpful and gramatically correct error message
hints = "Did you mean '#{hints.join(',')}'?" unless hints.empty?
p = invalid_privs.size > 1 ? ['s', 'are not valid'] : ['', 'is not valid']
detail = ["The privilege#{p[0]} '#{invalid_privs.join(',')}' #{p[1]}."]
fail [detail, hints].join(' ')
end
end

end

0 comments on commit 796e25b

Please sign in to comment.