Skip to content

Commit ae760d9

Browse files
committed
change existing users from native to caching without deleting user first
1 parent 4e48ee5 commit ae760d9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/puppet/provider/mysql_user/mysql.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,12 @@ def password_hash=(string)
169169
self.class.mysql_caller(sql, 'system')
170170
elsif !mysqld_version.nil? && newer_than('mysql' => '5.7.6', 'percona' => '5.7.6', 'mariadb' => '10.2.0')
171171
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)
172-
173172
sql = "ALTER USER #{merged_name} IDENTIFIED WITH"
174-
plugin == 'caching_sha2_password' ? sql += " '#{plugin}' AS X'#{@resource[:password_hash][2..-1]}'" : sql += " 'mysql_native_password' AS '#{@resource[:password_hash]}'"
173+
if plugin == 'caching_sha2_password'
174+
sql += " 'caching_sha2_password' AS X'#{string[2..-1]}'"
175+
else
176+
sql += " 'mysql_native_password' AS '#{string}'"
177+
end
175178
self.class.mysql_caller(sql, 'system')
176179
else
177180
# default ... if mysqld_version does not work
@@ -238,7 +241,7 @@ def plugin=(string)
238241
if string == 'mysql_native_password'
239242
sql += " AS '#{@resource[:password_hash]}'"
240243
elsif string == 'caching_sha2_password'
241-
sql += " AS X'#{password_hash[2..-1]}'"
244+
sql += " AS X'#{@resource[:password_hash][2..-1]}'"
242245
end
243246
else
244247
# See https://bugs.mysql.com/bug.php?id=67449

0 commit comments

Comments
 (0)