Skip to content

Further improvements to our matching - stop trying to guess what #319

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 2 commits into from
Oct 11, 2013
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
2 changes: 1 addition & 1 deletion lib/puppet/provider/mysql_grant/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def self.instances
# Match the munges we do in the type.
munged_grant = grant.delete("'").delete("`")
# Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION)
if match = munged_grant.match(/^GRANT\s(.+)\sON\s(.+)\sTO\s([\w.:]+)@([\w.:\/]+)(\s.*)$/)
if match = munged_grant.match(/^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)$/)
privileges, table, user, host, rest = match.captures
# Once we split privileges up on the , we need to make sure we
# shortern ALL PRIVILEGES to just all.
Expand Down
60 changes: 60 additions & 0 deletions spec/system/types/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -224,4 +224,64 @@ class { 'mysql::server': }
end
end

describe 'complex test' do
it 'setup mysql::server' do
pp = <<-EOS
$dbSubnet = '10.10.10.%'

mysql_database { 'foo':
ensure => present,
}

exec { 'mysql-create-table':
command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"',
environment => "HOME=${::root_home}",
unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"',
require => Mysql_database['foo'],
}

Mysql_grant {
ensure => present,
options => ['GRANT'],
privileges => ['ALL'],
table => '*.*',
require => [ Mysql_database['foo'], Exec['mysql-create-table'] ],
}

mysql_grant { "user1@${dbSubnet}/*.*":
user => "user1@${dbSubnet}",
}
mysql_grant { "user2@${dbSubnet}/foo.bar":
privileges => ['SELECT', 'INSERT', 'UPDATE'],
user => "user2@${dbSubnet}",
table => 'foo.bar',
}
mysql_grant { "user3@${dbSubnet}/foo.*":
privileges => ['SELECT', 'INSERT', 'UPDATE'],
user => "user3@${dbSubnet}",
table => 'foo.*',
}
mysql_grant { 'web@%/*.*':
user => 'web@%',
}
mysql_grant { "web@${dbSubnet}/*.*":
user => "web@${dbSubnet}",
}
mysql_grant { "web@${fqdn}/*.*":
user => "web@${fqdn}",
}
mysql_grant { 'web@localhost/*.*':
user => 'web@localhost',
}
EOS

puppet_apply(pp) do |r|
r.exit_code.should_not == 1
r.refresh
r.exit_code.should be_zero
end
end
end


end