diff --git a/lib/puppet/functions/mysql/password.rb b/lib/puppet/functions/mysql/password.rb index a865305eb..c094bfa08 100644 --- a/lib/puppet/functions/mysql/password.rb +++ b/lib/puppet/functions/mysql/password.rb @@ -22,7 +22,7 @@ def password(password, sensitive = false) password = password.unwrap if password.is_a?(Puppet::Pops::Types::PSensitiveType::Sensitive) - result_string = if %r{\*[A-F0-9]{40}$}.match?(password) or %r{0x[A-F0-9]+$}.match?(password) + result_string = if %r{\*[A-F0-9]{40}$}.match?(password) || %r{0x[A-F0-9]+$}.match?(password) password elsif password.empty? '' diff --git a/lib/puppet/provider/mysql_user/mysql.rb b/lib/puppet/provider/mysql_user/mysql.rb index a04f93052..4d1fa1eea 100644 --- a/lib/puppet/provider/mysql_user/mysql.rb +++ b/lib/puppet/provider/mysql_user/mysql.rb @@ -23,10 +23,10 @@ def self.instances # rubocop:enable Layout/LineLength @max_user_connections, @max_connections_per_hour, @max_queries_per_hour, @max_updates_per_hour, ssl_type, ssl_cipher, x509_issuer, x509_subject, @password, @plugin, @authentication_string = mysql_caller(query, 'regular').chomp.split(%r{\t}) - + if @plugin == 'caching_sha2_password' # Escaping all single quotes to prevent errors when password generated it - @password = @password.gsub("'"){"\\'"} + @password = @password.gsub("'") { "\\'" } @password = mysql_caller("SELECT CONCAT('0x',HEX('#{@password}'))", 'regular').chomp end @@ -83,7 +83,7 @@ def create if !plugin.nil? if password_hash.nil? self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}'", 'system') - elsif plugin.eql? "caching_sha2_password" + elsif plugin.eql? 'caching_sha2_password' self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS X'#{password_hash[2..-1]}'", 'system') else self.class.mysql_caller("CREATE USER '#{merged_name}' IDENTIFIED WITH '#{plugin}' AS '#{password_hash}'", 'system') @@ -168,12 +168,14 @@ def password_hash=(string) end self.class.mysql_caller(sql, 'system') elsif !mysqld_version.nil? && newer_than('mysql' => '5.7.6', 'percona' => '5.7.6', 'mariadb' => '10.2.0') - raise ArgumentError, _('Only mysql_native_password (*ABCD...XXX) or caching_sha2_password (0x1234ABC...XXX) hashes are supported.') unless %r{^\*|^$}.match?(string) || %r{0x[A-F0-9]+$}.match?(string) + raise ArgumentError, _('Only mysql_native_password (*ABCD...XXX) or caching_sha2_password (0x1234ABC...XXX) hashes are supported.') unless + %r{^\*|^$}.match?(string) || %r{0x[A-F0-9]+$}.match?(string) + sql = "ALTER USER #{merged_name} IDENTIFIED WITH" if plugin == 'caching_sha2_password' - sql += " 'caching_sha2_password' AS X'#{string[2..-1]}'" + sql << " 'caching_sha2_password' AS X'#{string[2..-1]}'" else - sql += " 'mysql_native_password' AS '#{string}'" + sql << " 'mysql_native_password' AS '#{string}'" end self.class.mysql_caller(sql, 'system') else