<commit_before>Puppet::Type.type(:database_user).provide(:mysql) do

  desc 'manage users for a mysql database.'

  defaultfor :kernel => 'Linux'

  optional_commands :mysql => 'mysql'
  optional_commands :mysqladmin => 'mysqladmin'

  def self.instances
    users = mysql([defaults_file, 'mysql', '-BNe' "select concat(User, '@',Host) as User from mysql.user"].compact).split("\n")
    users.select { |user| user =~ /.+@/ }.collect do |name|
      new(:name => name)
    end
  end

  def create
    merged_name = @resource[:name].sub('@', "'@'")
    password_hash = @resource.value(:password_hash)
    max_user_connections = @resource.value(:max_user_connections) || 0

    mysql([defaults_file, 'mysql', '-e', "create user '#{merged_name}' identified by PASSWORD
      '#{password_hash}' with max_user_connections #{max_user_connections}"].compact)

    exists? ? (return true) : (return false)
  end

  def destroy
    merged_name = @resource[:name].sub('@', "'@'")
    mysql([defaults_file, 'mysql', '-e', "drop user '#{merged_name}'"].compact)

    exists? ? (return false) : (return true)
  end

  def password_hash
    mysql([defaults_file, 'mysql', '-NBe', "select authentication_string from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp
  end

  def password_hash=(string)
    mysql([defaults_file, 'mysql', '-e', "ALTER USER '%s' IDENTIFIED BY '%s'" % [@resource[:name].sub('@', "'@'"), string]].compact)

    password_hash == string ? (return true) : (return false)
  end

  def max_user_connections
    mysql([defaults_file, "mysql", "-NBe", "select max_user_connections from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp
  end

  def max_user_connections=(int)
    mysql([defaults_file, "mysql", "-e", "grant usage on *.* to '%s' with max_user_connections #{int}" % [@resource[:name].sub("@", "'@'")]].compact).chomp

    max_user_connections == int ? (return true) : (return false)<commit_msg>Fix alter mysql user password<commit_after>Puppet::Type.type(:database_user).provide(:mysql) do

  desc 'manage users for a mysql database.'

  defaultfor :kernel => 'Linux'

  optional_commands :mysql => 'mysql'
  optional_commands :mysqladmin => 'mysqladmin'

  def self.instances
    users = mysql([defaults_file, 'mysql', '-BNe' "select concat(User, '@',Host) as User from mysql.user"].compact).split("\n")
    users.select { |user| user =~ /.+@/ }.collect do |name|
      new(:name => name)
    end
  end

  def create
    merged_name = @resource[:name].sub('@', "'@'")
    password_hash = @resource.value(:password_hash)
    max_user_connections = @resource.value(:max_user_connections) || 0

    mysql([defaults_file, 'mysql', '-e', "create user '#{merged_name}' identified by PASSWORD
      '#{password_hash}' with max_user_connections #{max_user_connections}"].compact)

    exists? ? (return true) : (return false)
  end

  def destroy
    merged_name = @resource[:name].sub('@', "'@'")
    mysql([defaults_file, 'mysql', '-e', "drop user '#{merged_name}'"].compact)

    exists? ? (return false) : (return true)
  end

  def password_hash
    mysql([defaults_file, 'mysql', '-NBe', "select authentication_string from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp
  end

  def password_hash=(string)
    mysql([defaults_file, 'mysql', '-e', "ALTER USER '%s' IDENTIFIED WITH mysql_native_password AS '%s'" % [@resource[:name].sub('@', "'@'"), string]].compact)

    password_hash == string ? (return true) : (return false)
  end

  def max_user_connections
    mysql([defaults_file, "mysql", "-NBe", "select max_user_connections from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp
  end

  def max_user_connections=(int)
    mysql([defaults_file, "mysql", "-e", "grant usage on *.* to '%s' with max_user_connections #{int}" % [@resource[:name].sub("@", "'@'")]].compact).chomp

    max_user_connections == int ? (return true) : (return false)
{'fraction_non_alphanumeric': 0.18295426143464133, 'fraction_numerical': 0.0004998750312421895, 'mean_word_length': 4.612903225806452, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3518745', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1265, 'n_words': 313}