jets 3.0.17 → 3.0.21

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: a03ac914d64e082dd8973795f04e9e4ebd3878b0eb04663e97ef368eecc19eb3
4
- data.tar.gz: 56fe08319ec68002c7990d140dd26e90cdd7ff13b503702bf94dcddb60e12e4a
3
+ metadata.gz: 3528d3aae63a12bcc3b82b0d9666db4b9b621122a8665f2591b655f4283c5368
4
+ data.tar.gz: edfb967cf885286ec053cb933749a1a378fa7d20fbf8952d81be518c63649d64
5
5
  SHA512:
6
- metadata.gz: 9bdcb8d9549179d4adf082abaa0b7353b758b4168019dc43a5208e427186462875bc2e843378461747b756f976d2b62ee175714a7081455ddacb532b4f1b6e2f
7
- data.tar.gz: 5d79ca553952a1413abf1ac4a143f6b905bf1067662c4642e598932ff5ee15b135334d57fbb3530171e63f8322c9e46dc60e6349c1d2e3c06b1416ce386a2821
6
+ metadata.gz: d5f4a9ed780d249b48488dafa67cdd15e82f0d63cc70c42717a667b0ad6d22fd9b9f07cbd6435a3cdb7f2346d8e49b87c3d6265782b60c0233e608a080a2c363
7
+ data.tar.gz: a844a49e320d9b9235da7b2e48bf336801aa06f348e039cc49ee5129b173fd8bd0a5e375ca09071f262f25d8532b329cf0c45024a450b26e4b954a96827619a5
data/CHANGELOG.md CHANGED
@@ -3,6 +3,22 @@
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/).
5
5
 
6
+ ## [3.0.21] - 2021-10-21
7
+ - [#605](https://github.com/boltops-tools/jets/pull/605) use safer 302 redirect as default
8
+
9
+ ## [3.0.20] - 2021-10-20
10
+ - [#603](https://github.com/boltops-tools/jets/pull/603) redirect_to: smarter handling of request xhr
11
+ - [#604](https://github.com/boltops-tools/jets/pull/604) fix redirect_to 301 and keep use default
12
+
13
+ ## [3.0.19] - 2021-10-20
14
+ - [#602](https://github.com/boltops-tools/jets/pull/602) pin zeitwerk to 2.4.x in gemfile
15
+
16
+ ## [3.0.18] - 2021-10-20
17
+ - [#596](https://github.com/boltops-tools/jets/pull/596) Serialize job data correctly
18
+ - [#598](https://github.com/boltops-tools/jets/pull/598) fixing issues when mounting
19
+ - [#599](https://github.com/boltops-tools/jets/pull/599) pin to zeitwerk 2.4.x
20
+ - [#600](https://github.com/boltops-tools/jets/pull/600) method override also on the lambda function side
21
+
6
22
  ## [3.0.17] - 2021-09-15
7
23
  - [#593](https://github.com/boltops-tools/jets/pull/593) Fix deploy for new projects. Added rescue block back into lib/jets/commands/deploy.rb
8
24
 
data/jets.gemspec CHANGED
@@ -61,7 +61,7 @@ Gem::Specification.new do |spec|
61
61
  spec.add_dependency "shotgun"
62
62
  spec.add_dependency "text-table"
63
63
  spec.add_dependency "thor"
64
- spec.add_dependency "zeitwerk"
64
+ spec.add_dependency "zeitwerk", "~> 2.4.0"
65
65
 
66
66
  spec.add_development_dependency "bundler"
67
67
  spec.add_development_dependency "byebug"
@@ -18,6 +18,7 @@ gem "mysql2", "~> 0.5.3"
18
18
  <% unless options[:mode] == 'job' -%>
19
19
  gem "dynomite"
20
20
  <% end -%>
21
+ gem "zeitwerk", "~> 2.4.0"
21
22
 
22
23
  # development and test groups are not bundled as part of the deployment
23
24
  group :development, :test do
@@ -43,7 +43,7 @@ class Jets::Controller
43
43
  # Most of the time, you want process! instead of dispatch!
44
44
  #
45
45
  def process!
46
- adapter = Jets::Controller::Rack::Adapter.new(event, context, meth)
46
+ adapter = Jets::Controller::Rack::Adapter.new(event, context)
47
47
  adapter.rack_vars(
48
48
  'jets.controller' => self,
49
49
  'lambda.context' => context,
@@ -75,6 +75,8 @@ class Jets::Controller
75
75
  # dispatch! is useful for megamode or mounted applications
76
76
  #
77
77
  def dispatch!
78
+ method_override!
79
+
78
80
  t1 = Time.now
79
81
  log_start
80
82
 
@@ -99,12 +101,30 @@ class Jets::Controller
99
101
  triplet # status, headers, body
100
102
  end
101
103
 
104
+ # Override @meth when POST with _method=delete
105
+ # By the time processing reaches dispatch which calls method_override!
106
+ # The Rack::MethodOverride middleware has overriden env['REQUEST_METHOD'] with DELETE
107
+ # and set env['rack.methodoverride.original_method']
108
+ def method_override!
109
+ env = request.env
110
+ if env['rack.methodoverride.original_method'] && env['REQUEST_METHOD'] == 'DELETE'
111
+ @original_meth = @meth
112
+ @meth = "delete"
113
+ end
114
+ end
115
+
116
+ def processing_log
117
+ processing = "Processing #{self.class.name}##{@meth}"
118
+ processing << " (original method #{@original_meth})" if @original_meth
119
+ processing
120
+ end
121
+
102
122
  # Documented interface method, careful not to rename
103
123
  def log_start
104
124
  # JSON.dump makes logging look pretty in CloudWatch logs because it keeps it on 1 line
105
125
  ip = request.ip
106
126
  Jets.logger.info "Started #{@event['httpMethod']} \"#{@event['path']}\" for #{ip} at #{Time.now}"
107
- Jets.logger.info "Processing #{self.class.name}##{@meth}"
127
+ Jets.logger.info processing_log
108
128
  Jets.logger.info " Event: #{event_log}"
109
129
  Jets.logger.info " Parameters: #{JSON.dump(filtered_parameters.to_h)}"
110
130
  end
@@ -5,13 +5,13 @@ module Jets::Controller::Rack
5
5
  extend Memoist
6
6
 
7
7
  # Returns back API Gateway response hash structure
8
- def self.process(event, context, meth)
9
- adapter = new(event, context, meth)
8
+ def self.process(event, context)
9
+ adapter = new(event, context)
10
10
  adapter.process
11
11
  end
12
12
 
13
- def initialize(event, context, meth)
14
- @event, @context, @meth = event, context, meth
13
+ def initialize(event, context)
14
+ @event, @context = event, context
15
15
  end
16
16
 
17
17
  # 1. Convert API Gateway event event to Rack env
@@ -27,12 +27,12 @@ module Jets::Controller::Rack
27
27
  def path_with_base_path
28
28
  resource = @event['resource']
29
29
  pathParameters = @event['pathParameters']
30
-
30
+
31
31
  if(!pathParameters.nil? and !resource.nil?)
32
32
  resource = pathParameters.reduce(resource) {|resource, parameter|
33
33
  key, value = parameter
34
- key = key.eql?("catchall") ? "{#{key}+}" : "{#{key}}"
35
- resource = resource.gsub(key, value)
34
+ resource = resource.gsub("{#{key}+}", value)
35
+ resource = resource.gsub("{#{key}}", value)
36
36
  resource
37
37
  }
38
38
  end
@@ -64,7 +64,9 @@ module Jets::Controller::Rack
64
64
  end
65
65
 
66
66
  def content_type
67
- headers['Content-Type'] || Jets::Controller::DEFAULT_CONTENT_TYPE
67
+ # Rack (local) uses Content-Type and APIGW (remote) uses content-type
68
+ # Rack::MethodOverride relys on content-type to detect content type properly.
69
+ headers['Content-Type'] || headers['content-type'] || Jets::Controller::DEFAULT_CONTENT_TYPE
68
70
  end
69
71
 
70
72
  def content_length
@@ -10,12 +10,22 @@ class Jets::Controller
10
10
  redirect_url = add_stage(url)
11
11
  redirect_url = ensure_protocol(redirect_url)
12
12
 
13
- aws_proxy = Rendering::RackRenderer.new(self,
14
- status: options[:status] || 302,
13
+ default = {
15
14
  headers: { "Location" => redirect_url },
16
- body: "",
17
15
  isBase64Encoded: false,
18
- )
16
+ }
17
+ if request.xhr?
18
+ options[:content_type] ||= "application/json"
19
+ options[:status] ||= 200
20
+ options[:body] ||= JSON.dump(success: true, location: redirect_url)
21
+ else
22
+ options[:status] ||= 302
23
+ options[:body] ||= ""
24
+ end
25
+ Jets.logger.info("redirect_to options #{options}")
26
+ options = default.merge(options)
27
+
28
+ aws_proxy = Rendering::RackRenderer.new(self, options)
19
29
  resp = aws_proxy.render
20
30
  # redirect is a type of rendering
21
31
  @rendered = true
@@ -29,11 +29,7 @@ class <%= controller_class_name %>Controller < ApplicationController
29
29
  @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
30
 
31
31
  if @<%= orm_instance.save %>
32
- if request.xhr?
33
- render json: {success: true, location: url_for(@<%= singular_table_name %>)}
34
- else
35
- redirect_to <%= singular_table_name %>_path(@<%= singular_table_name %>)
36
- end
32
+ redirect_to <%= singular_table_name %>_path(@<%= singular_table_name %>)
37
33
  else
38
34
  render :new
39
35
  end
@@ -42,11 +38,7 @@ class <%= controller_class_name %>Controller < ApplicationController
42
38
  # PUT <%= route_url %>/1
43
39
  def update
44
40
  if @<%= orm_instance.update("#{singular_table_name}_params") %>
45
- if request.xhr?
46
- render json: {success: true, location: url_for(@<%= singular_table_name %>)}
47
- else
48
- redirect_to <%= singular_table_name %>_path(@<%= singular_table_name %>)
49
- end
41
+ redirect_to <%= singular_table_name %>_path(@<%= singular_table_name %>)
50
42
  else
51
43
  render :edit
52
44
  end
@@ -55,11 +47,7 @@ class <%= controller_class_name %>Controller < ApplicationController
55
47
  # DELETE <%= route_url %>/1
56
48
  def delete
57
49
  @<%= orm_instance.destroy %>
58
- if request.xhr?
59
- render json: {success: true, location: <%= table_name %>_path}
60
- else
61
- redirect_to <%= table_name %>_path
62
- end
50
+ redirect_to <%= table_name %>_path
63
51
  end
64
52
 
65
53
  private
data/lib/jets/job/base.rb CHANGED
@@ -26,13 +26,13 @@ module Jets::Job
26
26
  end
27
27
 
28
28
  def perform_now(meth, event={}, context={})
29
- new(event, context, meth).send(meth)
29
+ new(event.try(:to_unsafe_h), context, meth).send(meth)
30
30
  end
31
31
 
32
32
  def perform_later(meth, event={}, context={})
33
33
  if on_lambda?
34
34
  function_name = "#{self.to_s.underscore}-#{meth}"
35
- call = Jets::Commands::Call.new(function_name, JSON.dump(event), invocation_type: "Event")
35
+ call = Jets::Commands::Call.new(function_name, JSON.dump(event.try(:to_unsafe_h)), invocation_type: "Event")
36
36
  call.run
37
37
  else
38
38
  puts "INFO: Not on AWS Lambda. In local mode perform_later executes the job with perform_now instead."
@@ -13,7 +13,7 @@ module Jets::Middleware
13
13
  middleware.use Shotgun::Static
14
14
  middleware.use Rack::Runtime
15
15
  middleware.use Jets::Controller::Middleware::Cors if cors_enabled?
16
- middleware.use Rack::MethodOverride # must come before Middleware::Local for multipart post forms to work
16
+ middleware.use Rack::MethodOverride unless ENV['JETS_RACK_METHOD_OVERRIDE'] == '0' # must come before Middleware::Local for multipart post forms to work
17
17
  middleware.use Jets::Controller::Middleware::Reloader if Jets.config.hot_reload
18
18
  middleware.use Jets::Controller::Middleware::Local # mimics AWS Lambda for local server only
19
19
  middleware.use session_store, session_options
data/lib/jets/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jets
2
- VERSION = "3.0.17"
2
+ VERSION = "3.0.21"
3
3
  end
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: 3.0.17
4
+ version: 3.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tung Nguyen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-15 00:00:00.000000000 Z
11
+ date: 2021-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -490,16 +490,16 @@ dependencies:
490
490
  name: zeitwerk
491
491
  requirement: !ruby/object:Gem::Requirement
492
492
  requirements:
493
- - - ">="
493
+ - - "~>"
494
494
  - !ruby/object:Gem::Version
495
- version: '0'
495
+ version: 2.4.0
496
496
  type: :runtime
497
497
  prerelease: false
498
498
  version_requirements: !ruby/object:Gem::Requirement
499
499
  requirements:
500
- - - ">="
500
+ - - "~>"
501
501
  - !ruby/object:Gem::Version
502
- version: '0'
502
+ version: 2.4.0
503
503
  - !ruby/object:Gem::Dependency
504
504
  name: bundler
505
505
  requirement: !ruby/object:Gem::Requirement