Skip to content

Commit

Permalink
rubocop linting
Browse files Browse the repository at this point in the history
  • Loading branch information
C24-AK committed Feb 23, 2024
1 parent ae760d9 commit 491fca1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/puppet/functions/mysql/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
''
Expand Down
14 changes: 8 additions & 6 deletions lib/puppet/provider/mysql_user/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 491fca1

Please sign in to comment.