umbra-rb 0.1.3.pre → 0.1.4.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.circleci/config.yml +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +7 -3
- data/lib/umbra/encoder.rb +31 -23
- data/lib/umbra/publisher.rb +2 -0
- data/lib/umbra/request_builder.rb +6 -1
- data/lib/umbra/shadow_requester.rb +3 -1
- data/lib/umbra/version.rb +1 -1
- data/lib/umbra.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 679e800927f9e68d4db11021a503382982a875ffe2603225733e41fcbecea043
|
4
|
+
data.tar.gz: 917c3503760f10e01849b3c57b6d9e61410f2b1d523407b128f96387fdcf212a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 705b476de7c8caf4fc74b20b5bcd4852f6794785ed07f0778aabcd846cbf520aac6060c7e715bc79e59f02468da828f371344393aa0f45ba5dbc208180eba666
|
7
|
+
data.tar.gz: 0c06e66a03e07d85f73f1b66de8b31efa8fcd18c81f267279140e970ada23f0455df5d789719775242699c5f4bd53b544d7aea7e356c7ed66f1cde4c86cf5ac8
|
data/.circleci/config.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
# umbra :waning_crescent_moon:
|
2
|
-
### A shadow requesting tool for rack-based apps
|
3
2
|
|
4
|
-
|
3
|
+
> **umbra** /ˈʌmbrə/
|
4
|
+
>
|
5
|
+
> noun
|
6
|
+
> 1. the fully shaded inner region of a shadow cast by an opaque object, especially the area on the earth or moon experiencing the total phase of an eclipse.
|
7
|
+
> 2. shadow or darkness.
|
8
|
+
> "an impenetrable umbra seemed to fill every inch of the museum"
|
5
9
|
|
6
|
-
|
10
|
+
`umbra` is a rack middleware that allows you to create shadow requests via a redis pub/sub channel.
|
7
11
|
|
8
12
|
# Installation
|
9
13
|
|
data/lib/umbra/encoder.rb
CHANGED
@@ -11,32 +11,37 @@ module Umbra
|
|
11
11
|
@status, @headers, @body = response
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
17
|
-
'
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
'
|
30
|
-
|
31
|
-
|
14
|
+
def to_h
|
15
|
+
@to_h ||=
|
16
|
+
{
|
17
|
+
'request' => {
|
18
|
+
'scheme' => @env.fetch('rack.url_scheme'),
|
19
|
+
'host' => @env['HTTP_HOST'] || @env.fetch('SERVER_NAME'),
|
20
|
+
'uri' => @env.fetch('REQUEST_URI'),
|
21
|
+
'port' => @env.fetch('SERVER_PORT'),
|
22
|
+
'method' => @env.fetch('REQUEST_METHOD'),
|
23
|
+
'query' => @env.fetch('QUERY_STRING'),
|
24
|
+
'script_name' => @env.fetch('SCRIPT_NAME'),
|
25
|
+
'path_info' => @env.fetch('PATH_INFO'),
|
26
|
+
'headers' => request_headers,
|
27
|
+
'body' => request_body
|
28
|
+
},
|
29
|
+
'response' => {
|
30
|
+
'status' => @status,
|
31
|
+
'headers' => @headers,
|
32
|
+
'body' => body_string
|
33
|
+
}
|
32
34
|
}
|
33
|
-
|
35
|
+
end
|
36
|
+
|
37
|
+
def call
|
38
|
+
@call ||= MultiJson.dump(to_h)
|
34
39
|
end
|
35
40
|
|
36
41
|
private
|
37
42
|
|
38
43
|
def request_headers
|
39
|
-
@env.select { |k, _| k.start_with?('HTTP_') }
|
44
|
+
@request_headers ||= @env.select { |k, _| k.start_with?('HTTP_') }
|
40
45
|
end
|
41
46
|
|
42
47
|
def request_body
|
@@ -44,11 +49,14 @@ module Umbra
|
|
44
49
|
end
|
45
50
|
|
46
51
|
def body_string
|
47
|
-
|
52
|
+
@body_string ||=
|
53
|
+
begin
|
54
|
+
str = []
|
48
55
|
|
49
|
-
|
56
|
+
@body.each { |x| str << x.to_s }
|
50
57
|
|
51
|
-
|
58
|
+
str.join('')
|
59
|
+
end
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
data/lib/umbra/publisher.rb
CHANGED
@@ -16,6 +16,7 @@ module Umbra
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
+
# rubocop:disable Metrics/MethodLength
|
19
20
|
def start_once!
|
20
21
|
LOCK.synchronize do
|
21
22
|
return if @started == Process.pid
|
@@ -44,6 +45,7 @@ module Umbra
|
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
48
|
+
# rubocop:enable Metrics/MethodLength
|
47
49
|
end
|
48
50
|
|
49
51
|
STOP = Object.new
|
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
module Umbra
|
4
4
|
class RequestBuilder
|
5
|
+
UMBRA_HEADERS = {
|
6
|
+
Umbra::HEADER_KEY => Umbra::HEADER_VALUE,
|
7
|
+
'HTTP_CACHE_CONTROL' => 'no-cache, no-store, private, max-age=0'
|
8
|
+
}.freeze
|
9
|
+
|
5
10
|
class << self
|
6
11
|
def call(env)
|
7
12
|
Typhoeus::Request.new(
|
@@ -17,7 +22,7 @@ module Umbra
|
|
17
22
|
def headers(env)
|
18
23
|
request(env)
|
19
24
|
.fetch('headers')
|
20
|
-
.merge(
|
25
|
+
.merge(UMBRA_HEADERS)
|
21
26
|
.transform_keys { |key| key.split('_').drop(1).map(&:capitalize).join('-') }
|
22
27
|
end
|
23
28
|
|
@@ -24,6 +24,7 @@ module Umbra
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
# rubocop:disable Metrics/MethodLength
|
27
28
|
def start_worker!
|
28
29
|
@lock.synchronize do
|
29
30
|
return if @started
|
@@ -31,7 +32,7 @@ module Umbra
|
|
31
32
|
@started = true
|
32
33
|
Umbra.logger.info '[umbra] Starting shadowing threads...'
|
33
34
|
|
34
|
-
workers = (
|
35
|
+
workers = (0...@pool).map do |thread_num|
|
35
36
|
Thread.new do
|
36
37
|
Umbra.logger.info "[umbra] shadow thread #{thread_num} waiting"
|
37
38
|
|
@@ -54,5 +55,6 @@ module Umbra
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
58
|
+
# rubocop:enable Metrics/MethodLength
|
57
59
|
end
|
58
60
|
end
|
data/lib/umbra/version.rb
CHANGED
data/lib/umbra.rb
CHANGED
@@ -36,7 +36,7 @@ module Umbra
|
|
36
36
|
return unless @config
|
37
37
|
return unless @config.request_selector.call(env, response)
|
38
38
|
|
39
|
-
env
|
39
|
+
env['umbra.request_body'] = request_body(env)
|
40
40
|
|
41
41
|
@config.publisher.call(env, response)
|
42
42
|
rescue StandardError => e
|
@@ -76,7 +76,7 @@ module Umbra
|
|
76
76
|
redis.ping
|
77
77
|
logger.info '[umbra] redis is alive!'
|
78
78
|
rescue Redis::BaseError => e
|
79
|
-
logger.warn "[umbra]
|
79
|
+
logger.warn "[umbra] error while connecting to redis: #{e.message}"
|
80
80
|
reset!
|
81
81
|
rescue StandardError => e
|
82
82
|
logger.warn "[umbra] redis is misconfigured: #{e.message}"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbra-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4.pre
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|