lamby 2.6.3 → 2.7.0

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: 36a979a80914b8e2b6b15bc65e5a2de4e2ee42021702dc194ded907697f05737
4
- data.tar.gz: e1dab7496ce709072a0a7d41fcd1c3e3bb7c9195b33cef868310650d82a06e26
3
+ metadata.gz: 898837f3efba1d03d1a66891a3c3292c2172aaa24f300775fb537f99e2270ff3
4
+ data.tar.gz: d6cf3bdd2428c566eff0089e153d44bfe3a9385c8d20fe16197e076574adc75d
5
5
  SHA512:
6
- metadata.gz: 2340052e5aa0926d2e096cd0db6fed6f7085243f1caf404b40d570f94cd4bd1b28d608749fe78334c8af97fcf218263f745607aba2c84ac593e0d13da3dd3945
7
- data.tar.gz: 1b5b4dc67b81ee9c0ad905256cd9d43a105a41efc93661920b52d4b184836a39222079fd971a5379b75a2ae31b8cfefe6fa6d2bc04c3d5afe1a3d4252acd5915
6
+ metadata.gz: 4a9c05316b430742811542f56e0655042ab0c67aa0d135a1cce019a9427a2a0480c6f10f7a5afa625cdfca3e5c6f2b7739a7ffc6e2f5b4f8beff1e0b2549fbb8
7
+ data.tar.gz: b7b93733799866aac121eabcc7924659ac14eb1e359dbc7afe8bd7f78e3ef559dff9f62f4c403e9ded172a308884aa6c5145ebc356e49daf3309e6f3896b3357
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@
4
4
 
5
5
  See this http://keepachangelog.com link for information on how we want this documented formatted.
6
6
 
7
+ ## v2.7.0
8
+
9
+ #### Added
10
+
11
+ - Support EventBridge events in handler with default proc to log.
12
+
7
13
  ## v2.6.3
8
14
 
9
15
  #### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lamby (2.6.3)
4
+ lamby (2.7.0)
5
5
  rack
6
6
 
7
7
  GEM
data/lib/lamby.rb CHANGED
@@ -2,6 +2,7 @@ require 'lamby/logger'
2
2
  require 'rack'
3
3
  require 'base64'
4
4
  require 'lamby/version'
5
+ require 'lamby/config'
5
6
  require 'lamby/sam_helpers'
6
7
  require 'lamby/rack'
7
8
  require 'lamby/rack_alb'
@@ -23,6 +24,10 @@ module Lamby
23
24
  Handler.call(app, event, context, options)
24
25
  end
25
26
 
27
+ def config
28
+ Lamby::Config.config
29
+ end
30
+
26
31
  autoload :SsmParameterStore, 'lamby/ssm_parameter_store'
27
32
 
28
33
  end
@@ -0,0 +1,47 @@
1
+ module Lamby
2
+ module Config
3
+
4
+ def configure
5
+ yield(config)
6
+ config
7
+ end
8
+
9
+ def reconfigure
10
+ config.reconfigure { |c| yield(c) if block_given? }
11
+ end
12
+
13
+ def config
14
+ @config ||= Configuration.new
15
+ end
16
+
17
+ extend self
18
+
19
+ end
20
+
21
+ class Configuration
22
+
23
+ def initialize
24
+ initialize_defaults
25
+ end
26
+
27
+ def reconfigure
28
+ instance_variables.each { |var| instance_variable_set var, nil }
29
+ initialize_defaults
30
+ yield(self) if block_given?
31
+ self
32
+ end
33
+
34
+ def initialize_defaults
35
+ @event_bridge_handler = lambda { |event, context| puts(event) }
36
+ end
37
+
38
+ def event_bridge_handler
39
+ @event_bridge_handler
40
+ end
41
+
42
+ def event_bridge_handler=(func)
43
+ @event_bridge_handler = func
44
+ end
45
+
46
+ end
47
+ end
data/lib/lamby/handler.rb CHANGED
@@ -47,7 +47,7 @@ module Lamby
47
47
  def call
48
48
  return self if @called
49
49
  @status, @headers, @body = call_app
50
- set_cookies
50
+ set_cookies if rack?
51
51
  @called = true
52
52
  self
53
53
  end
@@ -78,14 +78,19 @@ module Lamby
78
78
  end
79
79
 
80
80
  def rack_response
81
- rack.response(self)
81
+ rack? ? rack.response(self) : {}
82
82
  end
83
83
 
84
84
  def call_app
85
85
  if Debug.on?(@event)
86
86
  Debug.call @event, @context, rack.env
87
- else
87
+ elsif rack?
88
88
  @app.call rack.env
89
+ elsif event_bridge?
90
+ Lamby.config.event_bridge_handler.call @event, @context
91
+ [200, {}, StringIO.new('')]
92
+ else
93
+ [404, {}, StringIO.new('')]
89
94
  end
90
95
  end
91
96
 
@@ -93,5 +98,14 @@ module Lamby
93
98
  content_encoding_header = hdrs['Content-Encoding'] || ''
94
99
  content_encoding_header.split(', ').any? { |h| ['br', 'gzip'].include?(h) }
95
100
  end
101
+
102
+ def rack?
103
+ @event.key?('httpMethod') || @event.dig('requestContext', 'http')
104
+ end
105
+
106
+ def event_bridge?
107
+ Lamby.config.event_bridge_handler &&
108
+ @event.key?('source') && @event.key?('detail') && @event.key?('detail-type')
109
+ end
96
110
  end
97
111
  end
data/lib/lamby/railtie.rb CHANGED
@@ -1,8 +1,6 @@
1
1
  module Lamby
2
2
  class Railtie < ::Rails::Railtie
3
3
 
4
- config.lamby = ActiveSupport::OrderedOptions.new
5
-
6
4
  rake_tasks do
7
5
  load 'lamby/tasks.rake'
8
6
  load 'lamby/templates.rake'
data/lib/lamby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lamby
2
- VERSION = '2.6.3'
2
+ VERSION = '2.7.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lamby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ken Collins
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-26 00:00:00.000000000 Z
11
+ date: 2021-04-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -151,6 +151,7 @@ files:
151
151
  - lamby.gemspec
152
152
  - lib/lamby.rb
153
153
  - lib/lamby/bootsnap.rb
154
+ - lib/lamby/config.rb
154
155
  - lib/lamby/debug.rb
155
156
  - lib/lamby/handler.rb
156
157
  - lib/lamby/logger.rb