cfn-status 0.3.0 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: db0db619c3720d0b8aa596db7f48638b88ad4866b110647cba6af9bdef8a083b
4
- data.tar.gz: f911ca63d21c025da730f3b96065982698d0e2f4b2321a01d74c4ce854a0095e
3
+ metadata.gz: 154b5d15f93d77c109df45509a391310485430fe542f7d66f2f431ec73cdfd09
4
+ data.tar.gz: 7205fc07760831619538f468574c245010d8b4abe28eb33f64c60db94b04a1e9
5
5
  SHA512:
6
- metadata.gz: 506a3a5fda2b73a8a33e5aac2afb7e94dcbf63a6d90e4e3dad7bee7f1e182360b559db97b5c721a2282e0ec199e12d0f615c8dd2483e6c1b3b1a99a1cd8cf3f0
7
- data.tar.gz: 38991d9cdf18ea678061a4c0e60297b236a912cc208a49fc58ffad339d94864da229b92c25e649e7a290dc33c8590af37a8a6f2056bc00f2d94e9cca0e5574bb
6
+ metadata.gz: 93c77d9e09eb0a67e3fca9012779b878332f7674fbdcc97b02e930df42656ac8583a4e3890f28beb9e3064f32468adfa27646fd63addb7cdd7b86ffb204b820a
7
+ data.tar.gz: 0b5cddb879782ba4c46900c4b8cecb42086a04c44b48e8d51214f04405d6e8108331f2feae45125b1357733b0bb8d55abc8b243e6a3c748cc01c7c2f83f1ca71
data/CHANGELOG.md CHANGED
@@ -3,6 +3,21 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely* adheres to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [0.4.3] - 2021-05-27
7
+ - [#4](https://github.com/tongueroo/cfn-status/pull/4) fix current status message
8
+
9
+ ## [0.4.2]
10
+ - #3 improve messaging when wait called directly. dont show old events.
11
+
12
+ ## [0.4.1]
13
+ - fix require cfn_status/rollback_stack
14
+
15
+ ## [0.4.0]
16
+ - #2 add handle_rollback! method
17
+
18
+ ## [0.3.1]
19
+ - allow use of different cfn client
20
+
6
21
  ## [0.3.0]
7
22
  - #1 Breaking change: rename Rename to CfnStatus, cfn/status to cfn_status
8
23
  - Handle large templates and long stack_events via paginating the cfn.describe_stack_events until
data/lib/cfn_status.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "cfn_status/version"
2
+ require "cfn_status/rollback_stack"
2
3
 
3
4
  class CfnStatus
4
5
  class Error < StandardError; end
@@ -6,10 +7,13 @@ class CfnStatus
6
7
  autoload :AwsService, "cfn_status/aws_service"
7
8
  include AwsService
8
9
 
9
- attr_reader :events
10
+ attr_reader :events, :stack
10
11
  def initialize(stack_name, options={})
11
12
  @stack_name = stack_name
12
13
  @options = options
14
+ @cfn = options[:cfn] # allow use of different cfn client. can be useful multiple cfn clients and with different regions
15
+ resp = cfn.describe_stacks(stack_name: @stack_name)
16
+ @stack = resp.stacks.first
13
17
  reset
14
18
  end
15
19
 
@@ -19,11 +23,8 @@ class CfnStatus
19
23
  return true
20
24
  end
21
25
 
22
- resp = cfn.describe_stacks(stack_name: @stack_name)
23
- stack = resp.stacks.first
24
-
25
26
  puts "The current status for the stack #{@stack_name.color(:green)} is #{stack.stack_status.color(:green)}"
26
- if stack.stack_status =~ /_IN_PROGRESS$/
27
+ if in_progress?
27
28
  puts "Stack events (tailing):"
28
29
  # tail all events until done
29
30
  @hide_time_took = true
@@ -37,6 +38,11 @@ class CfnStatus
37
38
  success?
38
39
  end
39
40
 
41
+ def in_progress?
42
+ in_progress = stack.stack_status =~ /_IN_PROGRESS$/
43
+ !!in_progress
44
+ end
45
+
40
46
  def reset
41
47
  @events = [] # constantly replaced with recent events
42
48
  @last_shown_event_id = nil
@@ -45,6 +51,10 @@ class CfnStatus
45
51
 
46
52
  # check for /(_COMPLETE|_FAILED)$/ status
47
53
  def wait
54
+ # Check for in progress again in case .wait is called from other libraries like s3-antivirus
55
+ # Showing the event messages when will show old messages which can be confusing.
56
+ return unless in_progress?
57
+
48
58
  puts "Waiting for stack to complete"
49
59
  start_time = Time.now
50
60
 
@@ -242,4 +252,8 @@ class CfnStatus
242
252
  "#{minutes.to_i}m #{seconds.to_i}s"
243
253
  end
244
254
  end
255
+
256
+ def handle_rollback!
257
+ CfnStatus::RollbackStack.handle!(@stack_name, cfn: cfn)
258
+ end
245
259
  end
@@ -0,0 +1,42 @@
1
+ class CfnStatus
2
+ class RollbackStack
3
+ def self.handle!(stack_name, options={})
4
+ new(stack_name, options).run
5
+ end
6
+
7
+ attr_reader :status, :cfn
8
+ def initialize(stack_name, options={})
9
+ @stack_name = stack_name
10
+ @cfn = options[:cfn]
11
+ @status = CfnStatus.new(@stack_name, cfn: @cfn)
12
+ end
13
+
14
+ def run
15
+ @stack = find_stack(@stack_name)
16
+ if @stack && rollback_complete?(@stack)
17
+ puts "Existing stack in ROLLBACK_COMPLETE state. Deleting stack before continuing."
18
+ cfn.delete_stack(stack_name: @stack_name)
19
+ status.wait
20
+ status.reset
21
+ @stack = nil # at this point stack has been deleted
22
+ end
23
+ end
24
+
25
+ def rollback_complete?(stack)
26
+ stack.stack_status == 'ROLLBACK_COMPLETE'
27
+ end
28
+
29
+ def find_stack(stack_name)
30
+ return if ENV['CFN_STATUS_TEST']
31
+ resp = cfn.describe_stacks(stack_name: stack_name)
32
+ resp.stacks.first
33
+ rescue Aws::CloudFormation::Errors::ValidationError => e
34
+ # example: Stack with id demo-web does not exist
35
+ if e.message =~ /Stack with/ && e.message =~ /does not exist/
36
+ nil
37
+ else
38
+ raise
39
+ end
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  class CfnStatus
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfn-status
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-03-22 00:00:00.000000000 Z
11
+ date: 2021-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudformation
@@ -87,6 +87,7 @@ files:
87
87
  - lib/cfn-status.rb
88
88
  - lib/cfn_status.rb
89
89
  - lib/cfn_status/aws_service.rb
90
+ - lib/cfn_status/rollback_stack.rb
90
91
  - lib/cfn_status/version.rb
91
92
  homepage: https://github.com/tongueroo/cfn-status
92
93
  licenses:
@@ -107,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
108
  - !ruby/object:Gem::Version
108
109
  version: '0'
109
110
  requirements: []
110
- rubygems_version: 3.1.2
111
+ rubygems_version: 3.2.5
111
112
  signing_key:
112
113
  specification_version: 4
113
114
  summary: CloudFormation status library