Skip to content
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

(MODULES-1545) Allow multiple mysql_grant for same user/table, but wi… #1547

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion lib/puppet/type/mysql_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,12 @@ def initialize(*args)
raise(_('mysql_grant: `privileges` `parameter`: PROXY can only be specified by itself.')) if Array(self[:privileges]).size > 1 && Array(self[:privileges]).include?('PROXY')
raise(_('mysql_grant: `table` `parameter` is required.')) if self[:ensure] == :present && self[:table].nil?
raise(_('mysql_grant: `user` `parameter` is required.')) if self[:ensure] == :present && self[:user].nil?
if self[:user] && self[:table]
if self[:user] && self[:table] && self[:tag].nil?
raise(_('mysql_grant: `name` `parameter` must match user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}"
end
if self[:user] && self[:table] && self[:tag]
raise(_('mysql_grant: `name` `parameter` must match tag:user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}" && self[:name] != "#{self[:tag][0]}:#{self[:user]}/#{self[:table]}"
end
end

newparam(:name, namevar: true) do
Expand Down
17 changes: 17 additions & 0 deletions spec/unit/puppet/type/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
}.to raise_error %r{mysql_grant: `name` `parameter` must match user@host\/table format}
end

it 'requires the name to match the user and table with tag #general' do
expect {
Puppet::Type.type(:mysql_grant).new(name: 'foo@localhost/*.*', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar')
}.not_to raise_error
end

it 'requires the name to match the user and table with tag, also in name #general' do
expect {
Puppet::Type.type(:mysql_grant).new(name: 'bar:foo@localhost/*.*', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar')
}.not_to raise_error
end
it 'requires the name to match the user and table with tag #specific' do
expect {
Puppet::Type.type(:mysql_grant).new(name: 'foo', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost', tag: 'bar')
}.to raise_error %r{mysql_grant: `name` `parameter` must match tag:user@host\/table format}
end

describe 'it should munge privileges' do
it 'to just ALL' do
user = Puppet::Type.type(:mysql_grant).new(
Expand Down