faastruby 0.5.16 → 0.5.17

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: 4c2140df8e1c0f5ab07372b83c80d26e7395b64a02d8e722b50e7acdfaa4a8a8
4
- data.tar.gz: 73e3b0a89b4dea4393a09fc33ffec3fcadbdbfce2069ccc3cdb60d7e96ab064e
3
+ metadata.gz: be62481891e7988206be9866782916c9bbd5213c8870645d86e4d598bc1246e6
4
+ data.tar.gz: 27229e25d96cfd1710c5056babb467613972a18ade05e20ce697c2e265f5b098
5
5
  SHA512:
6
- metadata.gz: b5d46a540b29c8d43f15e939a455a7046caf501756eb3187e85116296b7dcc8ca96c3d8a6acb7f12fad506ad120d530845b5090651fa1896d822bc58fa2543c8
7
- data.tar.gz: aca215d48d18df5ba9609205a90a849ce0dd6ebb247f4210f6885831691b3271dca813baa9e2a67be0e4cef18b5ede29909c5361ba97de3b904313985e9b4f17
6
+ metadata.gz: 78e5ce7c09846351734aed179cc7aa3c387f95c7fdc6a653be1af8d1c4edb0322539e2d0be969bd784901bf914ce438296943510b8113ccf148cd1cfd48470c9
7
+ data.tar.gz: 0a43bb0ede6a7dfe9071e9dfac1d47ca8753f972acc524c6e3184c9d3cd065d6f8b66a7c80702bf8d966aa93e8ff4cdcd2f651e43e9fd4a0049c86f4a08eca17
data/CHANGELOG.md CHANGED
@@ -1,6 +1,12 @@
1
1
  # Changelog
2
2
 
3
- ## 0.5.16 - unreleased
3
+ ## 0.5.17 - Mar 19 2019
4
+ - Refactored headers parsing
5
+ - Change Oj load behaviour to use hash with symbol keys when loading rpc_args
6
+ - Bump `faastruby-rpc` version
7
+ - Added `favicon.ico` to the public template to stop annoying catch-all invocations on log
8
+
9
+ ## 0.5.16 - Mar 18 2019
4
10
  - Remove unused arguments from update workspace `run` method.
5
11
  - Update Help
6
12
  - Change the argument that measures the execution time on `run` to `--measure`
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- faastruby (0.5.16)
4
+ faastruby (0.5.17)
5
5
  colorize (~> 0.8)
6
- faastruby-rpc (~> 0.2.5)
6
+ faastruby-rpc (~> 0.2.6)
7
7
  listen (~> 3.1)
8
8
  oj (~> 3.6)
9
9
  puma (~> 3.12)
@@ -30,7 +30,7 @@ GEM
30
30
  unf (>= 0.0.5, < 1.0.0)
31
31
  equatable (0.5.0)
32
32
  erubis (2.7.0)
33
- faastruby-rpc (0.2.5)
33
+ faastruby-rpc (0.2.6)
34
34
  oj (~> 3.6)
35
35
  ffi (1.10.0)
36
36
  hashdiff (0.3.7)
data/faastruby.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.add_runtime_dependency 'sinatra', '~> 2.0'
21
21
  spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0'
22
22
  spec.add_runtime_dependency 'puma', '~> 3.12'
23
- spec.add_runtime_dependency 'faastruby-rpc', '~> 0.2.5'
23
+ spec.add_runtime_dependency 'faastruby-rpc', '~> 0.2.6'
24
24
  spec.add_runtime_dependency 'tmuxinator', '~> 0.15'
25
25
  spec.add_runtime_dependency 'rouge', '~> 3.3'
26
26
  spec.add_runtime_dependency 'listen', '~> 3.1'
@@ -6,6 +6,7 @@ require 'sinatra/multi_route'
6
6
  require 'securerandom'
7
7
  require 'rouge'
8
8
  require 'colorize'
9
+
9
10
  module FaaStRuby
10
11
  class Server < Sinatra::Base
11
12
  include FaaStRuby::Logger::Requests
@@ -23,21 +24,22 @@ module FaaStRuby
23
24
  request_uuid = SecureRandom.uuid
24
25
  splat = params['splat'][0]
25
26
  function_name = resolve_function_name(splat)
26
- headers = parse_headers(env)
27
- if headers.has_key?("Faastruby-Rpc")
27
+ request_headers = parse_headers(env)
28
+ if request_headers.has_key?('Faastruby-Rpc')
28
29
  body = nil
29
- rpc_args = parse_body(request.body.read, headers['Content-Type'], request.request_method) || []
30
+ rpc_args = parse_body(request.body.read, request_headers['Content-Type'], request.request_method, true) || []
31
+
30
32
  else
31
- body = parse_body(request.body.read, headers['Content-Type'], request.request_method)
33
+ body = parse_body(request.body.read, request_headers['Content-Type'], request.request_method)
32
34
  rpc_args = []
33
35
  end
34
- headers['X-Request-Id'] = request_uuid
35
- headers['Request-Method'] = request.request_method
36
- original_request_id = headers['X-Original-Request-Id']
36
+ request_headers['X-Request-Id'] = request_uuid
37
+ request_headers['Request-Method'] = request.request_method
38
+ original_request_id = request_headers['X-Original-Request-Id']
37
39
  query_params = parse_query(request.query_string)
38
40
  context = Oj.dump(FaaStRuby::ProjectConfig.secrets_for_function(function_name))
39
- event = FaaStRuby::Event.new(body: body, query_params: query_params, headers: headers, context: context)
40
- log_request_message(function_name, request, request_uuid, query_params, body, context)
41
+ event = FaaStRuby::Event.new(body: body, query_params: query_params, headers: request_headers, context: context)
42
+ log_request_message(function_name, request, request_uuid, query_params, body || rpc_args, context, request_headers)
41
43
  time, response = FaaStRuby::Runner.new(function_name).call(event, rpc_args)
42
44
  status response.status
43
45
  headers set_response_headers(response, request_uuid, original_request_id, time)
@@ -46,8 +48,8 @@ module FaaStRuby
46
48
  body response_body
47
49
  end
48
50
 
49
- def log_request_message(function_name, request, request_uuid, query_params, body, context)
50
- puts "[#{function_name}] <- [REQUEST: #{request.request_method} \"#{request.fullpath}\"] request_id=\"#{request_uuid}\" body=\"#{body}\" query_params=#{query_params} headers=#{headers}"
51
+ def log_request_message(function_name, request, request_uuid, query_params, body, context, request_headers)
52
+ puts "[#{function_name}] <- [REQUEST: #{request.request_method} \"#{request.fullpath}\"] request_id=\"#{request_uuid}\" body=\"#{body}\" query_params=#{query_params} headers=#{request_headers}"
51
53
  end
52
54
 
53
55
  def log_response_message(function_name, time, request_uuid, response, print_body)
@@ -80,10 +82,14 @@ module FaaStRuby
80
82
  File.file?("#{FaaStRuby::ProjectConfig.functions_dir}/#{name}/faastruby.yml")
81
83
  end
82
84
 
83
- def parse_body(body, content_type, method)
85
+ def parse_body(body, content_type, method, rpc=false)
84
86
  return nil if method == 'GET'
85
87
  return {} if body.nil? && method != 'GET'
86
- return Oj.load(body) if content_type == 'application/json'
88
+ if rpc
89
+ return Oj.load(body, symbol_keys: true) if content_type == 'application/json'
90
+ else
91
+ return Oj.load(body) if content_type == 'application/json'
92
+ end
87
93
  return body
88
94
  end
89
95
 
@@ -97,11 +103,16 @@ module FaaStRuby
97
103
  end
98
104
 
99
105
  def parse_headers(env)
100
- Hash[*env.select {|k,v| k.start_with? 'HTTP_'}
101
- .collect {|k,v| [k.sub(/^HTTP_/, ''), v]}
102
- .collect {|k,v| [k.split('_').collect{|a|k == 'DNT' ? k : k.capitalize}.join('-'), v]}
103
- .sort
104
- .flatten]
106
+ result = {}
107
+ env.select{|e| e.match(/^HTTP_/)}.each do |k, v|
108
+ newkey = k.sub(/^HTTP_/, '').split('_').map{|x| x.capitalize}.join('-')
109
+ result[newkey] = v
110
+ end
111
+ result['Content-Type'] = env['CONTENT_TYPE']
112
+ result['Request-Method'] = env['REQUEST_METHOD']
113
+ result['Content-Length'] = env['CONTENT_LENGTH']
114
+ result['Remote-Addr'] = env['REMOTE_ADDR']
115
+ result
105
116
  end
106
117
  end
107
118
  end
@@ -4,6 +4,7 @@ module FaaStRuby
4
4
  module Requests
5
5
 
6
6
  def puts(msg)
7
+ msg = msg.inspect unless msg.is_a?(String)
7
8
  msg = Rouge.highlight(msg, 'ruby', Rouge::Formatters::Terminal256.new(Rouge::Themes::Monokai.new))
8
9
  STDOUT_MUTEX.synchronize do
9
10
  STDOUT.puts "#{Time.now} | #{msg}"
@@ -1,3 +1,3 @@
1
1
  module FaaStRuby
2
- VERSION = '0.5.16'
2
+ VERSION = '0.5.17'
3
3
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faastruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.16
4
+ version: 0.5.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paulo Arruda
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-18 00:00:00.000000000 Z
11
+ date: 2019-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: 0.2.5
145
+ version: 0.2.6
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: 0.2.5
152
+ version: 0.2.6
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: tmuxinator
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -355,6 +355,7 @@ files:
355
355
  - templates/public-web/assets/images/logo-positive.png
356
356
  - templates/public-web/assets/javascripts/main.js
357
357
  - templates/public-web/assets/stylesheets/main.css
358
+ - templates/public-web/favicon.ico
358
359
  - templates/ruby/api-404/handler.rb
359
360
  - templates/ruby/api-root/handler.rb
360
361
  - templates/ruby/example-blank/handler.rb