class Libriciel::GetConfig

 Class GetConfig for chef deploy

Public Class Methods

compare_files_iparapheur(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file) click to toggle source
# File lib/libriciel.rb, line 487
def self.compare_files_iparapheur(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
  ## Schema pour le Xmx
  ## default['iparapheur']['ctl']['xms'] pour le iParapheur
  ## ["-Xmx": "xxxxm", "-Xms": "xxxxm"] pour le parse_spec_conf
  if !default_config_file_parse[libriciel]
    default_config_file_parse[libriciel] = {}

  end

  case

  ## Xmx et Xms
  ## Lancement du parse pour voir les bonnes valeurs des Xmx et xms
  ## Puis mise en place dans le config.json au cas ou pas existant
  when File.readlines(conf_file).grep(/Xms|Xmx/).size > 0
    tableau = {}
    tabs = parse_spec_conf(conf_file, caracs_to_extract_from, tableau, nil)

    if !default_config_file_parse[libriciel]["ctl"]
      default_config_file_parse[libriciel]["ctl"] = {}

    end

    if default_config_file_parse[libriciel]["ctl"].empty?
     default_config_file_parse[libriciel]["ctl"] = default_config_file_parse[libriciel]["ctl"].merge(tabs)

    else
     default_config_file_parse[libriciel]["ctl"] = tabs



    end

  ## database vérification et surcharge des
  ## entrée dans le config.json pour régénération
  when File.readlines(conf_file).grep(/db./).size > 0
    conf_file_parse = JSON.parse(File.read(conf_file))
    if !default_config_file_parse[libriciel]["database"]
      default_config_file_parse[libriciel]["database"] = {}

    end

    conf_file_parse.keys.each do |valeur_tableau_configuration|

      if valeur_tableau_configuration.include? "db."
        case valeur_tableau_configuration
        when "db.username"
          default_config_file_parse[libriciel]["database"]["user"] = conf_file_parse[valeur_tableau_configuration]

        when "db.password"
          default_config_file_parse[libriciel]["database"]["password"] = conf_file_parse[valeur_tableau_configuration]

        when "db.name"
          default_config_file_parse[libriciel]["database"]["name"] = conf_file_parse[valeur_tableau_configuration]

        when "db.url"
          default_config_file_parse[libriciel]["database"]["host_conf"] = conf_file_parse[valeur_tableau_configuration].gsub("jdbc:mysql://", "").gsub(/\/#{conf_file_parse["db.name"]}\z/, "")

        end
      elsif valeur_tableau_configuration == "hostname"
        default_config_file_parse[libriciel]["fullname"] = conf_file_parse[valeur_tableau_configuration]

      elsif valeur_tableau_configuration == "mail.from"
        default_config_file_parse[libriciel]["domain"] = conf_file_parse[valeur_tableau_configuration].gsub(/\S*@/, "")

      end
    end
  else
    puts "autres parametres"
  end

  ## Ici pour surcharge de mes valeurs par défaut du config .JSON
  ## Qui est généré par défaut
  File.open("#{default_config_file}", "w") {|f| f.write(JSON.pretty_generate(default_config_file_parse))}
end
compare_files_pastell(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file) click to toggle source

 Partie pour Pastell à contnuer

# File lib/libriciel.rb, line 443
def self.compare_files_pastell(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)
  if !default_config_file_parse[libriciel]
    default_config_file_parse[libriciel] = {}

  end

  if File.readlines(conf_file).grep(/BD_/).size > 0
    conf_file_parse = JSON.parse(File.read(conf_file))
    if !default_config_file_parse[libriciel]["database"]
      default_config_file_parse[libriciel]["database"] = {}

    end

    conf_file_parse.keys.each do |valeur_tableau_configuration|

      if valeur_tableau_configuration.include? "BD_"
        case valeur_tableau_configuration
        when "BD_USER"
          default_config_file_parse[libriciel]["database"]["user"] = conf_file_parse[valeur_tableau_configuration]

        when "BD_PASS"
          default_config_file_parse[libriciel]["database"]["password"] = conf_file_parse[valeur_tableau_configuration]

        when "BD_DSN"

          default_config_file_parse[libriciel]["database"]["host_conf"] = conf_file_parse[valeur_tableau_configuration]

        end
      elsif valeur_tableau_configuration == "hostname"
        default_config_file_parse[libriciel]["fullname"] = conf_file_parse[valeur_tableau_configuration]

      elsif valeur_tableau_configuration == "mail.from"
        default_config_file_parse[libriciel]["domain"] = conf_file_parse[valeur_tableau_configuration].gsub(/\S*@/, "")

      end
    end
  end
end
compare_files_webdelib(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file) click to toggle source

 Partie pour Webdelib à continuer

# File lib/libriciel.rb, line 483
def self.compare_files_webdelib(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)

end
compare_json(template_json, conf_json, table_valeur_diff) click to toggle source

faire une seconde fonction qui va prendre le tableau généré par celle ci pour le lire et inscrire dans le conf.json parsé au bon endroit “iparapheur”: {} par exemple les valeurs pour etre ready pour la mise à jour

# File lib/libriciel.rb, line 633
def self.compare_json(template_json, conf_json, table_valeur_diff)
  if !FileUtils.compare_file(template_json, conf_json)

    template_file_json = JSON.parse(File.read(template_json))
    conf_file_json = JSON.parse(File.read(conf_json))

    template_file_json.keys.each do |keys_template_file_lvl_1|

      if !conf_file_json.keys.include? keys_template_file_lvl_1
        puts "#{keys_template_file_lvl_1}"
        puts "Attention pas bonne syntaxe de la configuration"
        exit 222
      else
        if conf_file_json[keys_template_file_lvl_1] == template_file_json[keys_template_file_lvl_1]

        else

          ## Les if suivants sur le conf_json sont exclusif pour le iParapheur et
          ## la mise en place de l'aborescence du config.json
          if File.basename(conf_json) == "iparapheur-global.properties.json"
            keys_template_file_ip = "ihm"

            if !table_valeur_diff[keys_template_file_ip]
              table_valeur_diff[keys_template_file_ip] = {}

            end
            table_valeur_diff["ihm"][keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]

          elsif File.basename(conf_json) == "alfresco-global.properties.json"
            keys_template_file_ip = "alf"

            if !table_valeur_diff[keys_template_file_ip]
              table_valeur_diff[keys_template_file_ip] = {}

            end
            table_valeur_diff["alf"][keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]

          else
            table_valeur_diff[keys_template_file_lvl_1] = conf_file_json[keys_template_file_lvl_1]

          end
        end
      end
    end

  else
    # Mettre en place gestion des erreurs et raises
  end

  # Return du tableau avec les infos à ajouter au tableau config.json parsé
  return table_valeur_diff
end
concat_config_json(config_json_file, tableau, libriciel) click to toggle source

 Fonction qui va prendre le tableau généré par celle ci pour le lire et inscrire dans le conf.json parsé au bon endroit “iparpaheur”: {} par exemple les valeurs pour etre ready pour la mise à jour

# File lib/libriciel.rb, line 621
def self.concat_config_json(config_json_file, tableau, libriciel)
  config_json_file_parse = JSON.parse(File.read(config_json_file))
  config_json_file_parse[libriciel] = config_json_file_parse[libriciel].merge(tableau)

  ## Ici pour surcharge de mes valeurs par défaut du config .JSON
  ## Qui est généré par défaut
  File.open("#{config_json_file}", "w") {|f| f.write(JSON.pretty_generate(config_json_file_parse))}

end
config_json_generator(template_json_file, config_json_file, libriciel, default_config_json) click to toggle source

 Générateur du config.json avec les infos modifiées du fichier de configuration  par rapport au template

# File lib/libriciel.rb, line 688
def self.config_json_generator(template_json_file, config_json_file, libriciel, default_config_json)
  tableau = {}
  template_json_file.each do |each_template|
    config_json_file.each do |each_conf_files|
      if File.basename(each_template) == File.basename(each_conf_files)
        compare_json(each_template, each_conf_files, tableau)
        concat_config_json(default_config_json, tableau, libriciel)
      #else
        # Le test donne deux fichier différents qui n'ont pas à etre comparés
      end
    end
  end
end
cp_json(files, directory) click to toggle source
# File lib/libriciel.rb, line 789
def self.cp_json(files, directory)
    FileUtils.cp(files, directory)
end
ip_conf_to_json(line, tableau) click to toggle source

 Fonction permettant de parser les fichiers de properties iParapheur en JSON

# File lib/libriciel.rb, line 703
def self.ip_conf_to_json(line, tableau)
  array_properties_value = line.split(/[=\n]+/)
  array_properties_dot_split = array_properties_value[0].split(/[\.\n]+/)

  if array_properties_dot_split[0].include? "parapheur"
     array_properties_parapheur_split = array_properties_value[0].split(/parapheur\./)
     tableau[array_properties_parapheur_split[1]] = array_properties_value[1]

  elsif array_properties_value[0].include? "authentication.chain" or array_properties_value[0].include? "alfresco.authentication.allowGuestLogin" or array_properties_value[0].include? "synchronization.autoCreatePeopleOnLogin"
      if array_properties_value[0].include? "#"
        array_properties_value[0] = array_properties_value[0].gsub("#", "")
        tableau[array_properties_value[0]] = array_properties_value[1]
      else
        tableau[array_properties_value[0]] = array_properties_value[1]
      end
  else
      tableau[array_properties_value[0]] = array_properties_value[1]

  end
  return tableau
end
mv_json(files, directory) click to toggle source
# File lib/libriciel.rb, line 785
def self.mv_json(files, directory)
    FileUtils.mv(files, directory)
end
pa_conf_to_json(line, tableau) click to toggle source

 Fonction permettant de parser les fichiers de conf pastell en json

# File lib/libriciel.rb, line 726
def self.pa_conf_to_json(line, tableau)
  tmp_clean = line.gsub(/define\(/, "").gsub(/\);/, "")
  array_properties_value = tmp_clean.split(/[, \n]+/)

  tableau[array_properties_value[0]] = array_properties_value[1].gsub(/\\;/, "")

  return tableau
end
parse_spec_conf(conf_file, caracs_to_extract_from, carac_tableau, separateur) click to toggle source

 Fonction pour l'extraction d'une chaine de caractère  (par exemple le xmx et le xms dans le ctl.sh)  Fichier en entrée, la ou les chaines de caractères à parser  Petit tableau en retours pour pouvoir le faire corrspondre au tableau

# File lib/libriciel.rb, line 592
def self.parse_spec_conf(conf_file, caracs_to_extract_from, carac_tableau, separateur)
  conf_file_open = File.open(conf_file)

  conf_file_open.each_line do |line|
    line_split = line.split

    caracs_to_extract_from.each do |carac_to_split|
      if line.include? carac_to_split
        line_grep = line_split.grep(/#{carac_to_split}/)
        carac_mis_en_forme = carac_to_split.gsub(/[^0-9A-Za-z]/, '').to_s.downcase

        line_grep.each do |line_to_gsub|
          if !carac_mis_en_forme.empty?
            carac_tableau[carac_mis_en_forme] = line_to_gsub.gsub("#{carac_to_split}", '').gsub(/[^0-9A-Za-z]/, '')

          else
            # puts "entrée vide"
          end

        end
      end
    end
  end
  return carac_tableau

end
parsing_conf(files, directory_json) click to toggle source

 Fonction qui fait le parsing des fichiers en confs en data_bag

# File lib/libriciel.rb, line 746
def self.parsing_conf(files, directory_json)
  Array(files).each do |file|

    # Récupération des nom de fichier dans la chemin absolu
    array_absolute_path_to_file = file.split('/')
    config_file_to_write = "/tmp/#{array_absolute_path_to_file.last}.json"

    config_files = File.open(file).read

    # Si existant on surcharge
    File.open("#{config_file_to_write}", "w") {|f| f.write("") }

    tableau = {}
    ## Passage de chaque ligne en json pour le fichier de conf en cours
    config_files.each_line do |line|
      if line.include? "define("
        pa_conf_to_json(line, tableau)

      elsif line.include? "Configure::write("
        wd_conf_to_json(line, tableau)

      elsif line.include? "="
        if !line[0,1].include? "#" or line.include? "ldap"
          ip_conf_to_json(line, tableau)
        end

      end
    end

    ## Ecriture du parsing en json du tableau généré par les fonctions dans le fichier json
    File.open("#{config_file_to_write}", "a") {|f| f.write(JSON.pretty_generate(tableau)) }

    ## Copie des fichiers dans le répertoire commun
    mv_json("#{config_file_to_write}", directory_json.to_s)
  end
end
table_comparaison(all_conf_files, caracs_to_extract_from, libriciel, default_config_file) click to toggle source
Fonction pour la table de correspondance qui va permettre

 D'ajouter au config.json existant les bonnes valeurs  Par exemple le db.host avec le “database” : “hostname” = “” pour

# File lib/libriciel.rb, line 566
def self.table_comparaison(all_conf_files, caracs_to_extract_from, libriciel, default_config_file)
  default_config_file_parse = JSON.parse(File.read(default_config_file))
  all_conf_files.each do |conf_file|
    conf_file_open = File.open(conf_file)

    case libriciel
    when "iparapheur"
      compare_files_iparapheur(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)

    when "webdelib"
      compare_files_webdelib(default_config_file_parse, conf_file_open,conf_file, libriciel, caracs_to_extract_from, default_config_file)

    when "pastell"
      compare_files_pastell(default_config_file_parse, conf_file_open, conf_file, libriciel, caracs_to_extract_from, default_config_file)

    else
      puts "Outils pas dans la liste"
    end
  end
end
wd_conf_to_json(line, tableau) click to toggle source

 Fonction permettant de parser les fichiers de conf webdelib en json

# File lib/libriciel.rb, line 736
def self.wd_conf_to_json(line, tableau)
  tmp_clean = line.gsub(/Configure::write\(/, "").gsub(/\);/, "")
  array_properties_value = tmp_clean.split(/[, \n]+/)

  tableau[array_properties_value[0]] = array_properties_value[1]

  return tableau
end