lamby 4.1.1 → 4.2.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: fbf48cab613254b7bcdcf0b44471934f5aa2dfa6a1b3a4c367f2468bdf974abe
4
- data.tar.gz: ffda31e411518be62e5473ed52c39b53a49fd8902b392be32ea88360cf95a1c7
3
+ metadata.gz: 36672ad378e1e075df3ea97c48960dc48eaf69ef133bd73f52a8ba667689b909
4
+ data.tar.gz: 4617ec443a807af7994cb1c30c3780de4785ae14fd9aae8fa21a07f38284eea1
5
5
  SHA512:
6
- metadata.gz: a7a22a26e51f93a2b732858198d142e9d51fbcdf61db745ffdfda84209b77e88a1525dde8edebd00e1955afddee26dfeabceeb353370db8328c1a774e213ab85
7
- data.tar.gz: 910427c0ac907a06ddc767cb1c4d7d241dc8b6b1e640d6a6c4d57a43653fa569d1da61a496711102df209a5d93f61e3c4272555bfe0e96bc1e9c18d3656d41bf
6
+ metadata.gz: 624dca929cc78ffa686b784a3dbca0817547092e8ecaa3878b973c6e32960a8e980e9544f463f9ecbb00e525fd9dd7943d7013f6f2ef0f7e32db9a58c7f66dab
7
+ data.tar.gz: 5c6e012bf74e0a7b3579d70fed1327f7e331d8a3b49b8efeb1e7a9c8e98e20a927be3463be3f775dbdf361dbc51584bcc1a240b38be0518c9f751e8f7a0119a6
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  See this http://keepachangelog.com link for information on how we want this documented formatted.
4
4
 
5
+ ## v4.2.1
6
+
7
+ ### Added
8
+
9
+ - Local Development Proxy Server with Puma. See #164
10
+
11
+ ## v4.2.0
12
+
13
+ ### Added
14
+
15
+ - Local Development Proxy Server. See #164
16
+
5
17
  ## v4.1.1
6
18
 
7
19
  ### Changed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lamby (4.1.1)
4
+ lamby (4.2.1)
5
5
  rack
6
6
 
7
7
  GEM
@@ -170,6 +170,7 @@ GEM
170
170
  timeout (0.3.2)
171
171
  tzinfo (2.0.6)
172
172
  concurrent-ruby (~> 1.0)
173
+ webrick (1.8.1)
173
174
  websocket-driver (0.7.5)
174
175
  websocket-extensions (>= 0.1.0)
175
176
  websocket-extensions (0.1.5)
@@ -189,6 +190,7 @@ DEPENDENCIES
189
190
  pry
190
191
  rails
191
192
  rake
193
+ webrick
192
194
 
193
195
  BUNDLED WITH
194
196
  2.3.26
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Lamby [![Actions Status](https://github.com/rails-lambda/lamby/workflows/CI/CD/badge.svg)](https://github.com/rails-lambda/lamby/actions) [![Codespaces](https://img.shields.io/badge/Codespaces-✅-black)](https://github.com/features/codespaces)
1
+ # Lamby [![Actions Status](https://github.com/rails-lambda/lamby/workflows/CI/CD/badge.svg)](https://github.com/rails-lambda/lamby/actions)
2
2
 
3
3
  <h2>Simple Rails &amp; AWS Lambda Integration using Rack</h2>
4
4
  <a href="https://lamby.cloud"><img src="https://raw.githubusercontent.com/rails-lambda/lamby/master/images/social2.png" alt="Lamby: Simple Rails & AWS Lambda Integration using Rack." align="right" width="450" style="margin-left:1rem;margin-bottom:1rem;" /></a>
@@ -17,6 +17,8 @@ https://lamby.cloud/docs/anatomy
17
17
 
18
18
  ## Contributing
19
19
 
20
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/rails-lambda/lamby)
21
+
20
22
  This project is built for [GitHub Codespaces](https://github.com/features/codespaces) using the [Development Container](https://containers.dev) specification. Once you have the repo cloned and setup with a dev container using either Codespaces or [VS Code](#using-vs-code), run the following commands. This will install packages and run tests.
21
23
 
22
24
  ```shell
data/Rakefile CHANGED
@@ -5,7 +5,13 @@ require "rake/testtask"
5
5
  Rake::TestTask.new(:test) do |t|
6
6
  t.libs << "test"
7
7
  t.libs << "lib"
8
- t.test_files = FileList["test/**/*_test.rb"]
8
+ t.test_files = begin
9
+ if ENV['TEST_FILE']
10
+ [ENV['TEST_FILE']]
11
+ else
12
+ FileList["test/**/*_test.rb"]
13
+ end
14
+ end
9
15
  t.verbose = false
10
16
  t.warning = false
11
17
  end
data/lamby.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'minitest-focus'
27
27
  spec.add_development_dependency 'mocha'
28
28
  spec.add_development_dependency 'pry'
29
+ spec.add_development_dependency 'webrick'
29
30
  end
@@ -0,0 +1,25 @@
1
+ module Lamby
2
+ # This class is used by the `lamby:proxy_server` Rake task to run a
3
+ # Rack server for local development proxy. Specifically, this class
4
+ # accepts a JSON respresentation of a Lambda context object converted
5
+ # to a Hash as the single arugment.
6
+ #
7
+ class ProxyContext
8
+ def initialize(data)
9
+ @data = data
10
+ end
11
+
12
+ def method_missing(method_name, *args, &block)
13
+ key = method_name.to_s
14
+ if @data.key?(key)
15
+ @data[key]
16
+ else
17
+ super
18
+ end
19
+ end
20
+
21
+ def respond_to_missing?(method_name, include_private = false)
22
+ @data.key?(method_name.to_s) || super
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ module Lamby
2
+ class ProxyServer
3
+
4
+ METHOD_NOT_ALLOWED = <<-HEREDOC.strip
5
+ <h1>Method Not Allowed</h1>
6
+ <p>Please POST to this endpoint with an application/json content type and JSON payload of your Lambda's event and context.<p>
7
+ <p>Example: <code>{ "event": event, "context": context }</code></p>
8
+ HEREDOC
9
+
10
+ def call(env)
11
+ return method_not_allowed unless method_allowed?(env)
12
+ event, context = event_and_context(env)
13
+ lambda_to_rack Lamby.cmd(event: event, context: context)
14
+ end
15
+
16
+ private
17
+
18
+ def event_and_context(env)
19
+ data = env['rack.input'].dup.read
20
+ json = JSON.parse(data)
21
+ [ json['event'], Lamby::ProxyContext.new(json['context']) ]
22
+ end
23
+
24
+ def method_allowed?(env)
25
+ env['REQUEST_METHOD'] == 'POST' && env['CONTENT_TYPE'] == 'application/json'
26
+ end
27
+
28
+ def method_not_allowed
29
+ [405, {"Content-Type" => "text/html"}, [ METHOD_NOT_ALLOWED.dup ]]
30
+ end
31
+
32
+ def lambda_to_rack(response)
33
+ [ 200, {"Content-Type" => "application/json"}, [ response.to_json ] ]
34
+ end
35
+ end
36
+ end
data/lib/lamby/railtie.rb CHANGED
@@ -1,5 +1,9 @@
1
1
  module Lamby
2
2
  class Railtie < ::Rails::Railtie
3
3
  config.lamby = Lamby::Config.config
4
+
5
+ rake_tasks do
6
+ load 'lamby/tasks.rake'
7
+ end
4
8
  end
5
9
  end
@@ -0,0 +1,19 @@
1
+ namespace :lamby do
2
+ task :proxy_server => [:environment] do
3
+ require 'webrick'
4
+ port = ENV['LAMBY_PROXY_PORT'] || 3000
5
+ bind = ENV['LAMBY_PROXY_BIND'] || '0.0.0.0'
6
+ Rack::Handler::WEBrick.run Lamby::ProxyServer.new, Port: port, BindAddress: bind
7
+ end
8
+
9
+ task :proxy_server_puma => [:environment] do
10
+ port = ENV['LAMBY_PROXY_PORT'] || 3000
11
+ host = ENV['LAMBY_PROXY_BIND'] || '0.0.0.0'
12
+ lamby_proxy = Lamby::ProxyServer.new
13
+ maybe_later = MaybeLater::Middleware.new(lamby_proxy)
14
+ server = Puma::Server.new(maybe_later)
15
+ server.add_tcp_listener host, port
16
+ puts "Starting Puma server on #{host}:#{port}..."
17
+ server.run.join
18
+ end
19
+ end
data/lib/lamby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lamby
2
- VERSION = '4.1.1'
2
+ VERSION = '4.2.1'
3
3
  end
data/lib/lamby.rb CHANGED
@@ -35,5 +35,7 @@ module Lamby
35
35
  end
36
36
 
37
37
  autoload :SsmParameterStore, 'lamby/ssm_parameter_store'
38
+ autoload :ProxyContext, 'lamby/proxy_context'
39
+ autoload :ProxyServer, 'lamby/proxy_server'
38
40
 
39
41
  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: 4.1.1
4
+ version: 4.2.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: 2023-04-29 00:00:00.000000000 Z
11
+ date: 2023-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webrick
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Simple Rails & AWS Lambda Integration using Rack and various utilities.
126
140
  email:
127
141
  - ken@metaskills.net
@@ -153,6 +167,8 @@ files:
153
167
  - lib/lamby/debug.rb
154
168
  - lib/lamby/handler.rb
155
169
  - lib/lamby/logger.rb
170
+ - lib/lamby/proxy_context.rb
171
+ - lib/lamby/proxy_server.rb
156
172
  - lib/lamby/rack.rb
157
173
  - lib/lamby/rack_alb.rb
158
174
  - lib/lamby/rack_http.rb
@@ -160,6 +176,7 @@ files:
160
176
  - lib/lamby/railtie.rb
161
177
  - lib/lamby/runner.rb
162
178
  - lib/lamby/ssm_parameter_store.rb
179
+ - lib/lamby/tasks.rake
163
180
  - lib/lamby/version.rb
164
181
  - vendor/.keep
165
182
  homepage: https://github.com/rails-lambda/lamby
@@ -181,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
198
  - !ruby/object:Gem::Version
182
199
  version: '0'
183
200
  requirements: []
184
- rubygems_version: 3.4.12
201
+ rubygems_version: 3.3.26
185
202
  signing_key:
186
203
  specification_version: 4
187
204
  summary: Simple Rails & AWS Lambda Integration using Rack