cody 0.9.5 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -9
  3. data/CHANGELOG.md +23 -0
  4. data/Gemfile +0 -2
  5. data/cody.gemspec +3 -3
  6. data/lib/cody.rb +4 -8
  7. data/lib/cody/aws_services.rb +1 -1
  8. data/lib/cody/aws_services/helpers.rb +20 -3
  9. data/lib/cody/cli.rb +4 -13
  10. data/lib/cody/{badge.rb → cli/badge.rb} +1 -1
  11. data/lib/cody/{base.rb → cli/base.rb} +9 -3
  12. data/lib/cody/{delete.rb → cli/delete.rb} +3 -3
  13. data/lib/cody/cli/deploy.rb +7 -0
  14. data/lib/cody/cli/help.rb +11 -0
  15. data/lib/cody/{help → cli/help}/deploy.md +0 -0
  16. data/lib/cody/{help → cli/help}/init.md +0 -0
  17. data/lib/cody/{help → cli/help}/logs.md +0 -0
  18. data/lib/cody/{help → cli/help}/start.md +0 -0
  19. data/lib/cody/{help → cli/help}/stop.md +0 -0
  20. data/lib/cody/{init.rb → cli/init.rb} +1 -2
  21. data/lib/cody/{list.rb → cli/list.rb} +23 -4
  22. data/lib/cody/{logs.rb → cli/logs.rb} +3 -2
  23. data/lib/cody/{sequence.rb → cli/sequence.rb} +3 -3
  24. data/lib/cody/{start.rb → cli/start.rb} +3 -3
  25. data/lib/cody/{status.rb → cli/status.rb} +2 -1
  26. data/lib/cody/{stop.rb → cli/stop.rb} +2 -1
  27. data/lib/cody/command.rb +11 -0
  28. data/lib/cody/core.rb +5 -5
  29. data/lib/cody/dsl/base.rb +20 -0
  30. data/lib/cody/dsl/project.rb +54 -49
  31. data/lib/cody/dsl/role.rb +11 -11
  32. data/lib/cody/dsl/schedule.rb +8 -8
  33. data/lib/cody/list/no_builds_project.rb +9 -0
  34. data/lib/cody/list/project.rb +5 -2
  35. data/lib/cody/project.rb +26 -29
  36. data/lib/cody/role.rb +22 -23
  37. data/lib/cody/schedule.rb +39 -40
  38. data/lib/cody/stack.rb +16 -71
  39. data/lib/cody/stack/base.rb +104 -0
  40. data/lib/cody/{create.rb → stack/create.rb} +2 -2
  41. data/lib/cody/{update.rb → stack/update.rb} +2 -2
  42. data/lib/cody/tailer.rb +1 -1
  43. data/lib/cody/version.rb +1 -1
  44. data/lib/template/project/buildspec.yml +1 -1
  45. data/lib/template/project/project.rb.tt +5 -19
  46. metadata +66 -70
  47. data/lib/cody/completer.rb +0 -159
  48. data/lib/cody/completer/script.rb +0 -6
  49. data/lib/cody/completer/script.sh +0 -10
  50. data/lib/cody/deploy.rb +0 -40
  51. data/lib/cody/help.rb +0 -9
  52. data/lib/cody/help/completion.md +0 -22
  53. data/lib/cody/help/completion_script.md +0 -3
  54. data/vendor/aws_data/CHANGELOG.md +0 -7
  55. data/vendor/aws_data/Gemfile +0 -4
  56. data/vendor/aws_data/LICENSE.txt +0 -21
  57. data/vendor/aws_data/README.md +0 -42
  58. data/vendor/aws_data/Rakefile +0 -6
  59. data/vendor/aws_data/aws_data.gemspec +0 -30
  60. data/vendor/aws_data/bin/console +0 -14
  61. data/vendor/aws_data/bin/setup +0 -8
  62. data/vendor/aws_data/lib/aws_data.rb +0 -91
  63. data/vendor/aws_data/lib/aws_data/version.rb +0 -3
  64. data/vendor/aws_data/spec/aws_data_spec.rb +0 -5
  65. data/vendor/aws_data/spec/spec_helper.rb +0 -14
  66. data/vendor/cfn-status/Gemfile +0 -4
  67. data/vendor/cfn-status/LICENSE.txt +0 -21
  68. data/vendor/cfn-status/README.md +0 -56
  69. data/vendor/cfn-status/Rakefile +0 -6
  70. data/vendor/cfn-status/bin/console +0 -14
  71. data/vendor/cfn-status/bin/setup +0 -8
  72. data/vendor/cfn-status/cfn-status.gemspec +0 -30
  73. data/vendor/cfn-status/lib/cfn/aws_service.rb +0 -56
  74. data/vendor/cfn-status/lib/cfn/status.rb +0 -220
  75. data/vendor/cfn-status/lib/cfn/status/version.rb +0 -5
  76. data/vendor/cfn-status/spec/cfn/status_spec.rb +0 -81
  77. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +0 -1080
  78. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +0 -1080
  79. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +0 -1086
  80. data/vendor/cfn-status/spec/spec_helper.rb +0 -14
  81. data/vendor/cfn_camelizer/CHANGELOG.md +0 -10
  82. data/vendor/cfn_camelizer/Gemfile +0 -4
  83. data/vendor/cfn_camelizer/LICENSE.txt +0 -21
  84. data/vendor/cfn_camelizer/README.md +0 -40
  85. data/vendor/cfn_camelizer/Rakefile +0 -6
  86. data/vendor/cfn_camelizer/bin/console +0 -14
  87. data/vendor/cfn_camelizer/bin/setup +0 -8
  88. data/vendor/cfn_camelizer/cfn_camelizer.gemspec +0 -32
  89. data/vendor/cfn_camelizer/lib/camelizer.yml +0 -33
  90. data/vendor/cfn_camelizer/lib/cfn_camelizer.rb +0 -92
  91. data/vendor/cfn_camelizer/lib/cfn_camelizer/version.rb +0 -3
  92. data/vendor/cfn_camelizer/spec/cfn_camelizer_spec.rb +0 -79
  93. data/vendor/cfn_camelizer/spec/spec_helper.rb +0 -14
@@ -1,3 +0,0 @@
1
- class AwsData
2
- VERSION = "0.1.0"
3
- end
@@ -1,5 +0,0 @@
1
- RSpec.describe AwsData do
2
- it "has a version number" do
3
- expect(AwsData::VERSION).not_to be nil
4
- end
5
- end
@@ -1,14 +0,0 @@
1
- require "bundler/setup"
2
- require "aws_data"
3
-
4
- RSpec.configure do |config|
5
- # Enable flags like --only-failures and --next-failure
6
- config.example_status_persistence_file_path = ".rspec_status"
7
-
8
- # Disable RSpec exposing methods globally on `Module` and `main`
9
- config.disable_monkey_patching!
10
-
11
- config.expect_with :rspec do |c|
12
- c.syntax = :expect
13
- end
14
- end
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- # Specify your gem's dependencies in cfn-status.gemspec
4
- gemspec
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2019 Tung Nguyen
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,56 +0,0 @@
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).
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -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__)
@@ -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
@@ -1,30 +0,0 @@
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
@@ -1,56 +0,0 @@
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
@@ -1,220 +0,0 @@
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