Add mysql argument to use mysql database back

This commit is contained in:
Hunter Haugen 2012-10-09 13:44:54 -07:00
parent 24444ce119
commit 64d38890c6
3 changed files with 13 additions and 13 deletions

View file

@ -87,7 +87,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
end end
def destroy def destroy
mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-e", "REVOKE ALL ON '%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database], @resource[:name], @resource[:host] ] mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-e", "REVOKE ALL ON '%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database], @resource[:name], @resource[:host] ]
end end
def row_exists? def row_exists?
@ -96,7 +96,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
if name[:type] == :db if name[:type] == :db
fields << :db fields << :db
end end
not mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", 'mysql', '-NBe', 'SELECT "1" FROM %s WHERE %s' % [ name[:type], fields.map do |f| "%s=\"%s\"" % [f, name[f]] end.join(' AND ')]).empty? not mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", '-NBe', 'SELECT "1" FROM %s WHERE %s' % [ name[:type], fields.map do |f| "%s=\"%s\"" % [f, name[f]] end.join(' AND ')]).empty?
end end
def all_privs_set? def all_privs_set?
@ -118,9 +118,9 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
case name[:type] case name[:type]
when :user when :user
privs = mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-Be", 'select * from mysql.user where user="%s" and host="%s"' % [ name[:user], name[:host] ] privs = mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-Be", 'select * from mysql.user where user="%s" and host="%s"' % [ name[:user], name[:host] ]
when :db when :db
privs = mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-Be", 'select * from mysql.db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ] privs = mysql "--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-Be", 'select * from mysql.db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
end end
if privs.match(/^$/) if privs.match(/^$/)

View file

@ -8,30 +8,30 @@ Puppet::Type.type(:database_user).provide(:mysql) do
optional_commands :mysqladmin => 'mysqladmin' optional_commands :mysqladmin => 'mysqladmin'
def self.instances def self.instances
users = mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", '-BNe' "select concat(User, '@',Host) as User from mysql.user").split("\n") users = mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", '-BNe' "select concat(User, '@',Host) as User from mysql.user").split("\n")
users.select{ |user| user =~ /.+@/ }.collect do |name| users.select{ |user| user =~ /.+@/ }.collect do |name|
new(:name => name) new(:name => name)
end end
end end
def create def create
mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.value(:password_hash) ]) mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.value(:password_hash) ])
end end
def destroy def destroy
mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-e", "drop user '%s'" % @resource.value(:name).sub("@", "'@'") ) mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-e", "drop user '%s'" % @resource.value(:name).sub("@", "'@'") )
end end
def password_hash def password_hash
mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-NBe", "select password from mysql.user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).chomp mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-NBe", "select password from mysql.user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).chomp
end end
def password_hash=(string) def password_hash=(string)
mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] ) mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] )
end end
def exists? def exists?
not mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "-NBe", "select '1' from mysql.user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).empty? not mysql("--defaults-file=#{Facter.value(:root_home)}/.my.cnf", "mysql", "-NBe", "select '1' from mysql.user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).empty?
end end
def flush def flush

View file

@ -40,7 +40,7 @@ EOT
end end
it 'should query set priviliges' do it 'should query set priviliges' do
provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT
Host User Password Select_priv Insert_priv Update_priv Host User Password Select_priv Insert_priv Update_priv
host user Y N Y host user Y N Y
EOT EOT
@ -48,7 +48,7 @@ EOT
end end
it 'should recognize when all priviliges are set' do it 'should recognize when all priviliges are set' do
provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT
Host User Password Select_priv Insert_priv Update_priv Host User Password Select_priv Insert_priv Update_priv
host user Y Y Y host user Y Y Y
EOT EOT
@ -56,7 +56,7 @@ EOT
end end
it 'should recognize when all privileges are not set' do it 'should recognize when all privileges are not set' do
provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT provider_class.expects(:mysql).with("--defaults-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'select * from mysql.user where user="user" and host="host"').returns <<-EOT
Host User Password Select_priv Insert_priv Update_priv Host User Password Select_priv Insert_priv Update_priv
host user Y N Y host user Y N Y
EOT EOT