Class: Puppet::Provider::Mysql
- Inherits:
-
Puppet::Provider
- Object
- Puppet::Provider
- Puppet::Provider::Mysql
- Defined in:
- lib/puppet/provider/mysql.rb
Class Method Summary collapse
-
.cmd_options(options) ⇒ Object
Take in potential options and build up a query string with them.
- .cmd_privs(privileges) ⇒ Object
-
.cmd_table(table) ⇒ Object
Take root.* and return ON ‘root`.*.
-
.cmd_user(user) ⇒ Object
Take root@localhost and munge it to ‘root’@‘localhost’.
-
.defaults_file ⇒ Object
Optional defaults file.
- .users ⇒ Object
Instance Method Summary collapse
Class Method Details
.cmd_options(options) ⇒ Object
Take in potential options and build up a query string with them.
60 61 62 63 64 65 66 67 68 |
# File 'lib/puppet/provider/mysql.rb', line 60 def self.() option_string = '' .each do |opt| if opt == 'GRANT' option_string << ' WITH GRANT OPTION' end end option_string end |
.cmd_privs(privileges) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/puppet/provider/mysql.rb', line 46 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 |
.cmd_table(table) ⇒ Object
Take root.* and return ON ‘root`.*
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/puppet/provider/mysql.rb', line 31 def self.cmd_table(table) table_string = '' # We can't escape *.* so special case this. if table == '*.*' table_string << '*.*' # Special case also for PROCEDURES elsif table.start_with?('PROCEDURE ') table_string << table.sub(/^PROCEDURE (.*)(\..*)/, 'PROCEDURE `\1`\2') else table_string << table.sub(/^(.*)(\..*)/, '`\1`\2') end table_string end |
.cmd_user(user) ⇒ Object
Take root@localhost and munge it to ‘root’@‘localhost’
26 27 28 |
# File 'lib/puppet/provider/mysql.rb', line 26 def self.cmd_user(user) "'#{user.sub('@', "'@'")}'" end |
.defaults_file ⇒ Object
Optional defaults file
9 10 11 12 13 14 15 |
# File 'lib/puppet/provider/mysql.rb', line 9 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 |
.users ⇒ Object
21 22 23 |
# File 'lib/puppet/provider/mysql.rb', line 21 def self.users mysql([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n") end |
Instance Method Details
#defaults_file ⇒ Object
17 18 19 |
# File 'lib/puppet/provider/mysql.rb', line 17 def defaults_file self.class.defaults_file end |