Skip to content

Commit d2f3899

Browse files
committed
Merge pull request #1005 from joshuaspence/grantfunction
Add support for `GRANTS FUNCTION`
2 parents 4f42ab9 + 585bd32 commit d2f3899

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/puppet/provider/mysql.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ def self.cmd_table(table)
8989
# We can't escape *.* so special case this.
9090
table_string << if table == '*.*'
9191
'*.*'
92-
# Special case also for PROCEDURES
93-
elsif table.start_with?('PROCEDURE ')
94-
table.sub(%r{^PROCEDURE (.*)(\..*)}, 'PROCEDURE `\1`\2')
92+
# Special case also for FUNCTIONs and PROCEDUREs
93+
elsif table.start_with?('FUNCTION ', 'PROCEDURE ')
94+
table.sub(%r{^(FUNCTION|PROCEDURE) (.*)(\..*)}, '\1 `\2`\3')
9595
else
9696
table.sub(%r{^(.*)(\..*)}, '`\1`\2')
9797
end

spec/acceptance/types/mysql_grant_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,38 @@ class { 'mysql::server':
454454
end
455455
end
456456

457+
describe 'adding function privileges' do
458+
it 'works without errors' do
459+
pp = <<-EOS
460+
exec { 'simplefunc-create':
461+
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, \\'!\\')"',
462+
before => Mysql_user['test3@tester'],
463+
}
464+
465+
mysql_user { 'test3@tester':
466+
ensure => 'present',
467+
}
468+
469+
mysql_grant { 'test3@tester/FUNCTION mysql.simplefunc':
470+
ensure => 'present',
471+
table => 'FUNCTION mysql.simplefunc',
472+
user => 'test3@tester',
473+
privileges => ['EXECUTE'],
474+
require => Mysql_user['test3@tester'],
475+
}
476+
EOS
477+
478+
apply_manifest(pp, catch_failures: true)
479+
end
480+
481+
it 'finds the user' do
482+
shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r|
483+
expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'})
484+
expect(r.stderr).to be_empty
485+
end
486+
end
487+
end
488+
457489
describe 'proxy privilieges' do
458490
pre_run
459491

0 commit comments

Comments
 (0)