Skip to content

Add support for GRANTS FUNCTION #1005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/puppet/provider/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ def self.cmd_table(table)
# We can't escape *.* so special case this.
table_string << if table == '*.*'
'*.*'
# Special case also for PROCEDURES
elsif table.start_with?('PROCEDURE ')
table.sub(%r{^PROCEDURE (.*)(\..*)}, 'PROCEDURE `\1`\2')
# Special case also for FUNCTIONs and PROCEDUREs
elsif table.start_with?('FUNCTION ', 'PROCEDURE ')
table.sub(%r{^(FUNCTION|PROCEDURE) (.*)(\..*)}, '\1 `\2`\3')
else
table.sub(%r{^(.*)(\..*)}, '`\1`\2')
end
Expand Down
32 changes: 32 additions & 0 deletions spec/acceptance/types/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,38 @@ class { 'mysql::server':
end
end

describe 'adding function privileges' do
it 'works without errors' do
pp = <<-EOS
exec { 'simplefunc-create':
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, \\'!\\')"',
before => Mysql_user['test3@tester'],
}

mysql_user { 'test3@tester':
ensure => 'present',
}

mysql_grant { 'test3@tester/FUNCTION mysql.simplefunc':
ensure => 'present',
table => 'FUNCTION mysql.simplefunc',
user => 'test3@tester',
privileges => ['EXECUTE'],
require => Mysql_user['test3@tester'],
}
EOS

apply_manifest(pp, catch_failures: true)
end

it 'finds the user' do
shell('mysql -NBe "SHOW GRANTS FOR test3@tester"') do |r|
expect(r.stdout).to match(%r{GRANT EXECUTE ON FUNCTION `mysql`.`simplefunc` TO 'test3'@'tester'})
expect(r.stderr).to be_empty
end
end
end

describe 'proxy privilieges' do
pre_run

Expand Down