lamby 2.6.0 → 2.7.1

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: 5d9a016b7bcfeb2c05897068c0f4bae484e1769331da8687e1caf743a7acd55a
4
- data.tar.gz: 0cf5b19f4db83a839aaa64e7f498395803c926cb1088f00779dc02a504211268
3
+ metadata.gz: 59b1550c254f18e60ca584d6387dbb859628593032b669a4c502cc9ab00058c9
4
+ data.tar.gz: 4e2cafe4ec8a56e951ff98100e347d98fc669559673047cc6e40ee316815a45b
5
5
  SHA512:
6
- metadata.gz: b4ec3d030577596053e61a85c9e3d64917e06caab8b7119a6fcf3bba4d4ba787804e8ebdfa0c175b1925b61ef25c9026eca5989c93c61637b2db89fdaca4f74c
7
- data.tar.gz: cc7ea0e3b008d694e144f19abdc373b623c80f1df7c8369dee997e0ca3b1ddea98cfb78ecb9836418653d02670604a2d548f38d371d9ac6f80aaf70b088749ba
6
+ metadata.gz: 406cc8edacadeb1dcb6a5be145699b5f27ca7c7c35ee766fb564cc9f2dc8cb00e26629922d7b4de23a9f04cd6f0410af29cfeb9b82c109f9fb441f919fe8eaae
7
+ data.tar.gz: 4e7fe89bb256588a6cf7effa5c6111286c99de8f20210359203d5c68b249f245fc7629fb520b67ee875adce8ed59994e82bcdcb4be33426385a97078ccbad872
data/CHANGELOG.md CHANGED
@@ -1,73 +1,106 @@
1
1
  <!-- -*- mode: markdown -*- -->
2
+
2
3
  # Keep A Changelog!
3
4
 
4
5
  See this http://keepachangelog.com link for information on how we want this documented formatted.
5
6
 
7
+ ## v2.7.1
8
+
9
+ #### Removed
10
+
11
+ - Bootsnap setup convenience require.
12
+
13
+ ## v2.7.0
14
+
15
+ #### Added
16
+
17
+ - Support EventBridge events in handler with default proc to log.
18
+
19
+ ## v2.6.3
20
+
21
+ #### Added
22
+
23
+ - Bootsnap setup convenience require.
24
+
25
+ ## v2.6.2
26
+
27
+ - Fixed Rack::Deflate usage with an ALB.
28
+
29
+ ## v2.6.1
30
+
31
+ #### Fixed
32
+
33
+ - Support redirects with empty response body.
34
+
35
+ #### Added
36
+
37
+ - Tests for enabling Rack::Deflate middleware by passing RACK_DEFLATE_ENABLED env variable.
38
+
6
39
  ## v2.6.0
7
40
 
8
41
  #### Fixed
9
42
 
10
- * Support multiple Set-Cookie headers for all rest types.
43
+ - Support multiple Set-Cookie headers for all rest types.
11
44
 
12
45
  ## v2.5.3
13
46
 
14
47
  #### Fixed
15
48
 
16
- * Base64 encode response body if the rack response is gzip or brotli compressed.
49
+ - Base64 encode response body if the rack response is gzip or brotli compressed.
17
50
 
18
51
  ## v2.5.2
19
52
 
20
- * SSM file always overwrites. Fixes #65.
53
+ - SSM file always overwrites. Fixes #65.
21
54
 
22
55
  ## v2.5.1
23
56
 
24
57
  #### Fixed
25
58
 
26
- * Quoting in describe-subnets #62 Thanks @atwoodjw
59
+ - Quoting in describe-subnets #62 Thanks @atwoodjw
27
60
 
28
61
  ## v2.5.0
29
62
 
30
63
  #### Changed
31
64
 
32
- * Install files to favor containers.
65
+ - Install files to favor containers.
33
66
 
34
67
  ## v2.2.2
35
68
 
36
69
  #### Changed
37
70
 
38
- * More ActiveSupport removal. Better ENV.to_h.
71
+ - More ActiveSupport removal. Better ENV.to_h.
39
72
 
40
73
  ## v2.2.1
41
74
 
42
75
  #### Changed
43
76
 
44
- * More ActiveSupport removal from SsmParameterStore.
77
+ - More ActiveSupport removal from SsmParameterStore.
45
78
 
46
79
  ## v2.2.0
47
80
 
48
81
  #### Changed
49
82
 
50
- * Remove dependency on `activesupport` for rack-only applications.
51
- * Remove ActiveSupport artifacts:
83
+ - Remove dependency on `activesupport` for rack-only applications.
84
+ - Remove ActiveSupport artifacts:
52
85
  - Replace `strip_heredoc` with `<<~HEREDOC`.
53
86
  - Remove instances of `Object#try`, replace with `&.`.
54
87
  - Use `Rack::Utils.build_nested_query` in place of `Object#to_query`.
55
88
  - Replace `Object#present?` with `to_s.empty?`.
56
89
  - Replace `Array.wrap` with `Array[obj].compact.flatten`.
57
- * Add a check against the `RAILS_ENV` AND `RACK_ENV` environment
90
+ - Add a check against the `RAILS_ENV` AND `RACK_ENV` environment
58
91
  variables prior to enabling debug mode.
59
92
 
60
93
  ## v2.1.0
61
94
 
62
95
  #### Changed
63
96
 
64
- * Only load the railtie if `Rails` is defined.
97
+ - Only load the railtie if `Rails` is defined.
65
98
 
66
99
  ## v2.0.1
67
100
 
68
101
  #### Changed
69
102
 
70
- * Remove Rails runtime dep. Only rack is needed.
103
+ - Remove Rails runtime dep. Only rack is needed.
71
104
 
72
105
  ## v2.0.0
73
106
 
@@ -75,120 +108,107 @@ Support for new API Gateway HTTP APIs!!!
75
108
 
76
109
  #### Changed
77
110
 
78
- * The `Lamby.handler` must have a `:rack` option. One of `:http`, `:rest`, `:alb`.
79
- * Renamed template generators to match options above.
80
- * The `lamby:install` task now defaults to HTTP API.
81
- * Changed the name of `:api` rack option to `:rest`.
82
- * Removed `export` from Dotenv files. Better Docker compatability.
111
+ - The `Lamby.handler` must have a `:rack` option. One of `:http`, `:rest`, `:alb`.
112
+ - Renamed template generators to match options above.
113
+ - The `lamby:install` task now defaults to HTTP API.
114
+ - Changed the name of `:api` rack option to `:rest`.
115
+ - Removed `export` from Dotenv files. Better Docker compatability.
83
116
 
84
117
  #### Added
85
118
 
86
- * New rack handler for HTTP API v1 and v2.
87
- * Lots of backfill tests for, ALBs & REST APIs.
88
-
119
+ - New rack handler for HTTP API v1 and v2.
120
+ - Lots of backfill tests for, ALBs & REST APIs.
89
121
 
90
122
  ## v1.0.3
91
123
 
92
124
  #### Changed
93
125
 
94
- * Change shebangs to `#!/usr/bin/env bash`
95
-
126
+ - Change shebangs to `#!/usr/bin/env bash`
96
127
 
97
128
  ## v1.0.2
98
129
 
99
130
  #### Changed
100
131
 
101
- * Adds an optional 'overwrite' parameter to #to_env.
132
+ - Adds an optional 'overwrite' parameter to #to_env.
102
133
 
103
134
  ## v1.0.1
104
135
 
105
136
  #### Changed
106
137
 
107
- * Links in bin/build templates to point to lamby.custominktech.com site.
108
-
138
+ - Links in bin/build templates to point to lamby.custominktech.com site.
109
139
 
110
140
  ## v1.0.0
111
141
 
112
142
  #### Fixed
113
143
 
114
- * ALB query params & binary responses. Fixes #38.
115
-
144
+ - ALB query params & binary responses. Fixes #38.
116
145
 
117
146
  ## v0.6.0
118
147
 
119
148
  #### Added
120
149
 
121
- * APPLICATION LOAD BALANACER SUPPORT!!! The new default. Use `rack: :api` option to handler for API Gateway support.
150
+ - APPLICATION LOAD BALANACER SUPPORT!!! The new default. Use `rack: :api` option to handler for API Gateway support.
122
151
 
123
152
  #### Changed
124
153
 
125
- * Rake task `lamby:install` now defaults to `application_load_balancer`
126
-
154
+ - Rake task `lamby:install` now defaults to `application_load_balancer`
127
155
 
128
156
  ## v0.5.1
129
157
 
130
158
  #### Fixed
131
159
 
132
- * The .gitignore file template. Fix .aws-sam dir.
133
-
160
+ - The .gitignore file template. Fix .aws-sam dir.
134
161
 
135
162
  ## v0.5.0
136
163
 
137
164
  #### Added
138
165
 
139
- * Template generators for first install. Ex: `./bin/rake -r lamby lamby:install:api_gateway`.
140
- * New `Lamby::SsmParameterStore.get!` helper.
141
-
166
+ - Template generators for first install. Ex: `./bin/rake -r lamby lamby:install:api_gateway`.
167
+ - New `Lamby::SsmParameterStore.get!` helper.
142
168
 
143
169
  ## v0.4.1
144
170
 
145
171
  #### Fixed
146
172
 
147
- * Fix type in v0.4.0 fix below.
148
-
173
+ - Fix type in v0.4.0 fix below.
149
174
 
150
175
  ## v0.4.0
151
176
 
152
177
  #### Fixed
153
178
 
154
- * File uploads in #33 using `CONTENT_TYPE` and `CONTENT_LENGTH`.
155
-
179
+ - File uploads in #33 using `CONTENT_TYPE` and `CONTENT_LENGTH`.
156
180
 
157
181
  ## v0.3.2
158
182
 
159
183
  #### Added
160
184
 
161
- * Pass Request ID for CloudWatch logs. Fixes #30.
162
-
185
+ - Pass Request ID for CloudWatch logs. Fixes #30.
163
186
 
164
187
  ## v0.3.1
165
188
 
166
189
  #### Changed
167
190
 
168
- * Docs and SAM template tweaks.
169
-
191
+ - Docs and SAM template tweaks.
170
192
 
171
193
  ## v0.3.0
172
194
 
173
195
  #### Added
174
196
 
175
- * Secure configs rake task.
176
- * Project bin setup and tests.
197
+ - Secure configs rake task.
198
+ - Project bin setup and tests.
177
199
 
178
200
  #### Changed
179
201
 
180
- * SAM template tweaks.
181
-
202
+ - SAM template tweaks.
182
203
 
183
204
  ## v0.2.0
184
205
 
185
206
  #### Changed
186
207
 
187
- * Simple docs and project re-organization.
188
-
208
+ - Simple docs and project re-organization.
189
209
 
190
210
  ## v0.1.0
191
211
 
192
212
  #### Added
193
213
 
194
- * New gem and placeholder in rubygems.
214
+ - New gem and placeholder in rubygems.
data/Dockerfile CHANGED
@@ -1,10 +1,5 @@
1
1
  FROM lambci/lambda:build-ruby2.7
2
2
 
3
- # Lock down AWS SAM version.
4
- RUN pip install awscli && \
5
- pip uninstall --yes aws-sam-cli && \
6
- pip install aws-sam-cli==0.45.0
7
-
8
3
  # Asset Pipeline
9
4
  RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash - && \
10
5
  yum install -y nodejs
data/Gemfile.lock CHANGED
@@ -1,155 +1,158 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lamby (2.6.0)
4
+ lamby (2.7.1)
5
5
  rack
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- actioncable (6.0.2.2)
11
- actionpack (= 6.0.2.2)
10
+ actioncable (6.1.3.1)
11
+ actionpack (= 6.1.3.1)
12
+ activesupport (= 6.1.3.1)
12
13
  nio4r (~> 2.0)
13
14
  websocket-driver (>= 0.6.1)
14
- actionmailbox (6.0.2.2)
15
- actionpack (= 6.0.2.2)
16
- activejob (= 6.0.2.2)
17
- activerecord (= 6.0.2.2)
18
- activestorage (= 6.0.2.2)
19
- activesupport (= 6.0.2.2)
15
+ actionmailbox (6.1.3.1)
16
+ actionpack (= 6.1.3.1)
17
+ activejob (= 6.1.3.1)
18
+ activerecord (= 6.1.3.1)
19
+ activestorage (= 6.1.3.1)
20
+ activesupport (= 6.1.3.1)
20
21
  mail (>= 2.7.1)
21
- actionmailer (6.0.2.2)
22
- actionpack (= 6.0.2.2)
23
- actionview (= 6.0.2.2)
24
- activejob (= 6.0.2.2)
22
+ actionmailer (6.1.3.1)
23
+ actionpack (= 6.1.3.1)
24
+ actionview (= 6.1.3.1)
25
+ activejob (= 6.1.3.1)
26
+ activesupport (= 6.1.3.1)
25
27
  mail (~> 2.5, >= 2.5.4)
26
28
  rails-dom-testing (~> 2.0)
27
- actionpack (6.0.2.2)
28
- actionview (= 6.0.2.2)
29
- activesupport (= 6.0.2.2)
30
- rack (~> 2.0, >= 2.0.8)
29
+ actionpack (6.1.3.1)
30
+ actionview (= 6.1.3.1)
31
+ activesupport (= 6.1.3.1)
32
+ rack (~> 2.0, >= 2.0.9)
31
33
  rack-test (>= 0.6.3)
32
34
  rails-dom-testing (~> 2.0)
33
35
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
34
- actiontext (6.0.2.2)
35
- actionpack (= 6.0.2.2)
36
- activerecord (= 6.0.2.2)
37
- activestorage (= 6.0.2.2)
38
- activesupport (= 6.0.2.2)
36
+ actiontext (6.1.3.1)
37
+ actionpack (= 6.1.3.1)
38
+ activerecord (= 6.1.3.1)
39
+ activestorage (= 6.1.3.1)
40
+ activesupport (= 6.1.3.1)
39
41
  nokogiri (>= 1.8.5)
40
- actionview (6.0.2.2)
41
- activesupport (= 6.0.2.2)
42
+ actionview (6.1.3.1)
43
+ activesupport (= 6.1.3.1)
42
44
  builder (~> 3.1)
43
45
  erubi (~> 1.4)
44
46
  rails-dom-testing (~> 2.0)
45
47
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
46
- activejob (6.0.2.2)
47
- activesupport (= 6.0.2.2)
48
+ activejob (6.1.3.1)
49
+ activesupport (= 6.1.3.1)
48
50
  globalid (>= 0.3.6)
49
- activemodel (6.0.2.2)
50
- activesupport (= 6.0.2.2)
51
- activerecord (6.0.2.2)
52
- activemodel (= 6.0.2.2)
53
- activesupport (= 6.0.2.2)
54
- activestorage (6.0.2.2)
55
- actionpack (= 6.0.2.2)
56
- activejob (= 6.0.2.2)
57
- activerecord (= 6.0.2.2)
58
- marcel (~> 0.3.1)
59
- activesupport (6.0.2.2)
51
+ activemodel (6.1.3.1)
52
+ activesupport (= 6.1.3.1)
53
+ activerecord (6.1.3.1)
54
+ activemodel (= 6.1.3.1)
55
+ activesupport (= 6.1.3.1)
56
+ activestorage (6.1.3.1)
57
+ actionpack (= 6.1.3.1)
58
+ activejob (= 6.1.3.1)
59
+ activerecord (= 6.1.3.1)
60
+ activesupport (= 6.1.3.1)
61
+ marcel (~> 1.0.0)
62
+ mini_mime (~> 1.0.2)
63
+ activesupport (6.1.3.1)
60
64
  concurrent-ruby (~> 1.0, >= 1.0.2)
61
- i18n (>= 0.7, < 2)
62
- minitest (~> 5.1)
63
- tzinfo (~> 1.1)
64
- zeitwerk (~> 2.2)
65
- aws-eventstream (1.0.3)
66
- aws-partitions (1.287.0)
67
- aws-sdk-core (3.92.0)
68
- aws-eventstream (~> 1.0, >= 1.0.2)
65
+ i18n (>= 1.6, < 2)
66
+ minitest (>= 5.1)
67
+ tzinfo (~> 2.0)
68
+ zeitwerk (~> 2.3)
69
+ aws-eventstream (1.1.1)
70
+ aws-partitions (1.446.0)
71
+ aws-sdk-core (3.114.0)
72
+ aws-eventstream (~> 1, >= 1.0.2)
69
73
  aws-partitions (~> 1, >= 1.239.0)
70
74
  aws-sigv4 (~> 1.1)
71
75
  jmespath (~> 1.0)
72
- aws-sdk-ssm (1.73.0)
73
- aws-sdk-core (~> 3, >= 3.71.0)
76
+ aws-sdk-ssm (1.108.0)
77
+ aws-sdk-core (~> 3, >= 3.112.0)
74
78
  aws-sigv4 (~> 1.1)
75
- aws-sigv4 (1.1.1)
76
- aws-eventstream (~> 1.0, >= 1.0.2)
79
+ aws-sigv4 (1.2.3)
80
+ aws-eventstream (~> 1, >= 1.0.2)
77
81
  builder (3.2.4)
78
- coderay (1.1.2)
79
- concurrent-ruby (1.1.6)
82
+ coderay (1.1.3)
83
+ concurrent-ruby (1.1.8)
80
84
  crass (1.0.6)
81
- erubi (1.9.0)
85
+ erubi (1.10.0)
82
86
  globalid (0.4.2)
83
87
  activesupport (>= 4.2.0)
84
- i18n (1.8.2)
88
+ i18n (1.8.10)
85
89
  concurrent-ruby (~> 1.0)
86
90
  jmespath (1.4.0)
87
- loofah (2.4.0)
91
+ loofah (2.9.1)
88
92
  crass (~> 1.0.2)
89
93
  nokogiri (>= 1.5.9)
90
94
  mail (2.7.1)
91
95
  mini_mime (>= 0.1.1)
92
- marcel (0.3.3)
93
- mimemagic (~> 0.3.2)
96
+ marcel (1.0.1)
94
97
  method_source (1.0.0)
95
- mimemagic (0.3.4)
96
- mini_mime (1.0.2)
97
- mini_portile2 (2.4.0)
98
- minitest (5.14.0)
99
- minitest-focus (1.1.2)
98
+ mini_mime (1.0.3)
99
+ mini_portile2 (2.5.0)
100
+ minitest (5.14.4)
101
+ minitest-focus (1.2.1)
100
102
  minitest (>= 4, < 6)
101
- mocha (1.11.2)
102
- nio4r (2.5.2)
103
- nokogiri (1.10.9)
104
- mini_portile2 (~> 2.4.0)
105
- pry (0.13.0)
103
+ mocha (1.12.0)
104
+ nio4r (2.5.7)
105
+ nokogiri (1.11.3)
106
+ mini_portile2 (~> 2.5.0)
107
+ racc (~> 1.4)
108
+ pry (0.14.1)
106
109
  coderay (~> 1.1)
107
110
  method_source (~> 1.0)
108
- rack (2.2.2)
111
+ racc (1.5.2)
112
+ rack (2.2.3)
109
113
  rack-test (1.1.0)
110
114
  rack (>= 1.0, < 3)
111
- rails (6.0.2.2)
112
- actioncable (= 6.0.2.2)
113
- actionmailbox (= 6.0.2.2)
114
- actionmailer (= 6.0.2.2)
115
- actionpack (= 6.0.2.2)
116
- actiontext (= 6.0.2.2)
117
- actionview (= 6.0.2.2)
118
- activejob (= 6.0.2.2)
119
- activemodel (= 6.0.2.2)
120
- activerecord (= 6.0.2.2)
121
- activestorage (= 6.0.2.2)
122
- activesupport (= 6.0.2.2)
123
- bundler (>= 1.3.0)
124
- railties (= 6.0.2.2)
115
+ rails (6.1.3.1)
116
+ actioncable (= 6.1.3.1)
117
+ actionmailbox (= 6.1.3.1)
118
+ actionmailer (= 6.1.3.1)
119
+ actionpack (= 6.1.3.1)
120
+ actiontext (= 6.1.3.1)
121
+ actionview (= 6.1.3.1)
122
+ activejob (= 6.1.3.1)
123
+ activemodel (= 6.1.3.1)
124
+ activerecord (= 6.1.3.1)
125
+ activestorage (= 6.1.3.1)
126
+ activesupport (= 6.1.3.1)
127
+ bundler (>= 1.15.0)
128
+ railties (= 6.1.3.1)
125
129
  sprockets-rails (>= 2.0.0)
126
130
  rails-dom-testing (2.0.3)
127
131
  activesupport (>= 4.2.0)
128
132
  nokogiri (>= 1.6)
129
133
  rails-html-sanitizer (1.3.0)
130
134
  loofah (~> 2.3)
131
- railties (6.0.2.2)
132
- actionpack (= 6.0.2.2)
133
- activesupport (= 6.0.2.2)
135
+ railties (6.1.3.1)
136
+ actionpack (= 6.1.3.1)
137
+ activesupport (= 6.1.3.1)
134
138
  method_source
135
139
  rake (>= 0.8.7)
136
- thor (>= 0.20.3, < 2.0)
137
- rake (13.0.1)
138
- sprockets (4.0.0)
140
+ thor (~> 1.0)
141
+ rake (13.0.3)
142
+ sprockets (4.0.2)
139
143
  concurrent-ruby (~> 1.0)
140
144
  rack (> 1, < 3)
141
- sprockets-rails (3.2.1)
145
+ sprockets-rails (3.2.2)
142
146
  actionpack (>= 4.0)
143
147
  activesupport (>= 4.0)
144
148
  sprockets (>= 3.0.0)
145
- thor (1.0.1)
146
- thread_safe (0.3.6)
147
- tzinfo (1.2.6)
148
- thread_safe (~> 0.1)
149
- websocket-driver (0.7.1)
149
+ thor (1.1.0)
150
+ tzinfo (2.0.4)
151
+ concurrent-ruby (~> 1.0)
152
+ websocket-driver (0.7.3)
150
153
  websocket-extensions (>= 0.1.0)
151
- websocket-extensions (0.1.4)
152
- zeitwerk (2.3.0)
154
+ websocket-extensions (0.1.5)
155
+ zeitwerk (2.4.2)
153
156
 
154
157
  PLATFORMS
155
158
  ruby
@@ -166,4 +169,4 @@ DEPENDENCIES
166
169
  rake
167
170
 
168
171
  BUNDLED WITH
169
- 2.2.7
172
+ 2.2.15
data/Rakefile CHANGED
@@ -10,4 +10,12 @@ Rake::TestTask.new(:test) do |t|
10
10
  t.warning = false
11
11
  end
12
12
 
13
- task :default => :test
13
+ Rake::TestTask.new(:test_deflate) do |t|
14
+ t.libs << "test"
15
+ t.libs << "lib"
16
+ t.test_files = FileList["test/rack_deflate_test.rb"]
17
+ t.verbose = false
18
+ t.warning = false
19
+ end
20
+
21
+ task :default => [:test, :test_deflate]
data/bin/_test CHANGED
@@ -4,3 +4,4 @@ set -e
4
4
  export RAILS_ENV="test"
5
5
 
6
6
  bundle exec rake test
7
+ RACK_DEFLATE_ENABLED=1 bundle exec rake test_deflate
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
@@ -40,23 +40,23 @@ module Lamby
40
40
 
41
41
  def body
42
42
  @rbody ||= ''.tap do |rbody|
43
- @body.each { |part| rbody << part }
43
+ @body.each { |part| rbody << part if part }
44
44
  end
45
45
  end
46
46
 
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
54
54
 
55
- def base64_encodeable?
56
- @headers && (
57
- @headers['Content-Transfer-Encoding'] == 'binary' ||
58
- content_encoding_compressed? ||
59
- @headers['X-Lamby-Base64'] == '1'
55
+ def base64_encodeable?(hdrs = @headers)
56
+ hdrs && (
57
+ hdrs['Content-Transfer-Encoding'] == 'binary' ||
58
+ content_encoding_compressed?(hdrs) ||
59
+ hdrs['X-Lamby-Base64'] == '1'
60
60
  )
61
61
  end
62
62
 
@@ -78,20 +78,34 @@ 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
 
92
- def content_encoding_compressed?
93
- content_encoding_header = @headers['Content-Encoding'] || ''
97
+ def content_encoding_compressed?(hdrs)
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
@@ -16,7 +16,7 @@ module Lamby
16
16
  multivalue_headers['Set-Cookie'] = handler.set_cookies if handler.set_cookies
17
17
  end
18
18
  status_description = "#{handler.status} #{::Rack::Utils::HTTP_STATUS_CODES[handler.status]}"
19
- base64_encode = hhdrs['Content-Transfer-Encoding'] == 'binary' || hhdrs['X-Lamby-Base64'] == '1'
19
+ base64_encode = handler.base64_encodeable?(hhdrs)
20
20
  body = Base64.strict_encode64(handler.body) if base64_encode
21
21
  { multiValueHeaders: multivalue_headers,
22
22
  statusDescription: status_description,
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.0'
2
+ VERSION = '2.7.1'
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.0
4
+ version: 2.7.1
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-03-04 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -150,6 +150,7 @@ files:
150
150
  - docker-compose.yml
151
151
  - lamby.gemspec
152
152
  - lib/lamby.rb
153
+ - lib/lamby/config.rb
153
154
  - lib/lamby/debug.rb
154
155
  - lib/lamby/handler.rb
155
156
  - lib/lamby/logger.rb