class MultiIndex::Config
Public Instance Methods
profile()
click to toggle source
# File lib/multi_index/commands.rb, line 83 def profile with_exception_handling do print_parameters(options) filename = options['file'] format = (/.+\.json$/.match(filename)) ? :to_json : ((/.+\.yml/.match(filename)) ? :to_yaml : :unknown) check_argument(format != :unknown, 'File must end with a .json or .yml extension') # Reuse validation code so there is no duplication # Set output to CONFIG_SERVICE to force LDAP prompts profile = validate_config_parameters({'output' => 'CONFIG_SERVICE'})[:profile] file = File.open(filename, 'w') file.write(profile.send(format)) file.close LOG.info "Profile written to #{filename}. You can now use this file with the -p option in the `write` command." end end
write()
click to toggle source
# File lib/multi_index/commands.rb, line 27 def write with_exception_handling do print_parameters(options) write_options = validate_write_parameters(options) config_options = validate_config_parameters(options) profile = config_options[:profile] tier = config_options[:tier] mapping = MultiIndex::GoogleDoc.new(profile[:google_drive]).mapping output = write_options[:output] format = write_options[:format] method = options['invert'] || (output != 'stdout') ? :invert : :original case output when 'stdout' puts "******** MULTI-INDEX CONFIGURATION: #{tier} ********".green case format when 'yaml' puts mapping.send(method, tier).to_yaml.green when 'json' puts prettify(mapping.send(method, tier).to_json).green when 'escaped' puts prettify(mapping.send(method, tier).to_json).gsub(',', '\,').green end break when 'EAS' LOG.info 'Performing update assuming present working directory is EAS' resources_path = 'entity-attribute-server/src/main/resources' mapping.send(method, tier).each do |tier, indices| indices = Hash[indices.map { |k, v| [k.upcase, v] }] config_filename = "#{resources_path}/#{tier}.yml" config = YAML.load_file(config_filename) LOG.info "Updating file: #{config_filename} for tier: #{tier}" config['elasticsearch'] ||= {} config['elasticsearch'].merge!({'indices' => indices}) config_file = File.open(config_filename, 'w') config_file.write(config.to_yaml.gsub(/^---\n/, '')) config_file.close end break else # TODO: Code for config service writing end end end