Skip to content

Repair mysql_grant docs and diagnostics #1237

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 8, 2019
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 REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ The following parameters are available in the `mysql_grant` type.

namevar

Name to describe the grant.
Name to describe the grant. Must match *user*@*host*/*table*.

### mysql_plugin

Expand Down
22 changes: 11 additions & 11 deletions lib/puppet/type/mysql_grant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def initialize(*args)
end
# rubocop:enable Style/MultilineBlockChain
validate do
raise(_('`privileges` `parameter` is required.')) if self[:ensure] == :present && self[:privileges].nil?
raise(_('`privileges` `parameter`: PROXY can only be specified by itself.')) if Array(self[:privileges]).count > 1 && Array(self[:privileges]).include?('PROXY')
raise(_('`table` `parameter` is required.')) if self[:ensure] == :present && self[:table].nil?
raise(_('`user` `parameter` is required.')) if self[:ensure] == :present && self[:user].nil?
raise(_('mysql_grant: `privileges` `parameter` is required.')) if self[:ensure] == :present && self[:privileges].nil?
raise(_('mysql_grant: `privileges` `parameter`: PROXY can only be specified by itself.')) if Array(self[:privileges]).count > 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]
raise(_('`name` `parameter` must match user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}"
raise(_('mysql_grant: `name` `parameter` must match user@host/table format.')) if self[:name] != "#{self[:user]}/#{self[:table]}"
end
end

Expand All @@ -56,7 +56,7 @@ def initialize(*args)
validate do |value|
mysql_version = Facter.value(:mysql_version)
if value =~ %r{proxy}i && Puppet::Util::Package.versioncmp(mysql_version, '5.5.0') < 0
raise(ArgumentError, _('PROXY user not supported on mysql versions < 5.5.0. Current version %{version}.') % { version: mysql_version })
raise(ArgumentError, _('mysql_grant: PROXY user not supported on mysql versions < 5.5.0. Current version %{version}.') % { version: mysql_version })
end
end
end
Expand All @@ -66,7 +66,7 @@ def initialize(*args)

validate do |value|
if Array(@resource[:privileges]).include?('PROXY') && !%r{^[0-9a-zA-Z$_]*@[\w%\.:\-\/]*$}.match(value)
raise(ArgumentError, _('`table` `property` for PROXY should be specified as proxy_user@proxy_host.'))
raise(ArgumentError, _('mysql_grant: `table` `property` for PROXY should be specified as proxy_user@proxy_host.'))
end
end

Expand Down Expand Up @@ -95,15 +95,15 @@ def initialize(*args)
user_part = matches[1]
host_part = matches[2]
else
raise(ArgumentError, _('Invalid database user %{user}.') % { user: value })
raise(ArgumentError, _('mysql_grant: Invalid database user %{user}.') % { user: value })
end
# rubocop:enable Lint/AssignmentInCondition
# rubocop:enable Lint/UselessAssignment
mysql_version = Facter.value(:mysql_version)
unless mysql_version.nil?
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
raise(ArgumentError, _('MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 16 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '5.7.8') < 0 && user_part.size > 16
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 32 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') < 0 && user_part.size > 32
raise(ArgumentError, _('mysql_grant: MySQL usernames are limited to a maximum of 80 characters.')) if Puppet::Util::Package.versioncmp(mysql_version, '10.0.0') > 0 && user_part.size > 80
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/unit/puppet/type/mysql_grant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
it 'requires the name to match the user and table #specific' do
expect {
Puppet::Type.type(:mysql_grant).new(name: 'foo', privileges: ['ALL'], table: ['*.*'], user: 'foo@localhost')
}.to raise_error %r{`name` `parameter` must match user@host\/table format}
}.to raise_error %r{mysql_grant: `name` `parameter` must match user@host\/table format}
end

describe 'it should munge privileges' do
Expand Down