e315ee96d0
Should load the .my.cnf file with "--defaults-extra-file" instead of "--defaults-file". This is necessary if we have global my.cnf file but we want to use both of them.
66 lines
1.5 KiB
Ruby
66 lines
1.5 KiB
Ruby
class Puppet::Provider::Mysql < Puppet::Provider
|
|
|
|
# Without initvars commands won't work.
|
|
initvars
|
|
commands :mysql => 'mysql'
|
|
commands :mysqladmin => 'mysqladmin'
|
|
|
|
# Optional defaults file
|
|
def self.defaults_file
|
|
if File.file?("#{Facter.value(:root_home)}/.my.cnf")
|
|
"--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf"
|
|
else
|
|
nil
|
|
end
|
|
end
|
|
def defaults_file
|
|
self.class.defaults_file
|
|
end
|
|
|
|
def self.users
|
|
mysql([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n")
|
|
end
|
|
|
|
# Take root@localhost and munge it to 'root'@'localhost'
|
|
def self.cmd_user(user)
|
|
"'#{user.sub('@', "'@'")}'"
|
|
end
|
|
|
|
# Take root.* and return ON `root`.*
|
|
def self.cmd_table(table)
|
|
table_string = ''
|
|
|
|
# We can't escape *.* so special case this.
|
|
if table == '*.*'
|
|
table_string << '*.*'
|
|
else
|
|
table_string << table.sub(/^(.*)(\..*)/, '`\1`\2')
|
|
end
|
|
table_string
|
|
end
|
|
|
|
def self.cmd_privs(privileges)
|
|
if privileges.include?('ALL')
|
|
return 'ALL PRIVILEGES'
|
|
else
|
|
priv_string = ''
|
|
privileges.each do |priv|
|
|
priv_string << "#{priv}, "
|
|
end
|
|
end
|
|
# Remove trailing , from the last element.
|
|
priv_string.sub(/, $/, '')
|
|
end
|
|
|
|
# Take in potential options and build up a query string with them.
|
|
def self.cmd_options(options)
|
|
option_string = ''
|
|
options.each do |opt|
|
|
if opt == 'GRANT'
|
|
option_string << ' WITH GRANT OPTION'
|
|
end
|
|
end
|
|
option_string
|
|
end
|
|
|
|
end
|