codepipeline 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (202) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +3 -0
  3. data/Gemfile.lock +7 -7
  4. data/codepipe.gemspec +5 -1
  5. data/lib/codepipe/version.rb +1 -1
  6. data/vendor/aws_data/Gemfile +4 -0
  7. data/vendor/aws_data/Gemfile.lock +48 -0
  8. data/{docs/LICENSE → vendor/aws_data/LICENSE.txt} +4 -4
  9. data/vendor/aws_data/README.md +41 -0
  10. data/vendor/aws_data/Rakefile +6 -0
  11. data/vendor/aws_data/aws_data.gemspec +30 -0
  12. data/vendor/aws_data/bin/console +14 -0
  13. data/vendor/aws_data/bin/setup +8 -0
  14. data/vendor/aws_data/lib/aws_data.rb +89 -0
  15. data/vendor/aws_data/lib/aws_data/version.rb +3 -0
  16. data/vendor/aws_data/spec/aws_data_spec.rb +5 -0
  17. data/vendor/aws_data/spec/spec_helper.rb +14 -0
  18. data/vendor/cfn-status/Gemfile +4 -0
  19. data/vendor/cfn-status/Gemfile.lock +49 -0
  20. data/vendor/cfn-status/LICENSE.txt +21 -0
  21. data/vendor/cfn-status/README.md +56 -0
  22. data/vendor/cfn-status/Rakefile +6 -0
  23. data/vendor/cfn-status/bin/console +14 -0
  24. data/vendor/cfn-status/bin/setup +8 -0
  25. data/vendor/cfn-status/cfn-status.gemspec +30 -0
  26. data/vendor/cfn-status/lib/cfn/aws_service.rb +56 -0
  27. data/vendor/cfn-status/lib/cfn/status.rb +220 -0
  28. data/vendor/cfn-status/lib/cfn/status/version.rb +5 -0
  29. data/vendor/cfn-status/spec/cfn/status_spec.rb +81 -0
  30. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +1080 -0
  31. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +1080 -0
  32. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +1086 -0
  33. data/vendor/cfn-status/spec/spec_helper.rb +14 -0
  34. data/vendor/cfn_camelizer/CHANGELOG.md +10 -0
  35. data/vendor/cfn_camelizer/Gemfile +4 -0
  36. data/vendor/cfn_camelizer/LICENSE.txt +21 -0
  37. data/vendor/cfn_camelizer/README.md +40 -0
  38. data/vendor/cfn_camelizer/Rakefile +6 -0
  39. data/vendor/cfn_camelizer/bin/console +14 -0
  40. data/vendor/cfn_camelizer/bin/setup +8 -0
  41. data/vendor/cfn_camelizer/cfn_camelizer.gemspec +32 -0
  42. data/vendor/cfn_camelizer/lib/camelizer.yml +27 -0
  43. data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +92 -0
  44. data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +3 -0
  45. data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +79 -0
  46. data/vendor/cfn_camelizer/spec/spec_helper.rb +14 -0
  47. metadata +44 -171
  48. data/docs/.gitignore +0 -4
  49. data/docs/CNAME +0 -1
  50. data/docs/Gemfile +0 -3
  51. data/docs/README.md +0 -25
  52. data/docs/_config.yml +0 -73
  53. data/docs/_docs/contributing.md +0 -99
  54. data/docs/_docs/conventions.md +0 -42
  55. data/docs/_docs/deploy.md +0 -59
  56. data/docs/_docs/dsl.md +0 -39
  57. data/docs/_docs/dsl/approve.md +0 -62
  58. data/docs/_docs/dsl/pipeline.md +0 -55
  59. data/docs/_docs/dsl/pipeline/action.md +0 -28
  60. data/docs/_docs/dsl/pipeline/codebuild.md +0 -62
  61. data/docs/_docs/dsl/pipeline/prefix-and-suffix.md +0 -57
  62. data/docs/_docs/dsl/role.md +0 -79
  63. data/docs/_docs/dsl/schedule.md +0 -29
  64. data/docs/_docs/dsl/sns.md +0 -27
  65. data/docs/_docs/dsl/webhook.md +0 -31
  66. data/docs/_docs/ecs-deploy.md +0 -22
  67. data/docs/_docs/examples/codebuild-project.md +0 -21
  68. data/docs/_docs/examples/different-branches.md +0 -49
  69. data/docs/_docs/examples/multiple-codebuild-projects.md +0 -60
  70. data/docs/_docs/install.md +0 -14
  71. data/docs/_docs/next-steps.md +0 -16
  72. data/docs/_docs/settings.md +0 -34
  73. data/docs/_docs/start.md +0 -31
  74. data/docs/_docs/structure.md +0 -25
  75. data/docs/_includes/commands.html +0 -92
  76. data/docs/_includes/content.html +0 -25
  77. data/docs/_includes/edit-on-github.html +0 -9
  78. data/docs/_includes/example.html +0 -12
  79. data/docs/_includes/footer.html +0 -41
  80. data/docs/_includes/google_analytics.html +0 -10
  81. data/docs/_includes/head.html +0 -45
  82. data/docs/_includes/js.html +0 -15
  83. data/docs/_includes/nav.html +0 -17
  84. data/docs/_includes/prev_next.md +0 -19
  85. data/docs/_includes/reference.md +0 -1
  86. data/docs/_includes/subnav.html +0 -47
  87. data/docs/_includes/tutorials.md +0 -38
  88. data/docs/_layouts/default.html +0 -12
  89. data/docs/_reference/pipe-completion.md +0 -44
  90. data/docs/_reference/pipe-completion_script.md +0 -25
  91. data/docs/_reference/pipe-delete.md +0 -25
  92. data/docs/_reference/pipe-deploy.md +0 -26
  93. data/docs/_reference/pipe-init.md +0 -25
  94. data/docs/_reference/pipe-start.md +0 -25
  95. data/docs/_reference/pipe-version.md +0 -21
  96. data/docs/_sass/_bootstrap-overrides.scss +0 -40
  97. data/docs/_sass/_contact.scss +0 -49
  98. data/docs/_sass/_cta.scss +0 -37
  99. data/docs/_sass/_download.scss +0 -31
  100. data/docs/_sass/_features.scss +0 -47
  101. data/docs/_sass/_footer.scss +0 -49
  102. data/docs/_sass/_global.scss +0 -102
  103. data/docs/_sass/_main.scss +0 -370
  104. data/docs/_sass/_masthead.scss +0 -70
  105. data/docs/_sass/_mixins.scss +0 -79
  106. data/docs/_sass/_navbar.scss +0 -92
  107. data/docs/_sass/_syntax.scss +0 -65
  108. data/docs/_sass/_table.scss +0 -34
  109. data/docs/_sass/_timeline.scss +0 -207
  110. data/docs/_sass/_variables.scss +0 -24
  111. data/docs/bin/web +0 -8
  112. data/docs/docs.md +0 -24
  113. data/docs/img/docs/codepipeline-output.png +0 -0
  114. data/docs/img/docs/multiple-codebuild-projects-pipeline.png +0 -0
  115. data/docs/img/logos/boltops-logo-full.png +0 -0
  116. data/docs/img/logos/boltops-logo.png +0 -0
  117. data/docs/img/logos/project-logo.png +0 -0
  118. data/docs/index.html +0 -37
  119. data/docs/js/nav.js +0 -39
  120. data/docs/js/new-age.js +0 -38
  121. data/docs/js/new-age.min.js +0 -6
  122. data/docs/new-age.scss +0 -20
  123. data/docs/quick-start.md +0 -72
  124. data/docs/reference.md +0 -12
  125. data/docs/support.md +0 -22
  126. data/docs/vendor/bootstrap/css/bootstrap-grid.css +0 -1339
  127. data/docs/vendor/bootstrap/css/bootstrap-grid.css.map +0 -1
  128. data/docs/vendor/bootstrap/css/bootstrap-grid.min.css +0 -1
  129. data/docs/vendor/bootstrap/css/bootstrap-grid.min.css.map +0 -1
  130. data/docs/vendor/bootstrap/css/bootstrap-reboot.css +0 -459
  131. data/docs/vendor/bootstrap/css/bootstrap-reboot.css.map +0 -1
  132. data/docs/vendor/bootstrap/css/bootstrap-reboot.min.css +0 -1
  133. data/docs/vendor/bootstrap/css/bootstrap-reboot.min.css.map +0 -1
  134. data/docs/vendor/bootstrap/css/bootstrap.css +0 -9320
  135. data/docs/vendor/bootstrap/css/bootstrap.css.map +0 -1
  136. data/docs/vendor/bootstrap/css/bootstrap.min.css +0 -6
  137. data/docs/vendor/bootstrap/css/bootstrap.min.css.map +0 -1
  138. data/docs/vendor/bootstrap/js/bootstrap.js +0 -3535
  139. data/docs/vendor/bootstrap/js/bootstrap.min.js +0 -7
  140. data/docs/vendor/font-awesome/css/font-awesome.css +0 -2337
  141. data/docs/vendor/font-awesome/css/font-awesome.min.css +0 -4
  142. data/docs/vendor/font-awesome/fonts/FontAwesome.otf +0 -0
  143. data/docs/vendor/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  144. data/docs/vendor/font-awesome/fonts/fontawesome-webfont.svg +0 -2671
  145. data/docs/vendor/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  146. data/docs/vendor/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  147. data/docs/vendor/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  148. data/docs/vendor/font-awesome/less/animated.less +0 -34
  149. data/docs/vendor/font-awesome/less/bordered-pulled.less +0 -25
  150. data/docs/vendor/font-awesome/less/core.less +0 -12
  151. data/docs/vendor/font-awesome/less/fixed-width.less +0 -6
  152. data/docs/vendor/font-awesome/less/font-awesome.less +0 -18
  153. data/docs/vendor/font-awesome/less/icons.less +0 -789
  154. data/docs/vendor/font-awesome/less/larger.less +0 -13
  155. data/docs/vendor/font-awesome/less/list.less +0 -19
  156. data/docs/vendor/font-awesome/less/mixins.less +0 -60
  157. data/docs/vendor/font-awesome/less/path.less +0 -15
  158. data/docs/vendor/font-awesome/less/rotated-flipped.less +0 -20
  159. data/docs/vendor/font-awesome/less/screen-reader.less +0 -5
  160. data/docs/vendor/font-awesome/less/stacked.less +0 -20
  161. data/docs/vendor/font-awesome/less/variables.less +0 -799
  162. data/docs/vendor/font-awesome/scss/_animated.scss +0 -34
  163. data/docs/vendor/font-awesome/scss/_bordered-pulled.scss +0 -25
  164. data/docs/vendor/font-awesome/scss/_core.scss +0 -12
  165. data/docs/vendor/font-awesome/scss/_fixed-width.scss +0 -6
  166. data/docs/vendor/font-awesome/scss/_icons.scss +0 -789
  167. data/docs/vendor/font-awesome/scss/_larger.scss +0 -13
  168. data/docs/vendor/font-awesome/scss/_list.scss +0 -19
  169. data/docs/vendor/font-awesome/scss/_mixins.scss +0 -60
  170. data/docs/vendor/font-awesome/scss/_path.scss +0 -15
  171. data/docs/vendor/font-awesome/scss/_rotated-flipped.scss +0 -20
  172. data/docs/vendor/font-awesome/scss/_screen-reader.scss +0 -5
  173. data/docs/vendor/font-awesome/scss/_stacked.scss +0 -20
  174. data/docs/vendor/font-awesome/scss/_variables.scss +0 -799
  175. data/docs/vendor/font-awesome/scss/font-awesome.scss +0 -18
  176. data/docs/vendor/jquery-easing/jquery.easing.compatibility.js +0 -59
  177. data/docs/vendor/jquery-easing/jquery.easing.js +0 -166
  178. data/docs/vendor/jquery-easing/jquery.easing.min.js +0 -1
  179. data/docs/vendor/jquery/jquery.js +0 -10253
  180. data/docs/vendor/jquery/jquery.min.js +0 -4
  181. data/docs/vendor/simple-line-icons/css/simple-line-icons.css +0 -778
  182. data/docs/vendor/simple-line-icons/fonts/Simple-Line-Icons.eot +0 -0
  183. data/docs/vendor/simple-line-icons/fonts/Simple-Line-Icons.svg +0 -200
  184. data/docs/vendor/simple-line-icons/fonts/Simple-Line-Icons.ttf +0 -0
  185. data/docs/vendor/simple-line-icons/fonts/Simple-Line-Icons.woff +0 -0
  186. data/docs/vendor/simple-line-icons/fonts/Simple-Line-Icons.woff2 +0 -0
  187. data/docs/vendor/simple-line-icons/less/simple-line-icons.less +0 -982
  188. data/docs/vendor/simple-line-icons/scss/simple-line-icons.scss +0 -979
  189. data/docs/vendor/tether/tether.js +0 -1811
  190. data/docs/vendor/tether/tether.min.js +0 -1
  191. data/spec/fixtures/app/.codepipeline/pipeline.rb +0 -12
  192. data/spec/fixtures/app/.codepipeline/schedule.rb +0 -1
  193. data/spec/fixtures/app/.codepipeline/webhook.rb +0 -1
  194. data/spec/fixtures/pipelines/approve.rb +0 -22
  195. data/spec/fixtures/pipelines/approve_existing_sns.rb +0 -24
  196. data/spec/lib/cli_spec.rb +0 -18
  197. data/spec/lib/pipeline/approve_spec.rb +0 -32
  198. data/spec/lib/pipeline_spec.rb +0 -12
  199. data/spec/lib/role_spec.rb +0 -12
  200. data/spec/lib/schedule_spec.rb +0 -12
  201. data/spec/lib/webhook_spec.rb +0 -12
  202. data/spec/spec_helper.rb +0 -35
@@ -0,0 +1,56 @@
1
+ # Cfn Status
2
+
3
+ Helper library provides status of CloudFormation stack.
4
+
5
+ ## Usage
6
+
7
+ Add this line to your gem's gemspec:
8
+
9
+ ```ruby
10
+ gem.add_development_dependency "cfn-status"
11
+ ```
12
+
13
+ Require it to your library:
14
+
15
+ ```ruby
16
+ require "cfn/status"
17
+ ```
18
+
19
+ Use like so:
20
+
21
+ ```ruby
22
+ status = Cfn::Status.new(stack_name)
23
+ status.run # prints out stack events
24
+ ```
25
+
26
+ The `status.run` will:
27
+
28
+ * print out the most recent stack events and return right away if the stack is in a completed state.
29
+ * print out the most recent stack events and poll for more events until the stack in a completed state.
30
+
31
+ To find out whether the most recent completed state of the stack was a success or a fail, you can use `status.success?`.
32
+
33
+ ```ruby
34
+ status.success?
35
+ ```
36
+
37
+ If you need to just wait for the stack to complete, you can also use `status.wait`.
38
+
39
+ ```ruby
40
+ status.wait
41
+ status.success?
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cfn-status.
53
+
54
+ ## License
55
+
56
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
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__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,30 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cfn/status/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cfn-status"
8
+ spec.version = Cfn::Status::VERSION
9
+ spec.authors = ["Tung Nguyen"]
10
+ spec.email = ["tongueroo@gmail.com"]
11
+
12
+ spec.summary = "CloudFormation status library"
13
+ spec.homepage = "https://github.com/tongueroo/cfn-status"
14
+ spec.license = "MIT"
15
+
16
+ # Specify which files should be added to the gem when it is released.
17
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
18
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "aws-sdk-cloudformation"
26
+
27
+ spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ end
@@ -0,0 +1,56 @@
1
+ require "aws-sdk-cloudformation"
2
+
3
+ module Cfn
4
+ module AwsService
5
+ def cfn
6
+ @cfn ||= Aws::CloudFormation::Client.new
7
+ end
8
+
9
+ def stack_exists?(stack_name)
10
+ return true if testing_update?
11
+ return false if @options[:noop]
12
+
13
+ exist = nil
14
+ begin
15
+ # When the stack does not exist an exception is raised. Example:
16
+ # Aws::CloudFormation::Errors::ValidationError: Stack with id blah does not exist
17
+ resp = cfn.describe_stacks(stack_name: stack_name)
18
+ exist = true
19
+ rescue Aws::CloudFormation::Errors::ValidationError => e
20
+ if e.message =~ /does not exist/
21
+ exist = false
22
+ elsif e.message.include?("'stackName' failed to satisfy constraint")
23
+ # Example of e.message when describe_stack with invalid stack name
24
+ # "1 validation error detected: Value 'instance_and_route53' at 'stackName' failed to satisfy constraint: Member must satisfy regular expression pattern: [a-zA-Z][-a-zA-Z0-9]*|arn:[-a-zA-Z0-9:/._+]*"
25
+ puts "Invalid stack name: #{stack_name}"
26
+ puts "Full error message: #{e.message}"
27
+ exit 1
28
+ else
29
+ raise # re-raise exception because unsure what other errors can happen
30
+ end
31
+ end
32
+ exist
33
+ end
34
+
35
+ def find_stack(stack_name)
36
+ resp = cfn.describe_stacks(stack_name: stack_name)
37
+ resp.stacks.first
38
+ rescue Aws::CloudFormation::Errors::ValidationError => e
39
+ # example: Stack with id demo-web does not exist
40
+ if e.message =~ /Stack with/ && e.message =~ /does not exist/
41
+ nil
42
+ else
43
+ raise
44
+ end
45
+ end
46
+
47
+ def rollback_complete?(stack)
48
+ stack.stack_status == 'ROLLBACK_COMPLETE'
49
+ end
50
+
51
+ def testing_update?
52
+ # TODO: Figure out how to get rid of this
53
+ ENV['TEST'] # && self.class.name == "BoltCfn::Update"
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,220 @@
1
+ require "cfn/status/version"
2
+
3
+ module Cfn
4
+ autoload :AwsService, "cfn/aws_service"
5
+
6
+ class Status
7
+ class Error < StandardError; end
8
+
9
+ include AwsService
10
+
11
+ attr_reader :events
12
+ def initialize(stack_name, options={})
13
+ @stack_name = stack_name
14
+ @options = options
15
+ reset
16
+ end
17
+
18
+ # used for the bolt cfn status command
19
+ def run
20
+ unless stack_exists?(@stack_name)
21
+ puts "The stack #{@stack_name.color(:green)} does not exist."
22
+ return true
23
+ end
24
+
25
+ resp = cfn.describe_stacks(stack_name: @stack_name)
26
+ stack = resp.stacks.first
27
+
28
+ puts "The current status for the stack #{@stack_name.color(:green)} is #{stack.stack_status.color(:green)}"
29
+ if stack.stack_status =~ /_IN_PROGRESS$/
30
+ puts "Stack events (tailing):"
31
+ # tail all events until done
32
+ @hide_time_took = true
33
+ wait
34
+ else
35
+ puts "Stack events:"
36
+ # show the last events that was user initiated
37
+ refresh_events
38
+ show_events(true)
39
+ end
40
+ success?
41
+ end
42
+
43
+ def reset
44
+ @events = [] # constantly replaced with recent events
45
+ @last_shown_event_id = nil
46
+ @stack_deletion_completed = nil
47
+ end
48
+
49
+ # check for /(_COMPLETE|_FAILED)$/ status
50
+ def wait
51
+ puts "Waiting for stack to complete"
52
+ start_time = Time.now
53
+
54
+ refresh_events
55
+ until completed || @stack_deletion_completed
56
+ show_events
57
+ end
58
+ show_events(true) # show the final event
59
+
60
+ if @stack_deletion_completed
61
+ puts "Stack #{@stack_name} deleted."
62
+ return
63
+ end
64
+
65
+ if last_event_status =~ /_FAILED/
66
+ puts "Stack failed: #{last_event_status}".color(:red)
67
+ puts "Stack reason #{@events[0]["resource_status_reason"]}".color(:red)
68
+ elsif last_event_status =~ /_ROLLBACK_/
69
+ puts "Stack rolled back: #{last_event_status}".color(:red)
70
+ else # success
71
+ puts "Stack success status: #{last_event_status}".color(:green)
72
+ end
73
+
74
+ # Never gets here when deleting a stack because the describe stack returns nothing
75
+ # once the stack is deleted. Gets here for stack create and update though.
76
+ return if @hide_time_took # set in run
77
+ took = Time.now - start_time
78
+ puts "Time took for stack deployment: #{pretty_time(took).color(:green)}."
79
+ success?
80
+ end
81
+
82
+ def completed
83
+ last_event_status =~ /(_COMPLETE|_FAILED)$/ &&
84
+ @events[0]["logical_resource_id"] == @stack_name &&
85
+ @events[0]["resource_type"] == "AWS::CloudFormation::Stack"
86
+ end
87
+
88
+ def last_event_status
89
+ @events[0]["resource_status"]
90
+ end
91
+
92
+ # Only shows new events
93
+ def show_events(final=false)
94
+ if @last_shown_event_id.nil?
95
+ i = find_index(:start, final)
96
+ print_events(i)
97
+ else
98
+ i = find_index(:last_shown, final)
99
+ # puts "last_shown index #{i}"
100
+ print_events(i-1) unless i == 0
101
+ end
102
+
103
+ return if final
104
+ sleep 5 unless ENV['TEST']
105
+ refresh_events
106
+ end
107
+
108
+ def print_events(i)
109
+ @events[0..i].reverse.each do |e|
110
+ print_event(e)
111
+ end
112
+ @last_shown_event_id = @events[0]["event_id"]
113
+ # puts "@last_shown_event_id #{@last_shown_event_id.inspect}"
114
+ end
115
+
116
+ def print_event(e)
117
+ message = [
118
+ event_time(e["timestamp"]),
119
+ e["resource_status"],
120
+ e["resource_type"],
121
+ e["logical_resource_id"],
122
+ e["resource_status_reason"]
123
+ ].join(" ")
124
+ message = message.color(:red) if e["resource_status"] =~ /_FAILED/
125
+ puts message
126
+ end
127
+
128
+ # https://stackoverflow.com/questions/18000432/rails-12-hour-am-pm-range-for-a-day
129
+ def event_time(timestamp)
130
+ Time.parse(timestamp.to_s).localtime.strftime("%I:%M:%S%p")
131
+ end
132
+
133
+ # refreshes the loaded events in memory
134
+ def refresh_events
135
+ resp = cfn.describe_stack_events(stack_name: @stack_name)
136
+ @events = resp["stack_events"]
137
+ rescue Aws::CloudFormation::Errors::ValidationError => e
138
+ if e.message =~ /Stack .* does not exis/
139
+ @stack_deletion_completed = true
140
+ else
141
+ raise
142
+ end
143
+ end
144
+
145
+ def find_index(name, final=false)
146
+ send("#{name}_index", final)
147
+ end
148
+
149
+ def start_index(final=false)
150
+ index = @events.find_index do |event|
151
+ event["resource_type"] == "AWS::CloudFormation::Stack" &&
152
+ event["resource_status_reason"] == "User Initiated"
153
+ end
154
+ # Instead of paginating until until we find the first "User Initiated" "AWS::CloudFormation::Stack" event
155
+ # we'll use the max.
156
+ index ? index : @events.size - 1
157
+ end
158
+
159
+ def last_shown_index(_)
160
+ @events.find_index do |event|
161
+ event["event_id"] == @last_shown_event_id
162
+ end
163
+ end
164
+
165
+ def success?
166
+ resource_status = @events[0]["resource_status"]
167
+ %w[CREATE_COMPLETE UPDATE_COMPLETE].include?(resource_status)
168
+ end
169
+
170
+ def update_rollback?
171
+ @events[0]["resource_status"] == "UPDATE_ROLLBACK_COMPLETE"
172
+ end
173
+
174
+ def find_update_failed_event
175
+ i = @events.find_index do |event|
176
+ event["resource_type"] == "AWS::CloudFormation::Stack" &&
177
+ event["resource_status_reason"] == "User Initiated"
178
+ end
179
+
180
+ @events[0..i].reverse.find do |e|
181
+ e["resource_status"] == "UPDATE_FAILED"
182
+ end
183
+ end
184
+
185
+ def rollback_error_message
186
+ return unless update_rollback?
187
+
188
+ event = find_update_failed_event
189
+ return unless event
190
+
191
+ reason = event["resource_status_reason"]
192
+ messages_map.each do |pattern, message|
193
+ if reason =~ pattern
194
+ return message
195
+ end
196
+ end
197
+
198
+ reason # default message is original reason if not found in messages map
199
+ end
200
+
201
+ def messages_map
202
+ {
203
+ /CloudFormation cannot update a stack when a custom-named resource requires replacing/ => "A workaround is to run ufo again with STATIC_NAME=0 and to switch to dynamic names for resources. Then run ufo again with STATIC_NAME=1 to get back to statically name resources. Note, there are caveats with the workaround.",
204
+ /cannot be associated with more than one load balancer/ => "There's was an issue updating the stack. Target groups can only be associated with one load balancer at a time. The workaround for this is to use UFO_FORCE_TARGET_GROUP=1 and run the command again. This will force the recreation of the target group resource.",
205
+ /SetSubnets is not supported for load balancers of type/ => "Changing subnets for Network Load Balancers is currently not supported. You can try workarouding this with UFO_FORCE_ELB=1 and run the command again. This will force the recreation of the elb resource."
206
+ }
207
+ end
208
+
209
+ # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
210
+ def pretty_time(total_seconds)
211
+ minutes = (total_seconds / 60) % 60
212
+ seconds = total_seconds % 60
213
+ if total_seconds < 60
214
+ "#{seconds.to_i}s"
215
+ else
216
+ "#{minutes.to_i}m #{seconds.to_i}s"
217
+ end
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,5 @@
1
+ module Cfn
2
+ class Status
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,81 @@
1
+ RSpec.describe Cfn::Status do
2
+ it "has a version number" do
3
+ expect(Cfn::Status::VERSION).not_to be nil
4
+ end
5
+
6
+ let(:status) do
7
+ status = Cfn::Status.new("test-stack")
8
+ allow(status).to receive(:cfn).and_return(cfn)
9
+ status
10
+ end
11
+ let(:cfn) do
12
+ service = double("service").as_null_object
13
+ allow(service).to receive(:describe_stacks).and_return(stack_status)
14
+ allow(service).to receive(:describe_stack_events).and_return(stack_events)
15
+ service
16
+ end
17
+
18
+ context "in progress" do
19
+ let(:stack_status) { "UPDATE_IN_PROGRESS" }
20
+ let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-in-progress.json")) }
21
+ it "lists events since user initiated event" do
22
+ status.refresh_events
23
+ i = status.find_index(:start)
24
+ expect(i).to eq 15
25
+ # uncomment to view and debug
26
+ # status.show_events
27
+ # puts "****"
28
+ # status.show_events # show not show anything
29
+ end
30
+
31
+ it "lists events since last shown event" do
32
+ # first display
33
+ status.refresh_events
34
+ i = status.find_index(:start)
35
+ expect(i).to eq 15
36
+
37
+ # move the last event back in time 4 events, so should print 3 events
38
+ status.instance_variable_set(:@last_shown_event_id, "TargetGroup-ec634c43-b887-4bde-a525-7c69782865a6")
39
+
40
+ captured_events = []
41
+ allow(status).to receive(:print_event) do |e|
42
+ captured_events << "#{e["resource_type"]} #{e["resource_status"]}"
43
+ end
44
+ status.show_events
45
+ expect(captured_events).to eq([
46
+ "AWS::ElasticLoadBalancingV2::LoadBalancer DELETE_IN_PROGRESS",
47
+ "AWS::ElasticLoadBalancingV2::LoadBalancer DELETE_COMPLETE",
48
+ "AWS::EC2::SecurityGroup DELETE_IN_PROGRESS",
49
+ ])
50
+ end
51
+ end
52
+
53
+ context "complete" do
54
+ let(:stack_status) { "UPDATE_COMPLETE" }
55
+ let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-complete.json")) }
56
+ it "lists events all the way to completion" do
57
+ status.refresh_events
58
+ i = status.find_index(:start)
59
+ expect(i).to eq 17
60
+ # uncomment to view and debug
61
+ # status.show_events
62
+ end
63
+ end
64
+
65
+ context "update_rollback" do
66
+ let(:stack_status) { "UPDATE_ROLLBACK_COMPLETE" }
67
+ let(:stack_events) { JSON.load(IO.read("spec/fixtures/cfn/stack-events-update-rollback-complete.json")) }
68
+ it "lists events all the way to update rollback complete" do
69
+ status.refresh_events
70
+ expect(status.success?).to be false
71
+ expect(status.update_rollback?).to be true
72
+ expect(status.rollback_error_message).to include("STATIC_NAME")
73
+
74
+ # i = status.find_index(:start)
75
+ # expect(i).to eq 17
76
+ # uncomment to view and debug
77
+ # status.show_events
78
+ end
79
+ end
80
+ end
81
+