Skip to content

Commit 585bd32

Browse files
author
Joshua Spence
committed
Add support for GRANTS FUNCTION
Fixes MODULES-2075.
1 parent 9419870 commit 585bd32

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/puppet/provider/mysql.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ def self.cmd_table(table)
7979
# We can't escape *.* so special case this.
8080
table_string << if table == '*.*'
8181
'*.*'
82-
# Special case also for PROCEDURES
83-
elsif table.start_with?('PROCEDURE ')
84-
table.sub(%r{^PROCEDURE (.*)(\..*)}, 'PROCEDURE `\1`\2')
82+
# Special case also for FUNCTIONs and PROCEDUREs
83+
elsif table.start_with?('FUNCTION ', 'PROCEDURE ')
84+
table.sub(%r{^(FUNCTION|PROCEDURE) (.*)(\..*)}, '\1 `\2`\3')
8585
else
8686
table.sub(%r{^(.*)(\..*)}, '`\1`\2')
8787
end

spec/acceptance/types/mysql_grant_spec.rb

+32
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,38 @@ class { 'mysql::server':
422422
end
423423
end
424424

425+
describe 'adding function privileges' do
426+
it 'works without errors' do
427+
pp = <<-EOS
428+
exec { 'simplefunc-create':
429+
command => '/usr/bin/mysql --user="root" --password="password" --database=mysql -NBe "CREATE FUNCTION simplefunc (s CHAR(20)) RETURNS CHAR(50) DETERMINISTIC RETURN CONCAT(\\'Hello, \\', s, \\'!\\')"',
430+
before => Mysql_user['test3@tester'],
431+
}
432+
433+
mysql_user { 'test3@tester':
434+
ensure => 'present',
435+
}
436+
437+
mysql_grant { 'test3@tester/FUNCTION mysql.simplefunc':
438+
ensure => 'present',
439+
table => 'FUNCTION mysql.simplefunc',
440+
user => 'test3@tester',
441+
privileges => ['EXECUTE'],
442+
require => Mysql_user['test3@tester'],
443+
}
444+
EOS
445+
446+
apply_manifest(pp, catch_failures: true)
447+
end
448+
449+
it 'finds the user' do
450+
shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r|
451+
expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'})
452+
expect(r.stderr).to be_empty
453+
end
454+
end
455+
end
456+
425457
describe 'proxy privilieges' do
426458
pre_run
427459

0 commit comments

Comments
 (0)