jets 1.6.7 → 1.6.8

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: 69556eafe9fdb5824e36659f2a2b9eb55b0a597fd9f0d1322bb73292b0a4d57d
4
- data.tar.gz: d33bf0cc0a22f7e6dd83cce09e6c4a1087943cacc2e859976d3f0fa43137db01
3
+ metadata.gz: 58be2e98e5ac05eb8b721e2dd3561561ec887eda18bdf17baeb75b7f0e1b73bb
4
+ data.tar.gz: ec9bad41783087450f9fac8f62f5032cefeb6be701fb1f774ed1277adccdc7e4
5
5
  SHA512:
6
- metadata.gz: ffaf7153c8ad19c8d744fc9b87aff4929b4734b39a04c2d2494ec82c2615965c2b6a2a56ecaef0a1a20bc504d1a8ba9181bf1a062057ba6276cb5be7882b9511
7
- data.tar.gz: 6b7655a80691cf8cbc455a303a2dfe2a633be92927dc90810d83c4cf81b4130561f4ff8f3e074085c89f26a3fd9fe20f3e7f30810048ade7bb4a5c5bb34d723e
6
+ metadata.gz: 874405e9a58ac61ed2688ef853b0bad7008cec7b1799581de581607ca2af4d7524ba6ede39c1805c906bb960375192b7736b177f673115a41fbe964b4ae3528f
7
+ data.tar.gz: 44b70405f81f129a3f4aeb928e7afb4d1702ab2d671d22344cbd87a8be183667468d345a3a536a45d2047a1721bbafc463adfe98b9001dee4fc57f7e61ce4f08
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
5
5
 
6
+ ## [1.6.8]
7
+ - #181 cors middleware
8
+ - #182 more robust handler shim
9
+ - fix polymorphic get_source_path path
10
+ - only upgrade config.ru if exists
11
+
6
12
  ## [1.6.7]
7
13
  - update faq: JETS_AGREE no interruption flag
8
14
 
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: .
13
13
  specs:
14
- jets (1.6.7)
14
+ jets (1.6.8)
15
15
  activerecord (~> 5.2.1)
16
16
  activesupport (~> 5.2.1)
17
17
  aws-sdk-apigateway
@@ -120,7 +120,7 @@ GEM
120
120
  loofah (~> 2.2, >= 2.2.2)
121
121
  jmespath (1.4.0)
122
122
  json (2.1.0)
123
- kramdown (2.0.0)
123
+ kramdown (2.1.0)
124
124
  loofah (2.2.3)
125
125
  crass (~> 1.0.2)
126
126
  nokogiri (>= 1.5.9)
@@ -127,7 +127,7 @@ class Jets::Builders
127
127
  folder = original_path.sub(/\.rb$/,'')
128
128
  lang_folder = "#{folder}/#{task.lang}"
129
129
  root = Jets.root unless original_path.include?("lib/jets/internal")
130
- "#{root}#{lang_folder}/#{task.meth}#{task.lang_ext}"
130
+ "#{root}/#{lang_folder}/#{task.meth}#{task.lang_ext}"
131
131
  end
132
132
 
133
133
  # Builds and copies over the native source code: python or node
@@ -2,6 +2,11 @@ require "bundler/setup"
2
2
  require "jets"
3
3
  Jets.once # runs once in lambda execution context
4
4
 
5
- <% @vars.functions.each do |function_name| -%>
6
- Jets.handler(self, "<%= @vars.handler_for(function_name) %>")
5
+ <% @vars.functions.each do |function_name|
6
+ handler = @vars.handler_for(function_name)
7
+ meth = handler.split('.').last
8
+ -%>
9
+ def <%= meth -%>(event:, context:)
10
+ Jets.process(event, context, "<%= handler -%>")
11
+ end
7
12
  <% end %>
@@ -78,11 +78,13 @@ module Jets::Commands
78
78
  end
79
79
 
80
80
  def update_config_ru
81
- config_ru = File.read("#{Jets.root}/config.ru")
81
+ src = "#{Jets.root}/config.ru"
82
+ return unless File.exist?(src)
83
+ config_ru = File.read(src)
82
84
  return if config_ru.include?("Jets.boot")
83
85
 
84
86
  src = File.expand_path("templates/skeleton/config.ru", File.dirname(__FILE__))
85
- dest = "#{Jets.root}/config.ru"
87
+ dest = src
86
88
  puts "Update: config.ru"
87
89
  FileUtils.cp(src, dest)
88
90
  end
@@ -1,4 +1,5 @@
1
1
  module Jets::Controller::Middleware
2
+ autoload :Cors, "jets/controller/middleware/cors"
2
3
  autoload :Local, "jets/controller/middleware/local"
3
4
  autoload :Main, "jets/controller/middleware/main"
4
5
  end
@@ -0,0 +1,59 @@
1
+ # The rack cors middleware handles all types of requests locally, this includes the OPTIONS request.
2
+ # Remotely on lambda, the rack cors middleware handles all requests except the OPTIONS request.
3
+ # The options request is handled by a OPTIONS API Gateway Method Mock. This is to allow it to bypass
4
+ # API Gateway authorizers.
5
+ module Jets::Controller::Middleware
6
+ class Cors
7
+ extend Memoist
8
+
9
+ def initialize(app)
10
+ @app = app
11
+ end
12
+
13
+ def call(env)
14
+ if env['REQUEST_METHOD'] == 'OPTIONS'
15
+ return [200, cors_headers(true), StringIO.new]
16
+ end
17
+
18
+ status, headers, body = @app.call(env)
19
+ cors_headers.each do |k,v|
20
+ headers[k] ||= v
21
+ end
22
+ [status, headers, body]
23
+ end
24
+
25
+ private
26
+ def cors_headers(preflight=false)
27
+ headers = case Jets.config.cors
28
+ when true
29
+ {
30
+ "access-control-allow-origin" => "*", # Required for CORS support to work
31
+ "access-control-allow-credentials" => "true" # Required for cookies, authorization headers with HTTPS
32
+ }
33
+ when String
34
+ {
35
+ "access-control-allow-origin" => Jets.config.cors, # contains Hash with Access-Control-Allow-* values
36
+ "access-control-allow-credentials" => "true" # Required for cookies, authorization headers with HTTPS
37
+ }
38
+ when Hash
39
+ Jets.config.cors # contains Hash with Access-Control-Allow-* values
40
+ else
41
+ {}
42
+ end
43
+
44
+ headers.merge!(preflight_headers) if preflight
45
+ headers
46
+ end
47
+
48
+ # Preflight OPTIONS request has extra headers.
49
+ # This is only used locally. Remotely on AWS Lambda, OPTIONS requests are handled by an API Gateway Method.
50
+ def preflight_headers
51
+ # FYI: Jets as part of the rack processing normalizes the casing of these headers eventually.
52
+ # IE: Access-Control-Allow-Methods
53
+ {
54
+ "access-control-allow-methods" => "OPTIONS,GET",
55
+ "access-control-allow-headers" => "Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,X-Amz-User-Agent",
56
+ }
57
+ end
58
+ end
59
+ end
@@ -22,7 +22,6 @@ module Jets::Controller::Rendering
22
22
  base64 = normalized_base64_option(@options)
23
23
 
24
24
  headers = @options[:headers] || {}
25
- headers = cors_headers.merge(headers)
26
25
  set_content_type!(status, headers)
27
26
  # x-jets-base64 to convert this Rack triplet to a API Gateway hash structure later
28
27
  headers["x-jets-base64"] = base64 ? 'yes' : 'no' # headers values must be Strings
@@ -186,25 +185,6 @@ module Jets::Controller::Rendering
186
185
  base64
187
186
  end
188
187
 
189
- def cors_headers
190
- case Jets.config.cors
191
- when true
192
- {
193
- "Access-Control-Allow-Origin" => "*", # Required for CORS support to work
194
- "Access-Control-Allow-Credentials" => "true" # Required for cookies, authorization headers with HTTPS
195
- }
196
- when String
197
- {
198
- "Access-Control-Allow-Origin" => Jets.config.cors, # contains Hash with Access-Control-Allow-* values
199
- "Access-Control-Allow-Credentials" => "true" # Required for cookies, authorization headers with HTTPS
200
- }
201
- when Hash
202
- Jets.config.cors # contains Hash with Access-Control-Allow-* values
203
- else
204
- {}
205
- end
206
- end
207
-
208
188
  class << self
209
189
  def setup!
210
190
  require "action_controller"
@@ -183,14 +183,6 @@ module Jets::Core
183
183
  end
184
184
  end
185
185
 
186
- # Example: Jets.handler(self, "handlers/controllers/posts_controller.index")
187
- def handler(lambda_context, handler)
188
- meth = handler.split('.').last
189
- lambda_context.send(:define_method, meth) do |event:, context:|
190
- Jets.process(event, context, handler)
191
- end
192
- end
193
-
194
186
  def once
195
187
  boot
196
188
  override_lambda_ruby_runtime
@@ -8,6 +8,7 @@ module Jets::Middleware
8
8
 
9
9
  def build_stack
10
10
  Stack.new do |middleware|
11
+ middleware.use Jets::Controller::Middleware::Cors if cors_enabled?
11
12
  middleware.use Rack::Runtime
12
13
  middleware.use Rack::MethodOverride # must come before Middleware::Local for multipart post forms to work
13
14
  middleware.use Jets::Controller::Middleware::Local # mimics AWS Lambda for local server only
@@ -20,6 +21,10 @@ module Jets::Middleware
20
21
  end
21
22
 
22
23
  private
24
+ def cors_enabled?
25
+ Jets.config.cors
26
+ end
27
+
23
28
  # Written as method to easily not include webpacker for case when either
24
29
  # webpacker not installed at all or disabled upon `jets deploy`.
25
30
  def use_webpacker(middleware)
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "1.6.7"
2
+ VERSION = "1.6.8"
3
3
  end
@@ -77,7 +77,6 @@ Jets is unable to build a deployment package that will work on AWS Lambda withou
77
77
 
78
78
  * Use another gem that does not require compilation.
79
79
  * Create your own custom layer with the gem: http://rubyonjets.com/docs/custom-lambda-layers/
80
- * Build the gem yourself and add it to your own custom lambdagems sources. Refer to the Lambda Gems Docs: http://rubyonjets.com/docs/lambdagems
81
80
  <% if agree.yes? -%>
82
81
  * No need to report this to us, as we've already been notified.
83
82
  <% elsif agree.no? -%>
@@ -85,6 +84,7 @@ Jets is unable to build a deployment package that will work on AWS Lambda withou
85
84
  <% end -%>
86
85
 
87
86
  Compiled gems usually take some time to figure out how to build as they each depend on different libraries and packages.
87
+ More info: http://rubyonjets.com/docs/lambdagems/
88
88
 
89
89
  EOL
90
90
  erb = ERB.new(template, nil, '-') # trim mode https://stackoverflow.com/questions/4632879/erb-template-removing-the-trailing-line
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jets
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.7
4
+ version: 1.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-31 00:00:00.000000000 Z
11
+ date: 2019-02-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -608,6 +608,7 @@ files:
608
608
  - lib/jets/controller/cookies/jar.rb
609
609
  - lib/jets/controller/layout.rb
610
610
  - lib/jets/controller/middleware.rb
611
+ - lib/jets/controller/middleware/cors.rb
611
612
  - lib/jets/controller/middleware/local.rb
612
613
  - lib/jets/controller/middleware/local/api_gateway.rb
613
614
  - lib/jets/controller/middleware/local/mimic_aws_call.rb