Class: AppCommand::CloudFormationDetectDrift

Inherits:
Convoy::ActionCommand::Base
  • Object
show all
Defined in:
lib/routes/cloudformation_detect_drift.rb

Constant Summary collapse

TMP_OUTPUT =
'/tmp/execute-output'

Instance Method Summary collapse

Instance Method Details

#executeObject



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

def execute

    begin

        @opts = command_options
        @args = arguments

        @regions = []
        @threads = []

        opts_validate
        opts_routing

    rescue => e

        Blufin::Terminal::print_exception(e)

    end

end

#opts_routingObject



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
# File 'lib/routes/cloudformation_detect_drift.rb', line 34

def opts_routing
    threads = []
    puts
    stacks = App::AWSCloudFormation::get_stacks
    puts
    system("rm #{TMP_OUTPUT}")
    system("touch #{TMP_OUTPUT}")
    stacks.each do |stack|
        sleep(0.01)
        threads << Thread.new {
            cmd = "aws cloudformation detect-stack-drift --stack-name #{stack[:name]} --region #{stack[:region]}#{App::AWS::get_profile_for_cli} >> #{TMP_OUTPUT} 2>&1"
            App::AWSOutputter::output_cli_command(cmd)
            `#{cmd}`
        }
    end
    sleep(0.1)
    puts
    # Display spinner while waiting for threads to finish.
    Blufin::Terminal::execute_proc("AWS \xe2\x80\x94 Detecting Drift...", Proc.new {
        threads.each { |thread| thread.join }
    })
    output = `cat #{TMP_OUTPUT}`
    output.split("\n").each do |line|
        line = line.strip
        next if line == ''
        next if line =~ /^\{$/
        next if line =~ /^\}$/
        next if line =~ /"StackDriftDetectionId":\s*"[A-Za-z0-9-]+"/
        puts
        puts "\x1B[38;5;196m#{line}\x1B[0m"
    end
    puts
end

#opts_validateObject



28
29
30
31
32
# File 'lib/routes/cloudformation_detect_drift.rb', line 28

def opts_validate

    @regions = App::AWSValidator::get_and_validate_regions(@opts[:region_given])

end