Class: Paramsync::CLI::PushCommand

Inherits:
Object
  • Object
show all
Defined in:
lib/paramsync/cli/push_command.rb

Class Method Summary collapse

Class Method Details

.run(args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/paramsync/cli/push_command.rb', line 7

def run(args)
  Paramsync::CLI.configure
  STDOUT.sync = true

  Paramsync.config.sync_targets.each do |target|
    diff = target.diff(:push)

    diff.print_report

    if not diff.any_changes?
      puts
      puts "Everything is in sync. No changes need to be made to this sync target."
      next
    end

    puts
    puts "Do you want to push these changes?"
    print "  Enter '" + "yes".bold + "' to continue: "
    answer = args.include?('--yes') ? 'yes' : gets.chomp

    if answer.downcase != "yes"
      puts
      puts "Push cancelled. No changes will be made to this sync target."
      next
    end

    puts
    diff.items_to_change.each do |item|
      case item.op
      when :create
        print "CREATE".bold.green + " " + item.ssm_key
        begin
          target.ssm.put_parameter(
            name: item.ssm_key,
            value: item.local_content[0],
            type: item.local_content[1] ? 'SecureString' : 'String'
          )
          puts "   OK".bold
        rescue
          puts "   ERROR".bold.red
        end

      when :update
        print "UPDATE".bold.blue + " " + item.ssm_key
        begin
          target.ssm.put_parameter(
            name: item.ssm_key,
            value: item.local_content[0],
            type: item.local_content[1] ? 'SecureString' : 'String',
            overwrite: true
          )
          puts "   OK".bold
        rescue
          puts "   ERROR".bold.red
        end

      when :delete
        print "DELETE".bold.red + " " + item.ssm_key
        begin
          target.ssm.delete_parameter(name: item.ssm_key)
          puts "   OK".bold
        rescue
          puts "   ERROR".bold.red
        end

      else
        if Paramsync.config.verbose?
          STDERR.puts "paramsync: WARNING: unexpected operation '#{item.op}' for #{item.ssm_key}"
          next
        end

      end
    end
  end
end