ruby 使用此脚本检查每个客户端conf是否具有默认方案集(如果需要)。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 使用此脚本检查每个客户端conf是否具有默认方案集(如果需要)。相关的知识,希望对你有一定的参考价值。

require 'json'
require 'pp'
require 'pathname'

CONF_PATH = '/Users/davidteren/Projects/IMQS/_conf'

def absolute_paths_of_dir_contents(dir, list = '*')
  path = File.join(dir, list)
  Dir.glob(path) - %w(. .. .DS_Store)
end

def path_basename(path)
  Pathname.new(path).basename.to_s
end

def a_git_repo?(dir)
  File.exist?(File.join(dir, '.git', 'config'))
end

def select_repos(dirs)
  dirs.select do |dir|
    a_git_repo?(dir)
  end
end

def absolute_paths_for_repos(path)
  select_repos(absolute_paths_of_dir_contents(path, '*/'))
end

def client_modules(json)
  json['modules']
end


def read_json(conf)
  JSON.parse(File.read(File.join(conf, 'client-config-public.json')))
end

def test_scenarios(modul)
  unless modul['scenarios'].nil?
    unless modul['scenarios'].include?('04') || modul['scenarios'].include?('02')
      if modul['defaultScenarios'].nil?
        return 'FAIL!'
      end
    end
    'OK!'
  end
end

def show_results(conf_path, has_tablesearch, modules)
  puts "CONF: #{path_basename conf_path}"
  puts "MODULES COUNT: #{modules.size}"
  puts "Has 'tablesearch': #{has_tablesearch}"
  counter = 0
  modules.each do |modul|
    puts "#{counter += 1} : #{modul['name']} : #{test_scenarios(modul)}"
  end
  puts "####################################\n\n"
end

def process_confs
  absolute_paths_for_repos(CONF_PATH).each do |conf_path|
    # next unless conf_path.include?('uat') || conf_path.include?('gls')
    client_json = read_json(conf_path)
    next if client_json['feature-flags'].is_a?(NilClass)
    has_tablesearch = client_json['feature-flags']['tablesearch']
    next unless has_tablesearch
    modules = client_json['modules']
    show_results(conf_path, has_tablesearch, modules)
  end
end

process_confs

以上是关于ruby 使用此脚本检查每个客户端conf是否具有默认方案集(如果需要)。的主要内容,如果未能解决你的问题,请参考以下文章