jets 2.3.19 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.gitmodules +0 -3
  3. data/.python-version +1 -1
  4. data/.ruby-version +1 -1
  5. data/CHANGELOG.md +28 -2
  6. data/README.md +2 -2
  7. data/backers.md +1 -0
  8. data/jets.gemspec +11 -10
  9. data/lib/jets.rb +9 -13
  10. data/lib/jets/application.rb +9 -2
  11. data/lib/jets/application/defaults.rb +17 -15
  12. data/lib/jets/autoloaders.rb +15 -1
  13. data/lib/jets/booter.rb +3 -3
  14. data/lib/jets/builders/code_builder.rb +16 -15
  15. data/lib/jets/builders/gem_replacer.rb +3 -16
  16. data/lib/jets/builders/lambda_layer.rb +4 -5
  17. data/lib/jets/builders/ruby_packager.rb +18 -42
  18. data/lib/jets/builders/tidy.rb +1 -2
  19. data/lib/jets/bundle.rb +6 -0
  20. data/lib/jets/cfn/builders/api_gateway_builder.rb +61 -7
  21. data/lib/jets/cfn/ship.rb +2 -1
  22. data/lib/jets/cli.rb +6 -1
  23. data/lib/jets/commands/base.rb +1 -1
  24. data/lib/jets/commands/call.rb +14 -1
  25. data/lib/jets/commands/clean.rb +1 -1
  26. data/lib/jets/commands/clean/base.rb +1 -1
  27. data/lib/jets/commands/configure.rb +51 -0
  28. data/lib/jets/commands/delete.rb +2 -2
  29. data/lib/jets/commands/gems.rb +2 -10
  30. data/lib/jets/commands/help/call.md +8 -0
  31. data/lib/jets/commands/help/gems/check.md +3 -5
  32. data/lib/jets/commands/main.rb +9 -1
  33. data/lib/jets/commands/new.rb +9 -1
  34. data/lib/jets/commands/sequence.rb +6 -0
  35. data/lib/jets/commands/templates/skeleton/Gemfile.tt +1 -1
  36. data/lib/jets/commands/templates/skeleton/config/application.rb.tt +1 -1
  37. data/lib/jets/commands/templates/skeleton/public/index.html.tt +1 -1
  38. data/lib/jets/commands/url.rb +1 -0
  39. data/lib/jets/controller/base.rb +14 -4
  40. data/lib/jets/controller/middleware/main.rb +2 -1
  41. data/lib/jets/controller/params.rb +26 -4
  42. data/lib/jets/controller/rack/env.rb +18 -1
  43. data/lib/jets/controller/rendering.rb +5 -2
  44. data/lib/jets/controller/rendering/rack_renderer.rb +7 -1
  45. data/lib/jets/core.rb +12 -4
  46. data/lib/jets/dotenv/ssm.rb +18 -4
  47. data/lib/jets/generator.rb +2 -3
  48. data/lib/jets/internal/app/functions/jets/base_path.rb +10 -149
  49. data/lib/jets/internal/app/functions/jets/base_path_mapping.rb +81 -0
  50. data/lib/jets/internal/app/shared/functions/jets/s3_bucket_config.rb +14 -24
  51. data/lib/jets/resource/api_gateway/base_path/function.rb +6 -1
  52. data/lib/jets/resource/api_gateway/deployment.rb +2 -0
  53. data/lib/jets/resource/api_gateway/rest_api/logical_id.rb +34 -0
  54. data/lib/jets/resource/api_gateway/rest_api/logical_id/message.rb +49 -0
  55. data/lib/jets/resource/child_stack/api_deployment.rb +2 -0
  56. data/lib/jets/resource/lambda/function.rb +1 -1
  57. data/lib/jets/router/dsl.rb +7 -1
  58. data/lib/jets/router/method_creator/code.rb +1 -1
  59. data/lib/jets/router/scope.rb +7 -3
  60. data/lib/jets/spec_helpers/controllers.rb +10 -3
  61. data/lib/jets/spec_helpers/controllers/request.rb +12 -5
  62. data/lib/jets/stack/main/dsl/lambda.rb +1 -1
  63. data/lib/jets/turbo.rb +1 -0
  64. data/lib/jets/version.rb +1 -1
  65. metadata +51 -58
  66. data/vendor/cfn-status/CHANGELOG.md +0 -14
  67. data/vendor/cfn-status/Gemfile +0 -4
  68. data/vendor/cfn-status/LICENSE.txt +0 -21
  69. data/vendor/cfn-status/README.md +0 -56
  70. data/vendor/cfn-status/Rakefile +0 -6
  71. data/vendor/cfn-status/bin/console +0 -14
  72. data/vendor/cfn-status/bin/setup +0 -8
  73. data/vendor/cfn-status/cfn-status.gemspec +0 -30
  74. data/vendor/cfn-status/lib/cfn-status.rb +0 -1
  75. data/vendor/cfn-status/lib/cfn_status.rb +0 -245
  76. data/vendor/cfn-status/lib/cfn_status/aws_service.rb +0 -51
  77. data/vendor/cfn-status/lib/cfn_status/version.rb +0 -3
  78. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-1.json +0 -1103
  79. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-2.json +0 -1104
  80. data/vendor/cfn-status/spec/fixtures/cfn/pages/fresh/describe_stack_events-3.json +0 -1103
  81. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-1.json +0 -1103
  82. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-2.json +0 -1104
  83. data/vendor/cfn-status/spec/fixtures/cfn/pages/updating/describe_stack_events-3.json +0 -1103
  84. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-complete.json +0 -1080
  85. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-in-progress.json +0 -1080
  86. data/vendor/cfn-status/spec/fixtures/cfn/stack-events-update-rollback-complete.json +0 -1086
  87. data/vendor/cfn-status/spec/lib/cfn_status_spec.rb +0 -153
  88. data/vendor/cfn-status/spec/spec_helper.rb +0 -14
@@ -1,14 +0,0 @@
1
- # Change Log
2
-
3
- All notable changes to this project will be documented in this file.
4
- This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
-
6
- ## [UNRELEASED]
7
- - #1 Breaking change: rename Rename to CfnStatus, cfn/status to cfn_status
8
- - Handle large templates and long stack_events via paginating the cfn.describe_stack_events until
9
-
10
- ## [0.2.0]
11
- - allow require "cfn-status" to work also
12
-
13
- ## [0.1.0]
14
- - Initial release
@@ -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 = CfnStatus.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 = CfnStatus::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 +0,0 @@
1
- require "cfn_status"
@@ -1,245 +0,0 @@
1
- require "cfn_status/version"
2
-
3
- class CfnStatus
4
- class Error < StandardError; end
5
-
6
- autoload :AwsService, "cfn_status/aws_service"
7
- include AwsService
8
-
9
- attr_reader :events
10
- def initialize(stack_name, options={})
11
- @stack_name = stack_name
12
- @options = options
13
- reset
14
- end
15
-
16
- def run
17
- unless stack_exists?(@stack_name)
18
- puts "The stack #{@stack_name.color(:green)} does not exist."
19
- return true
20
- end
21
-
22
- resp = cfn.describe_stacks(stack_name: @stack_name)
23
- stack = resp.stacks.first
24
-
25
- 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
- puts "Stack events (tailing):"
28
- # tail all events until done
29
- @hide_time_took = true
30
- wait
31
- else
32
- puts "Stack events:"
33
- # show the last events that was user initiated
34
- refresh_events
35
- show_events(final: true)
36
- end
37
- success?
38
- end
39
-
40
- def reset
41
- @events = [] # constantly replaced with recent events
42
- @last_shown_event_id = nil
43
- @stack_deletion_completed = nil
44
- end
45
-
46
- # check for /(_COMPLETE|_FAILED)$/ status
47
- def wait
48
- puts "Waiting for stack to complete"
49
- start_time = Time.now
50
-
51
- refresh_events
52
- until completed || @stack_deletion_completed
53
- show_events(final: false)
54
- end
55
- show_events(final: true) # show the final event
56
-
57
- if @stack_deletion_completed
58
- puts "Stack #{@stack_name} deleted."
59
- return
60
- end
61
-
62
- # Never gets beyond here when deleting a stack because the describe stack returns nothing
63
- # once the stack is deleted. Gets here for stack create and update though.
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
- return if @hide_time_took # set in run
75
- took = Time.now - start_time
76
- puts "Time took for stack deployment: #{pretty_time(took).color(:green)}."
77
- success?
78
- end
79
-
80
- def completed
81
- last_event_status =~ /(_COMPLETE|_FAILED)$/ &&
82
- @events[0]["logical_resource_id"] == @stack_name &&
83
- @events[0]["resource_type"] == "AWS::CloudFormation::Stack"
84
- end
85
-
86
- def last_event_status
87
- @events[0]["resource_status"]
88
- end
89
-
90
- # Only shows new events
91
- def show_events(final: false)
92
- if @last_shown_event_id.nil?
93
- i = start_index
94
- print_events(i)
95
- else
96
- i = last_shown_index
97
- # puts "last_shown index #{i}"
98
- print_events(i-1) unless i == 0
99
- end
100
-
101
- return if final
102
- sleep 5 unless ENV['TEST']
103
- refresh_events
104
- end
105
-
106
- def print_events(i)
107
- @events[0..i].reverse.each do |e|
108
- print_event(e)
109
- end
110
-
111
- @last_shown_event_id = @events[0]["event_id"]
112
- # puts "@last_shown_event_id #{@last_shown_event_id.inspect}"
113
- end
114
-
115
- def print_event(e)
116
- message = [
117
- event_time(e["timestamp"]),
118
- e["resource_status"],
119
- e["resource_type"],
120
- e["logical_resource_id"],
121
- e["resource_status_reason"]
122
- ].join(" ")
123
- message = message.color(:red) if e["resource_status"] =~ /_FAILED/
124
- puts message
125
- end
126
-
127
- # https://stackoverflow.com/questions/18000432/rails-12-hour-am-pm-range-for-a-day
128
- def event_time(timestamp)
129
- Time.parse(timestamp.to_s).localtime.strftime("%I:%M:%S%p")
130
- end
131
-
132
- # Refreshes the @events in memory.
133
- #
134
- def refresh_events
135
- resp = cfn.describe_stack_events(stack_name: @stack_name)
136
- @events = resp["stack_events"]
137
-
138
- # refresh_events uses add_events_pages and resp["next_token"] to load all events until:
139
- #
140
- # 1. @last_shown_event_id found - if @last_shown_event_id is set
141
- # 2. User Initiated Event found - fallback when @last_shown_event_id is not set
142
- #
143
- if @last_shown_event_id
144
- add_events_pages(resp, :last_shown_index)
145
- else
146
- add_events_pages(resp, :start_index)
147
- end
148
-
149
- rescue Aws::CloudFormation::Errors::ValidationError => e
150
- if e.message =~ /Stack .* does not exis/
151
- @stack_deletion_completed = true
152
- else
153
- raise
154
- end
155
- end
156
-
157
- # Examples:
158
- #
159
- # add_events_pages(:start_index)
160
- # add_events_pages(:last_shown_index)
161
- #
162
- # if index_method is start_index
163
- # loops add_events_pagess through describe_stack_events until "User Initiated" is found
164
- #
165
- # if index_method is last_shown_index
166
- # loops add_events_pagess through describe_stack_events until last_shown_index is found
167
- #
168
- def add_events_pages(resp, index_method)
169
- found = !!send(index_method)
170
- until found
171
- resp = cfn.describe_stack_events(stack_name: @stack_name, next_token: resp["next_token"])
172
- @events += resp["stack_events"]
173
- found = !!send(index_method)
174
- end
175
- end
176
-
177
- # Should always find a "User Initiated" stack event when @last_shown_index is not set
178
- def start_index
179
- @events.find_index do |event|
180
- event["resource_type"] == "AWS::CloudFormation::Stack" &&
181
- event["resource_status_reason"] == "User Initiated"
182
- end
183
- end
184
-
185
- def last_shown_index
186
- @events.find_index do |event|
187
- event["event_id"] == @last_shown_event_id
188
- end
189
- end
190
-
191
- def success?
192
- resource_status = @events[0]["resource_status"]
193
- %w[CREATE_COMPLETE UPDATE_COMPLETE].include?(resource_status)
194
- end
195
-
196
- def update_rollback?
197
- @events[0]["resource_status"] == "UPDATE_ROLLBACK_COMPLETE"
198
- end
199
-
200
- def find_update_failed_event
201
- i = @events.find_index do |event|
202
- event["resource_type"] == "AWS::CloudFormation::Stack" &&
203
- event["resource_status_reason"] == "User Initiated"
204
- end
205
-
206
- @events[0..i].reverse.find do |e|
207
- e["resource_status"] == "UPDATE_FAILED"
208
- end
209
- end
210
-
211
- def rollback_error_message
212
- return unless update_rollback?
213
-
214
- event = find_update_failed_event
215
- return unless event
216
-
217
- reason = event["resource_status_reason"]
218
- messages_map.each do |pattern, message|
219
- if reason =~ pattern
220
- return message
221
- end
222
- end
223
-
224
- reason # default message is original reason if not found in messages map
225
- end
226
-
227
- def messages_map
228
- {
229
- /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.",
230
- /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.",
231
- /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."
232
- }
233
- end
234
-
235
- # http://stackoverflow.com/questions/4175733/convert-duration-to-hoursminutesseconds-or-similar-in-rails-3-or-ruby
236
- def pretty_time(total_seconds)
237
- minutes = (total_seconds / 60) % 60
238
- seconds = total_seconds % 60
239
- if total_seconds < 60
240
- "#{seconds.to_i}s"
241
- else
242
- "#{minutes.to_i}m #{seconds.to_i}s"
243
- end
244
- end
245
- end
@@ -1,51 +0,0 @@
1
- require "aws-sdk-cloudformation"
2
-
3
- class CfnStatus
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 ENV['TEST']
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
- 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
- end
51
- end