salestation 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +3 -2
- data/lib/salestation/app/errors.rb +2 -0
- data/lib/salestation/app/input_verification.rb +2 -0
- data/lib/salestation/app/request.rb +2 -0
- data/lib/salestation/app.rb +2 -0
- data/lib/salestation/result_helper.rb +2 -0
- data/lib/salestation/web/active_record_connection_management.rb +2 -0
- data/lib/salestation/web/error_mapper.rb +2 -0
- data/lib/salestation/web/extractors.rb +2 -0
- data/lib/salestation/web/request_logger.rb +33 -54
- data/lib/salestation/web/responses.rb +2 -0
- data/lib/salestation/web/statsd_middleware.rb +2 -0
- data/lib/salestation/web.rb +2 -0
- data/lib/salestation.rb +2 -0
- data/salestation.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dc82a6d835313f9a3dc307f08087dde23916dabccc6805aee7d4e2c8e1f7b9b2
|
4
|
+
data.tar.gz: a0088243adf9f2dae6c119b86c836138627475cc1a11a9b07a7171ff9adcecc2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82e2007245ee0fc1c1f0170f063c658d837af57df50f126bcaae10eb3b245f5c895699010f8013ccbbd3d8333f1ec187beceb6f994061d7385b488f1ac33a890
|
7
|
+
data.tar.gz: 2c4510ad5f22ab4e548197dca991b68bf238d166572a5b63eb0d579139a9c47feb31ad43638670bcf79617bd8fc3c021f9d2c48a86afa3af1b8d3a5d915768a8
|
data/.travis.yml
CHANGED
data/lib/salestation/app.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'securerandom'
|
2
4
|
require 'json'
|
3
5
|
|
@@ -5,15 +7,15 @@ module Salestation
|
|
5
7
|
class Web < Module
|
6
8
|
class RequestLogger
|
7
9
|
|
8
|
-
REMOTE_ADDR = 'REMOTE_ADDR'
|
9
|
-
REQUEST_URI = 'REQUEST_URI'
|
10
|
-
REQUEST_METHOD = 'REQUEST_METHOD'
|
11
|
-
QUERY_STRING
|
12
|
-
CONTENT_TYPE = 'CONTENT_TYPE'
|
13
|
-
HTTP_USER_AGENT = 'HTTP_USER_AGENT'
|
14
|
-
HTTP_ACCEPT = 'HTTP_ACCEPT'
|
15
|
-
SERVER_NAME = 'SERVER_NAME'
|
16
|
-
JSON_CONTENT_TYPE = 'application/json'
|
10
|
+
REMOTE_ADDR = 'REMOTE_ADDR'
|
11
|
+
REQUEST_URI = 'REQUEST_URI'
|
12
|
+
REQUEST_METHOD = 'REQUEST_METHOD'
|
13
|
+
QUERY_STRING = 'QUERY_STRING'
|
14
|
+
CONTENT_TYPE = 'CONTENT_TYPE'
|
15
|
+
HTTP_USER_AGENT = 'HTTP_USER_AGENT'
|
16
|
+
HTTP_ACCEPT = 'HTTP_ACCEPT'
|
17
|
+
SERVER_NAME = 'SERVER_NAME'
|
18
|
+
JSON_CONTENT_TYPE = 'application/json'
|
17
19
|
|
18
20
|
def initialize(app, logger, log_response_body: true)
|
19
21
|
@app = app
|
@@ -22,23 +24,18 @@ module Salestation
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def call(env)
|
25
|
-
request_id = SecureRandom.hex(4)
|
26
|
-
request_logger = Logger.new(@logger, request_id)
|
27
|
-
|
28
|
-
env['request_logger'] = request_logger
|
29
27
|
began_at = Time.now
|
30
28
|
|
31
|
-
request_logger.info('Received request', request_log(env))
|
32
29
|
@app.call(env).tap do |status, headers, body|
|
33
30
|
type = status >= 500 ? :error : :info
|
34
|
-
|
31
|
+
@logger.public_send(type, 'Processed request', response_log(env, status, headers, body, began_at))
|
35
32
|
end
|
36
33
|
end
|
37
34
|
|
38
35
|
private
|
39
36
|
|
40
|
-
def
|
41
|
-
{
|
37
|
+
def response_log(env, status, headers, body, began_at)
|
38
|
+
log = {
|
42
39
|
remote_addr: env[REMOTE_ADDR],
|
43
40
|
method: env[REQUEST_METHOD],
|
44
41
|
path: env[REQUEST_URI],
|
@@ -46,50 +43,32 @@ module Salestation
|
|
46
43
|
content_type: env[CONTENT_TYPE],
|
47
44
|
http_agent: env[HTTP_USER_AGENT],
|
48
45
|
http_accept: env[HTTP_ACCEPT],
|
49
|
-
server_name: env[SERVER_NAME]
|
46
|
+
server_name: env[SERVER_NAME],
|
47
|
+
status: status,
|
48
|
+
duration: Time.now - began_at,
|
49
|
+
headers: headers
|
50
50
|
}
|
51
|
-
end
|
52
|
-
|
53
|
-
def response_log(env, status, headers, body, began_at)
|
54
|
-
response_payload =
|
55
|
-
if status >= 400
|
56
|
-
{ error: parse_body(body, env) }
|
57
|
-
elsif @log_response_body
|
58
|
-
{ body: parse_body(body, env) }
|
59
|
-
else
|
60
|
-
{}
|
61
|
-
end
|
62
51
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
duration: Time.now - began_at,
|
68
|
-
headers: headers
|
69
|
-
}.merge(response_payload)
|
70
|
-
end
|
71
|
-
|
72
|
-
def parse_body(body, env)
|
73
|
-
begin
|
74
|
-
# Rack body is an array
|
75
|
-
return {} if body.empty?
|
76
|
-
JSON.parse(body.join)
|
77
|
-
rescue Exception
|
78
|
-
{error: 'Failed to parse response body'}
|
52
|
+
if status >= 400
|
53
|
+
log[:error] = parse_body(body)
|
54
|
+
elsif @log_response_body
|
55
|
+
log[:body] = parse_body(body)
|
79
56
|
end
|
57
|
+
|
58
|
+
log
|
80
59
|
end
|
81
60
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
@request_id = request_id
|
86
|
-
end
|
61
|
+
def parse_body(body)
|
62
|
+
# Rack body is an array
|
63
|
+
return {} if body.empty?
|
87
64
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
65
|
+
if defined?(Oj)
|
66
|
+
Oj.load(body.join)
|
67
|
+
else
|
68
|
+
JSON.parse(body.join)
|
92
69
|
end
|
70
|
+
rescue Exception
|
71
|
+
{error: 'Failed to parse response body'}
|
93
72
|
end
|
94
73
|
end
|
95
74
|
end
|
data/lib/salestation/web.rb
CHANGED
data/lib/salestation.rb
CHANGED
data/salestation.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salestation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SaleMove TechMovers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.6
|
159
|
+
rubygems_version: 2.7.6
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: ''
|