Class: Credman::Conflicts

Inherits:
Base
  • Object
show all
Defined in:
lib/credman/conflicts.rb

Constant Summary collapse

REGEXP =
/^<{7} HEAD(\r?\n(?!={7}\r?\n).*)*\r?\n={7}(\r?\n(?!>{7} ).*)*\r?\n>{7} \S+/m

Instance Method Summary collapse

Methods inherited from Base

#config_has_keys?, #configs, #decript, #initialize, #key_for, #pastel, #print_key_and_value, #rewrite_config_for

Constructor Details

This class inherits a constructor from Credman::Base

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/credman/conflicts.rb', line 7

def perform
  @environment_list.each do |env|
    puts pastel.green("#{env}:")
    cred_content = File.read("config/credentials/#{env}.yml.enc")
    parsed_conflict = REGEXP.match(cred_content)

    unless parsed_conflict
      puts "✅ No conflicts found"
      next
    end

    our_config = config_to_compare_for(env, parsed_conflict[1].strip)
    their_config = config_to_compare_for(env, parsed_conflict[2].strip)
    @merged_config = our_config.deep_merge(their_config)
    deep_print_diff(HashDiff.diff(their_config, our_config))

    rewrite_config_for(env, @merged_config)
    puts "✅ Merged config for #{env} has been saved"
  end
end