cfn-status 0.5.0 → 0.6.0

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: 8995a22b702f88f6b8474940ff4cedcad0ed03f5959662f858b20597b3b7bd75
4
- data.tar.gz: 9d0a502a23754203bfdc2a7043c587b168379fc0419b2849cb76374525c9516b
3
+ metadata.gz: 83ea64eefe541a908445abdcb961258dc4da1214975c4a0e757c8a54e689e554
4
+ data.tar.gz: f8d9d83fdf7d77b71f93ca9049f46c6d9a054adc4c7c64d8afe9b620e9f7df09
5
5
  SHA512:
6
- metadata.gz: 39b82b43b28f88fc08b784a6c595d27f553f641add1f27f0ae207de62182b05269fbba62f0c094d84da918b8cf450d4ffa8d050fb73a73a63bbdbda957cd7d2e
7
- data.tar.gz: f6c0b78894e28f66285c9bafb6c48775c4e13dc72d2c5908c3168368c6cf4d571ab66e464b5f9bdebc7b48ab9166f88fbd8090164fe85a3ace2624af2557e589
6
+ metadata.gz: b8944265098682315726a329935fea5ab71e6ccef3b02ef786714802d6eae13ab484957d9de132b433e1a8978a18f2deedf79126a7aab6a5e1c1fe704ff234b9
7
+ data.tar.gz: 2ae96f538b6af56ddcbf48fcc630e3270ae4ad40d61668578e3c69f87e08924d338649e8d5be3e783978306cdecd3ff698793f58eb72d2c5b7c48acd675edc82
data/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
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.6.0] - 2024-04-15
7
+ - [#8](https://github.com/tongueroo/cfn-status/pull/8) Fix success return
8
+ - fix success after delete
9
+ - fix success return after wait
10
+ - remove bin scripts
11
+ - @hide_time_took fix
12
+ - show took false by default
13
+
6
14
  ## [0.5.0] - 2023-12-17
7
15
  - [#6](https://github.com/tongueroo/cfn-status/pull/6) Use events.dig instead of brackets
8
16
  - [#7](https://github.com/tongueroo/cfn-status/pull/7) Add start_index_before_delete option
@@ -1,3 +1,3 @@
1
1
  class CfnStatus
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/cfn_status.rb CHANGED
@@ -8,7 +8,7 @@ class CfnStatus
8
8
  include AwsService
9
9
 
10
10
  attr_reader :events, :stack
11
- def initialize(stack_name, options={})
11
+ def initialize(stack_name, options = {})
12
12
  @stack_name = stack_name
13
13
  @options = options
14
14
  @cfn = options[:cfn] # allow use of different cfn client. can be useful multiple cfn clients and with different regions
@@ -53,13 +53,13 @@ class CfnStatus
53
53
  def wait
54
54
  # Check for in progress again in case .wait is called from other libraries like s3-antivirus
55
55
  # Showing the event messages when will show old messages which can be confusing.
56
- return unless in_progress?
56
+ return success? unless in_progress?
57
57
 
58
58
  puts "Waiting for stack to complete"
59
59
  start_time = Time.now
60
60
 
61
61
  refresh_events
62
- until completed || @stack_deletion_completed
62
+ until completed? || @stack_deletion_completed
63
63
  show_events(final: false)
64
64
  end
65
65
  show_events(final: true) # show the final event
@@ -67,35 +67,39 @@ class CfnStatus
67
67
  if @stack_deletion_completed
68
68
  puts "Stack #{@stack_name} deleted."
69
69
  show_took(start_time)
70
- return
70
+ # Cant use success? because the stack is deleted and the describe stack errors
71
+ # For deletion, always return true once describe_stack fails to return the stack
72
+ return true
71
73
  end
72
74
 
73
75
  # Never gets beyond here when deleting a stack because the describe stack returns nothing
74
76
  # once the stack is deleted. Gets here for stack create and update though.
75
77
 
76
- if last_event_status =~ /_FAILED/
78
+ if /_FAILED/.match?(last_event_status)
77
79
  puts "Stack failed: #{last_event_status}".color(:red)
78
- puts "Stack reason #{@events.dig(0,"resource_status_reason")}".color(:red)
79
- elsif last_event_status =~ /_ROLLBACK_/
80
+ puts "Stack reason #{@events.dig(0, "resource_status_reason")}".color(:red)
81
+ elsif /_ROLLBACK_/.match?(last_event_status)
80
82
  puts "Stack rolled back: #{last_event_status}".color(:red)
81
83
  else # success
82
84
  puts "Stack success status: #{last_event_status}".color(:green)
83
85
  end
84
86
 
85
- return if @hide_time_took # set in run
86
87
  show_took(start_time)
87
88
  success?
88
89
  end
89
90
 
90
91
  def show_took(start_time)
92
+ # @hide_time_took set in run
93
+ return if @hide_time_took
94
+ return unless @options[:show_took]
91
95
  took = Time.now - start_time
92
96
  puts "Time took: #{pretty_time(took).color(:green)}"
93
97
  end
94
98
 
95
- def completed
99
+ def completed?
96
100
  last_event_status =~ /(_COMPLETE|_FAILED)$/ &&
97
- @events.dig(0,"logical_resource_id") == @stack_name &&
98
- @events.dig(0,"resource_type") == "AWS::CloudFormation::Stack"
101
+ @events.dig(0, "logical_resource_id") == @stack_name &&
102
+ @events.dig(0, "resource_type") == "AWS::CloudFormation::Stack"
99
103
  end
100
104
 
101
105
  def last_event_status
@@ -110,16 +114,16 @@ class CfnStatus
110
114
  else
111
115
  i = last_shown_index
112
116
  # puts "last_shown index #{i}"
113
- print_events(i-1) unless i == 0
117
+ print_events(i - 1) unless i == 0
114
118
  end
115
119
 
116
120
  return if final
117
- sleep 5 unless ENV['TEST']
121
+ sleep 5 unless ENV["TEST"]
118
122
  refresh_events
119
123
  end
120
124
 
121
125
  def print_events(i)
122
- @events[0..i].reverse.each do |e|
126
+ @events[0..i].reverse_each do |e|
123
127
  print_event(e)
124
128
  end
125
129
 
@@ -135,7 +139,7 @@ class CfnStatus
135
139
  e["logical_resource_id"],
136
140
  e["resource_status_reason"]
137
141
  ].join(" ")
138
- message = message.color(:red) if e["resource_status"] =~ /_FAILED/
142
+ message = message.color(:red) if /_FAILED/.match?(e["resource_status"])
139
143
  puts message
140
144
  end
141
145
 
@@ -160,9 +164,8 @@ class CfnStatus
160
164
  else
161
165
  add_events_pages(resp, :start_index)
162
166
  end
163
-
164
167
  rescue Aws::CloudFormation::Errors::ValidationError => e
165
- if e.message =~ /Stack .* does not exis/
168
+ if /Stack .* does not exis/.match?(e.message)
166
169
  @stack_deletion_completed = true
167
170
  else
168
171
  raise
@@ -197,8 +200,8 @@ class CfnStatus
197
200
  skip = start_index_before_delete && event["resource_status"] == "DELETE_IN_PROGRESS"
198
201
 
199
202
  event["resource_type"] == "AWS::CloudFormation::Stack" &&
200
- event["resource_status_reason"] == "User Initiated" &&
201
- !skip
203
+ event["resource_status_reason"] == "User Initiated" &&
204
+ !skip
202
205
  end
203
206
  end
204
207
 
@@ -209,18 +212,26 @@ class CfnStatus
209
212
  end
210
213
 
211
214
  def success?
212
- resource_status = @events.dig(0,"resource_status")
213
- %w[CREATE_COMPLETE UPDATE_COMPLETE].include?(resource_status)
215
+ resource_status = @events.dig(0, "resource_status")
216
+ if resource_status.nil? # not called as a part of wait
217
+ resp = cfn.describe_stacks(stack_name: @stack_name)
218
+ status = resp.stacks.first.stack_status
219
+ else
220
+ status = resource_status
221
+ end
222
+
223
+ successes = %w[CREATE_COMPLETE UPDATE_COMPLETE]
224
+ successes.include?(status)
214
225
  end
215
226
 
216
227
  def update_rollback?
217
- @events.dig(0,"resource_status") == "UPDATE_ROLLBACK_COMPLETE"
228
+ @events.dig(0, "resource_status") == "UPDATE_ROLLBACK_COMPLETE"
218
229
  end
219
230
 
220
231
  def find_update_failed_event
221
232
  i = @events.find_index do |event|
222
233
  event["resource_type"] == "AWS::CloudFormation::Stack" &&
223
- event["resource_status_reason"] == "User Initiated"
234
+ event["resource_status_reason"] == "User Initiated"
224
235
  end
225
236
 
226
237
  @events[0..i].reverse.find do |e|
@@ -236,7 +247,7 @@ class CfnStatus
236
247
 
237
248
  reason = event["resource_status_reason"]
238
249
  messages_map.each do |pattern, message|
239
- if reason =~ pattern
250
+ if reason&.match?(pattern)
240
251
  return message
241
252
  end
242
253
  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.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-12-17 00:00:00.000000000 Z
11
+ date: 2024-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-cloudformation
@@ -95,8 +95,6 @@ files:
95
95
  - LICENSE.txt
96
96
  - README.md
97
97
  - Rakefile
98
- - bin/console
99
- - bin/setup
100
98
  - cfn-status.gemspec
101
99
  - lib/cfn-status.rb
102
100
  - lib/cfn_status.rb
@@ -122,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
122
120
  - !ruby/object:Gem::Version
123
121
  version: '0'
124
122
  requirements: []
125
- rubygems_version: 3.4.20
123
+ rubygems_version: 3.4.19
126
124
  signing_key:
127
125
  specification_version: 4
128
126
  summary: CloudFormation status library
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "cfn_status"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here