add column grant to mysql_grant
This commit is contained in:
parent
1faf0b322f
commit
ae6dab7c25
2 changed files with 38 additions and 2 deletions
|
@ -26,6 +26,8 @@ MYSQL_TABLE_PRIVS = [ :select_priv, :insert_priv, :update_priv, :delete_priv,
|
||||||
:trigger_priv
|
:trigger_priv
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MYSQL_COLUMN_PRIVS = [ :select_priv, :insert_priv, :update_priv, :references_priv ]
|
||||||
|
|
||||||
Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
|
|
||||||
desc "Uses mysql as database."
|
desc "Uses mysql as database."
|
||||||
|
@ -39,7 +41,7 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
|
|
||||||
# this parses the
|
# this parses the
|
||||||
def split_name(string)
|
def split_name(string)
|
||||||
matches = /^([^@]*)@([^\/]*)(\/(.*))?(\/(.*))?$/.match(string).captures.compact
|
matches = /^([^@]*)@([^\/]*)(\/(.*))?(\/(.*))?(\/(.*))?$/.match(string).captures.compact
|
||||||
case matches.length
|
case matches.length
|
||||||
when 2
|
when 2
|
||||||
{
|
{
|
||||||
|
@ -62,6 +64,15 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
:db => matches[3],
|
:db => matches[3],
|
||||||
:table => matches[5]
|
:table => matches[5]
|
||||||
}
|
}
|
||||||
|
when 8
|
||||||
|
{
|
||||||
|
:type => :table,
|
||||||
|
:user => matches[0],
|
||||||
|
:host => matches[1],
|
||||||
|
:db => matches[3],
|
||||||
|
:table => matches[5],
|
||||||
|
:column => matches[7]
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -81,6 +92,10 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
mysql "mysql", "-e", "INSERT INTO tables_priv (host, user, db, table) VALUES ('%s', '%s', '%s', '%s')" % [
|
mysql "mysql", "-e", "INSERT INTO tables_priv (host, user, db, table) VALUES ('%s', '%s', '%s', '%s')" % [
|
||||||
name[:host], name[:user], name[:db], name[:table],
|
name[:host], name[:user], name[:db], name[:table],
|
||||||
]
|
]
|
||||||
|
when :column
|
||||||
|
mysql "mysql", "-e", "INSERT INTO columns_priv (host, user, db, table, column_name) VALUES ('%s', '%s', '%s', '%s', '%s')" % [
|
||||||
|
name[:host], name[:user], name[:db], name[:table], name[:column],
|
||||||
|
]
|
||||||
end
|
end
|
||||||
mysql_flush
|
mysql_flush
|
||||||
end
|
end
|
||||||
|
@ -99,6 +114,9 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
if name[:type] == :table
|
if name[:type] == :table
|
||||||
fields << :table
|
fields << :table
|
||||||
end
|
end
|
||||||
|
if name[:type] == :column
|
||||||
|
fields << :column
|
||||||
|
end
|
||||||
not mysql( "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( "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
|
||||||
|
|
||||||
|
@ -110,6 +128,8 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
MYSQL_DB_PRIVS
|
MYSQL_DB_PRIVS
|
||||||
when :table
|
when :table
|
||||||
MYSQL_TABLE_PRIVS
|
MYSQL_TABLE_PRIVS
|
||||||
|
when :column
|
||||||
|
MYSQL_COLUMN_PRIVS
|
||||||
end
|
end
|
||||||
all_privs = all_privs.collect do |p| p.to_s end.sort.join("|")
|
all_privs = all_privs.collect do |p| p.to_s end.sort.join("|")
|
||||||
privs = privileges.collect do |p| p.to_s end.sort.join("|")
|
privs = privileges.collect do |p| p.to_s end.sort.join("|")
|
||||||
|
@ -128,6 +148,8 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
privs = mysql "mysql", "-Be", 'select * from db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
|
privs = mysql "mysql", "-Be", 'select * from db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
|
||||||
when :table
|
when :table
|
||||||
privs = mysql "mysql", "-Be", 'select * from tables_priv where User="%s" and Host="%s" and Db="%s" and Table="%s"' % [ name[:user], name[:host], name[:db], name[:table] ]
|
privs = mysql "mysql", "-Be", 'select * from tables_priv where User="%s" and Host="%s" and Db="%s" and Table="%s"' % [ name[:user], name[:host], name[:db], name[:table] ]
|
||||||
|
when :column
|
||||||
|
privs = mysql "mysql", "-Be", 'select * from columns_priv where User="%s" and Host="%s" and Db="%s" and Table_name="%s" and Column_name="%s"' % [ name[:user], name[:host], name[:db], name[:table], name[:column] ]
|
||||||
end
|
end
|
||||||
|
|
||||||
if privs.match(/^$/)
|
if privs.match(/^$/)
|
||||||
|
@ -165,7 +187,11 @@ Puppet::Type.type(:mysql_grant).provide(:mysql) do
|
||||||
when :table
|
when :table
|
||||||
stmt = 'update table_priv set '
|
stmt = 'update table_priv set '
|
||||||
where = ' where user="%s" and host="%s" and Db="%s"' % [ name[:user], name[:host], name[:db] ]
|
where = ' where user="%s" and host="%s" and Db="%s"' % [ name[:user], name[:host], name[:db] ]
|
||||||
all_privs = MYSQL_DB_PRIVS
|
all_privs = MYSQL_DB_PRIVS
|
||||||
|
when :column
|
||||||
|
stmt = 'update columns_priv set '
|
||||||
|
where = ' where user="%s" and host="%s" and Db="%s" and Table="%s"' % [ name[:user], name[:host], name[:db], name[:table] ]
|
||||||
|
all_privs = MYSQL_DB_PRIVS
|
||||||
end
|
end
|
||||||
|
|
||||||
if privs[0] == :all
|
if privs[0] == :all
|
||||||
|
|
|
@ -5,6 +5,16 @@ Puppet::Type.newtype(:mysql_grant) do
|
||||||
#ensurable
|
#ensurable
|
||||||
autorequire(:service) { 'mysqld' }
|
autorequire(:service) { 'mysqld' }
|
||||||
|
|
||||||
|
autorequire :mysql_table do
|
||||||
|
reqs = []
|
||||||
|
matches = self[:name].match(/^([^@]*)@([^\/]*)\/(.+)\/(.+)$/)
|
||||||
|
unless matches.nil?
|
||||||
|
reqs << matches[4]
|
||||||
|
end
|
||||||
|
# puts "Autoreq: '%s'" % reqs.join(" ")
|
||||||
|
reqs
|
||||||
|
end
|
||||||
|
|
||||||
autorequire :mysql_db do
|
autorequire :mysql_db do
|
||||||
# puts "Starting db autoreq for %s" % self[:name]
|
# puts "Starting db autoreq for %s" % self[:name]
|
||||||
reqs = []
|
reqs = []
|
||||||
|
|
Loading…
Reference in a new issue