umbra-rb 0.3.0.pre → 0.4.0
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/.bundle/config +2 -0
- data/.standard.yml +2 -0
- data/Gemfile +1 -2
- data/Rakefile +3 -4
- data/bin/console +10 -0
- data/config.ru +7 -4
- data/lib/umbra/config.rb +1 -1
- data/lib/umbra/encoder.rb +26 -40
- data/lib/umbra/middleware.rb +2 -4
- data/lib/umbra/pb/umbra_pb.rb +17 -0
- data/lib/umbra/publisher.rb +7 -5
- data/lib/umbra/version.rb +1 -1
- data/lib/umbra.rb +26 -28
- data/umbra-rb.gemspec +32 -30
- metadata +50 -68
- data/.circleci/config.yml +0 -59
- data/.gitignore +0 -12
- data/.rubocop.yml +0 -9
- data/Gemfile.lock +0 -93
- data/LICENSE.txt +0 -21
- data/README.md +0 -100
- data/lib/umbra/request_builder.rb +0 -58
- data/lib/umbra/shadow_requester.rb +0 -34
- data/lib/umbra/subscriber.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4afc0097d45fdf86d794b0bbde9911e18e3264d12a1d819acf42d601ced6996a
|
4
|
+
data.tar.gz: 295ab669b07ae259877acd956be50bb21139350767ac96c699a12ac18da240ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7eb855724c5b1500f5842a72e718f7829595f65a3210b9e49a9d4f3855a43ab1ecd7fc14388ba21350250c90ec61604a84eae4ab6daee100ecfbce7c583fc614
|
7
|
+
data.tar.gz: 6d0cd76798e774df8a2b67989c92af477bdcd0332fc91c2d38b3feb1d58c831c5efcca7245417948cbbdea526a4fac6943dc5901f3b69478f496edf670f7c8f6
|
data/.bundle/config
ADDED
data/.standard.yml
ADDED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
ADDED
data/config.ru
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require "rack"
|
5
|
+
require "rackup/lobster"
|
6
|
+
require "umbra"
|
4
7
|
|
5
8
|
Umbra.configure
|
6
9
|
|
7
10
|
use Umbra::Middleware
|
8
|
-
run
|
11
|
+
run Rackup::Lobster.new
|
data/lib/umbra/config.rb
CHANGED
data/lib/umbra/encoder.rb
CHANGED
@@ -2,61 +2,47 @@
|
|
2
2
|
|
3
3
|
module Umbra
|
4
4
|
class Encoder
|
5
|
-
def self.call(env
|
6
|
-
new(env
|
5
|
+
def self.call(env)
|
6
|
+
new(env).call
|
7
7
|
end
|
8
8
|
|
9
|
-
def initialize(env
|
9
|
+
def initialize(env)
|
10
10
|
@env = env
|
11
|
-
@status, @headers, @body = response
|
12
|
-
end
|
13
|
-
|
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
|
-
}
|
34
|
-
}
|
35
11
|
end
|
36
12
|
|
37
13
|
def call
|
38
|
-
@call ||=
|
14
|
+
@call ||= Pb::Message.new(
|
15
|
+
method: rack_request.request_method,
|
16
|
+
url: rack_request.url,
|
17
|
+
body: request_body,
|
18
|
+
headers: request_headers
|
19
|
+
).to_proto
|
20
|
+
end
|
21
|
+
|
22
|
+
def ignored_headers
|
23
|
+
[]
|
39
24
|
end
|
40
25
|
|
41
26
|
private
|
42
27
|
|
43
|
-
def
|
44
|
-
@
|
28
|
+
def rack_request
|
29
|
+
@rack_request ||= Rack::Request.new(@env)
|
45
30
|
end
|
46
31
|
|
47
|
-
def
|
48
|
-
@
|
32
|
+
def request_headers
|
33
|
+
@request_headers ||=
|
34
|
+
@env
|
35
|
+
.select { |k, _| k.start_with?("HTTP_") && !ignored_headers.include?(k) }
|
36
|
+
.merge(HEADER_KEY => HEADER_VALUE)
|
37
|
+
.transform_keys { |k| to_http_header(k) }
|
49
38
|
end
|
50
39
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
str = []
|
55
|
-
|
56
|
-
@body.each { |x| str << x.to_s }
|
40
|
+
def to_http_header(rack_header)
|
41
|
+
rack_header.delete_prefix("HTTP_").downcase.split("_").join("-")
|
42
|
+
end
|
57
43
|
|
58
|
-
|
59
|
-
|
44
|
+
def request_body
|
45
|
+
@env.fetch("umbra.request_body")
|
60
46
|
end
|
61
47
|
end
|
62
48
|
end
|
data/lib/umbra/middleware.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
3
|
+
# source: umbra.proto
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
|
8
|
+
descriptor_data = "\n\x0bumbra.proto\x12\x08umbra.pb\"\x95\x01\n\x07Message\x12\x0e\n\x06method\x18\x01 \x01(\t\x12\x0b\n\x03url\x18\x02 \x01(\t\x12/\n\x07headers\x18\x03 \x03(\x0b\x32\x1e.umbra.pb.Message.HeadersEntry\x12\x0c\n\x04\x62ody\x18\x04 \x01(\x0c\x1a.\n\x0cHeadersEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\x42\x1cZ\x1agithub.com/carwow/umbra/pbb\x06proto3"
|
9
|
+
|
10
|
+
pool = Google::Protobuf::DescriptorPool.generated_pool
|
11
|
+
pool.add_serialized_file(descriptor_data)
|
12
|
+
|
13
|
+
module Umbra
|
14
|
+
module Pb
|
15
|
+
Message = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("umbra.pb.Message").msgclass
|
16
|
+
end
|
17
|
+
end
|
data/lib/umbra/publisher.rb
CHANGED
@@ -4,6 +4,8 @@ module Umbra
|
|
4
4
|
DEFAULT_MIN_THREADS = 1
|
5
5
|
DEFAULT_MAX_THREADS = 1
|
6
6
|
|
7
|
+
attr_reader :pool
|
8
|
+
|
7
9
|
def initialize(**options)
|
8
10
|
@pool = Concurrent::CachedThreadPool.new(
|
9
11
|
min_threads: options.fetch(:min_threads, DEFAULT_MIN_THREADS),
|
@@ -13,18 +15,18 @@ module Umbra
|
|
13
15
|
)
|
14
16
|
end
|
15
17
|
|
16
|
-
def call(env,
|
17
|
-
@pool << proc { call!(env,
|
18
|
+
def call(env, encoder: Umbra.encoder, redis: Umbra.redis)
|
19
|
+
@pool << proc { call!(env, encoder: encoder, redis: redis) }
|
18
20
|
|
19
21
|
true
|
20
22
|
rescue Concurrent::RejectedExecutionError
|
21
|
-
Umbra.logger.warn
|
23
|
+
Umbra.logger.warn "[umbra] Queue at max - dropping items"
|
22
24
|
|
23
25
|
false
|
24
26
|
end
|
25
27
|
|
26
|
-
def call!(env,
|
27
|
-
redis.publish(Umbra::CHANNEL, encoder.call(env
|
28
|
+
def call!(env, encoder: Umbra.encoder, redis: Umbra.redis)
|
29
|
+
redis.publish(Umbra::CHANNEL, encoder.call(env))
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
data/lib/umbra/version.rb
CHANGED
data/lib/umbra.rb
CHANGED
@@ -1,27 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "zeitwerk"
|
4
|
+
require "rack"
|
5
|
+
require "redis"
|
6
|
+
require "concurrent"
|
7
|
+
require "logger"
|
8
|
+
|
9
|
+
Zeitwerk::Loader.for_gem.setup
|
7
10
|
|
8
11
|
module Umbra
|
9
|
-
autoload :
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
autoload :RequestBuilder, 'umbra/request_builder'
|
15
|
-
autoload :ShadowRequester, 'umbra/shadow_requester'
|
16
|
-
autoload :SynchronousPublisher, 'umbra/synchronous_publisher'
|
17
|
-
autoload :Version, 'umbra/version'
|
18
|
-
|
19
|
-
CHANNEL = 'umbra_channel'
|
20
|
-
HEADER_KEY = 'HTTP_X_UMBRA_REQUEST'
|
21
|
-
HEADER_VALUE = 'true'
|
12
|
+
autoload :Pb, "umbra/pb/umbra_pb"
|
13
|
+
|
14
|
+
CHANNEL = "umbra_channel"
|
15
|
+
HEADER_KEY = "HTTP_X_UMBRA_REQUEST"
|
16
|
+
HEADER_VALUE = "true"
|
22
17
|
|
23
18
|
RequestSelector = proc { true }
|
24
|
-
SuppressErrorHandler = proc {
|
19
|
+
SuppressErrorHandler = proc {}
|
25
20
|
|
26
21
|
class << self
|
27
22
|
attr_reader :config
|
@@ -32,16 +27,17 @@ module Umbra
|
|
32
27
|
test_redis_connection!
|
33
28
|
end
|
34
29
|
|
35
|
-
def publish(env
|
30
|
+
def publish(env)
|
36
31
|
return if umbra_request?(env)
|
32
|
+
|
37
33
|
return unless @config
|
38
|
-
return unless @config.request_selector.call(env
|
34
|
+
return unless @config.request_selector.call(env)
|
39
35
|
|
40
|
-
env[
|
36
|
+
env["umbra.request_body"] = request_body(env)
|
41
37
|
|
42
|
-
@config.publisher.call(env
|
43
|
-
rescue
|
44
|
-
@config.error_handler.call(e, env
|
38
|
+
@config.publisher.call(env)
|
39
|
+
rescue => e
|
40
|
+
@config.error_handler.call(e, env)
|
45
41
|
end
|
46
42
|
|
47
43
|
def redis
|
@@ -64,7 +60,9 @@ module Umbra
|
|
64
60
|
private
|
65
61
|
|
66
62
|
def request_body(env)
|
67
|
-
|
63
|
+
return nil unless env.key? "rack.input"
|
64
|
+
|
65
|
+
io = env.fetch("rack.input")
|
68
66
|
io.rewind
|
69
67
|
body = io.read
|
70
68
|
io.rewind
|
@@ -73,13 +71,13 @@ module Umbra
|
|
73
71
|
end
|
74
72
|
|
75
73
|
def test_redis_connection!
|
76
|
-
logger.info
|
74
|
+
logger.info "[umbra] Testing redis connection..."
|
77
75
|
redis.ping
|
78
|
-
logger.info
|
76
|
+
logger.info "[umbra] redis is alive!"
|
79
77
|
rescue Redis::BaseError => e
|
80
78
|
logger.warn "[umbra] error while connecting to redis: #{e.message}"
|
81
79
|
reset!
|
82
|
-
rescue
|
80
|
+
rescue => e
|
83
81
|
logger.warn "[umbra] redis is misconfigured: #{e.message}"
|
84
82
|
reset!
|
85
83
|
end
|
data/umbra-rb.gemspec
CHANGED
@@ -1,41 +1,43 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
lib = File.expand_path(
|
3
|
+
lib = File.expand_path("lib", __dir__)
|
4
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
-
|
5
|
+
|
6
|
+
require "umbra/version"
|
6
7
|
|
7
8
|
Gem::Specification.new do |spec|
|
8
|
-
spec.name
|
9
|
-
spec.version
|
10
|
-
spec.authors
|
11
|
-
spec.email
|
9
|
+
spec.name = "umbra-rb"
|
10
|
+
spec.version = Umbra::VERSION
|
11
|
+
spec.authors = ["carwow Developers"]
|
12
|
+
spec.email = ["developers@carwow.co.uk"]
|
13
|
+
|
14
|
+
spec.summary = "A shadow requesting library for rack based applications"
|
15
|
+
spec.homepage = "https://github.com/carwow/umbra"
|
16
|
+
spec.license = "MIT"
|
12
17
|
|
13
|
-
spec.
|
14
|
-
spec.
|
15
|
-
spec.
|
18
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["github_repo"] = spec.homepage
|
21
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
16
22
|
|
17
|
-
spec.
|
18
|
-
spec.metadata['homepage_uri'] = spec.homepage
|
19
|
-
spec.metadata['source_code_uri'] = spec.homepage
|
23
|
+
spec.require_paths = ["lib"]
|
20
24
|
|
21
|
-
# Specify which files should be added to the gem when it is released.
|
22
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
-
`git ls-files -z
|
26
|
+
`git ls-files -z`
|
27
|
+
.split("\x0")
|
28
|
+
.reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
29
|
end
|
26
|
-
|
27
|
-
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
|
36
|
-
spec.add_dependency
|
37
|
-
spec.add_dependency
|
38
|
-
spec.add_dependency
|
39
|
-
spec.add_dependency 'redis', '~> 4.1'
|
40
|
-
spec.add_dependency 'typhoeus', '~> 1.3'
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~>2.6"
|
32
|
+
spec.add_development_dependency "rack-test", "~>2.2"
|
33
|
+
spec.add_development_dependency "rake", "~>13.2"
|
34
|
+
spec.add_development_dependency "rspec", "~>3"
|
35
|
+
spec.add_development_dependency "standard", "~>1.49"
|
36
|
+
|
37
|
+
spec.add_dependency "concurrent-ruby", "~>1.3"
|
38
|
+
spec.add_dependency "google-protobuf", "~>4.30"
|
39
|
+
spec.add_dependency "rack", "~>3.1"
|
40
|
+
spec.add_dependency "rackup", "~>2.2"
|
41
|
+
spec.add_dependency "redis", "~>5.4"
|
42
|
+
spec.add_dependency "zeitwerk", "~>2.7"
|
41
43
|
end
|
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.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- carwow Developers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,193 +16,174 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.6'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rack-test
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: pry
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
31
|
+
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
33
|
+
version: '2.2'
|
48
34
|
type: :development
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
|
-
- - "
|
38
|
+
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
40
|
+
version: '2.2'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
42
|
+
name: rake
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
58
44
|
requirements:
|
59
|
-
- - "
|
45
|
+
- - "~>"
|
60
46
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
47
|
+
version: '13.2'
|
62
48
|
type: :development
|
63
49
|
prerelease: false
|
64
50
|
version_requirements: !ruby/object:Gem::Requirement
|
65
51
|
requirements:
|
66
|
-
- - "
|
52
|
+
- - "~>"
|
67
53
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
54
|
+
version: '13.2'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
56
|
+
name: rspec
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
72
58
|
requirements:
|
73
59
|
- - "~>"
|
74
60
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
61
|
+
version: '3'
|
76
62
|
type: :development
|
77
63
|
prerelease: false
|
78
64
|
version_requirements: !ruby/object:Gem::Requirement
|
79
65
|
requirements:
|
80
66
|
- - "~>"
|
81
67
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
68
|
+
version: '3'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
70
|
+
name: standard
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
86
72
|
requirements:
|
87
73
|
- - "~>"
|
88
74
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
75
|
+
version: '1.49'
|
90
76
|
type: :development
|
91
77
|
prerelease: false
|
92
78
|
version_requirements: !ruby/object:Gem::Requirement
|
93
79
|
requirements:
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
82
|
+
version: '1.49'
|
97
83
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
84
|
+
name: concurrent-ruby
|
99
85
|
requirement: !ruby/object:Gem::Requirement
|
100
86
|
requirements:
|
101
87
|
- - "~>"
|
102
88
|
- !ruby/object:Gem::Version
|
103
|
-
version: '3'
|
104
|
-
type: :
|
89
|
+
version: '1.3'
|
90
|
+
type: :runtime
|
105
91
|
prerelease: false
|
106
92
|
version_requirements: !ruby/object:Gem::Requirement
|
107
93
|
requirements:
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
|
-
version: '3'
|
96
|
+
version: '1.3'
|
111
97
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
98
|
+
name: google-protobuf
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
114
100
|
requirements:
|
115
101
|
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
103
|
+
version: '4.30'
|
118
104
|
type: :runtime
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
107
|
requirements:
|
122
108
|
- - "~>"
|
123
109
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
110
|
+
version: '4.30'
|
125
111
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
112
|
+
name: rack
|
127
113
|
requirement: !ruby/object:Gem::Requirement
|
128
114
|
requirements:
|
129
115
|
- - "~>"
|
130
116
|
- !ruby/object:Gem::Version
|
131
|
-
version: '1
|
117
|
+
version: '3.1'
|
132
118
|
type: :runtime
|
133
119
|
prerelease: false
|
134
120
|
version_requirements: !ruby/object:Gem::Requirement
|
135
121
|
requirements:
|
136
122
|
- - "~>"
|
137
123
|
- !ruby/object:Gem::Version
|
138
|
-
version: '1
|
124
|
+
version: '3.1'
|
139
125
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
126
|
+
name: rackup
|
141
127
|
requirement: !ruby/object:Gem::Requirement
|
142
128
|
requirements:
|
143
129
|
- - "~>"
|
144
130
|
- !ruby/object:Gem::Version
|
145
|
-
version: '
|
131
|
+
version: '2.2'
|
146
132
|
type: :runtime
|
147
133
|
prerelease: false
|
148
134
|
version_requirements: !ruby/object:Gem::Requirement
|
149
135
|
requirements:
|
150
136
|
- - "~>"
|
151
137
|
- !ruby/object:Gem::Version
|
152
|
-
version: '
|
138
|
+
version: '2.2'
|
153
139
|
- !ruby/object:Gem::Dependency
|
154
140
|
name: redis
|
155
141
|
requirement: !ruby/object:Gem::Requirement
|
156
142
|
requirements:
|
157
143
|
- - "~>"
|
158
144
|
- !ruby/object:Gem::Version
|
159
|
-
version: '4
|
145
|
+
version: '5.4'
|
160
146
|
type: :runtime
|
161
147
|
prerelease: false
|
162
148
|
version_requirements: !ruby/object:Gem::Requirement
|
163
149
|
requirements:
|
164
150
|
- - "~>"
|
165
151
|
- !ruby/object:Gem::Version
|
166
|
-
version: '4
|
152
|
+
version: '5.4'
|
167
153
|
- !ruby/object:Gem::Dependency
|
168
|
-
name:
|
154
|
+
name: zeitwerk
|
169
155
|
requirement: !ruby/object:Gem::Requirement
|
170
156
|
requirements:
|
171
157
|
- - "~>"
|
172
158
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
159
|
+
version: '2.7'
|
174
160
|
type: :runtime
|
175
161
|
prerelease: false
|
176
162
|
version_requirements: !ruby/object:Gem::Requirement
|
177
163
|
requirements:
|
178
164
|
- - "~>"
|
179
165
|
- !ruby/object:Gem::Version
|
180
|
-
version: '
|
181
|
-
description:
|
166
|
+
version: '2.7'
|
167
|
+
description:
|
182
168
|
email:
|
183
169
|
- developers@carwow.co.uk
|
184
170
|
executables: []
|
185
171
|
extensions: []
|
186
172
|
extra_rdoc_files: []
|
187
173
|
files:
|
188
|
-
- ".
|
189
|
-
- ".gitignore"
|
174
|
+
- ".bundle/config"
|
190
175
|
- ".rspec"
|
191
|
-
- ".
|
176
|
+
- ".standard.yml"
|
192
177
|
- Gemfile
|
193
|
-
- Gemfile.lock
|
194
|
-
- LICENSE.txt
|
195
|
-
- README.md
|
196
178
|
- Rakefile
|
179
|
+
- bin/console
|
197
180
|
- config.ru
|
198
181
|
- lib/umbra.rb
|
199
182
|
- lib/umbra/config.rb
|
200
183
|
- lib/umbra/encoder.rb
|
201
184
|
- lib/umbra/middleware.rb
|
185
|
+
- lib/umbra/pb/umbra_pb.rb
|
202
186
|
- lib/umbra/publisher.rb
|
203
|
-
- lib/umbra/request_builder.rb
|
204
|
-
- lib/umbra/shadow_requester.rb
|
205
|
-
- lib/umbra/subscriber.rb
|
206
187
|
- lib/umbra/version.rb
|
207
188
|
- umbra-rb.gemspec
|
208
189
|
homepage: https://github.com/carwow/umbra
|
@@ -211,8 +192,9 @@ licenses:
|
|
211
192
|
metadata:
|
212
193
|
allowed_push_host: https://rubygems.org
|
213
194
|
homepage_uri: https://github.com/carwow/umbra
|
195
|
+
github_repo: https://github.com/carwow/umbra
|
214
196
|
source_code_uri: https://github.com/carwow/umbra
|
215
|
-
post_install_message:
|
197
|
+
post_install_message:
|
216
198
|
rdoc_options: []
|
217
199
|
require_paths:
|
218
200
|
- lib
|
@@ -223,12 +205,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
223
205
|
version: '0'
|
224
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
207
|
requirements:
|
226
|
-
- - "
|
208
|
+
- - ">="
|
227
209
|
- !ruby/object:Gem::Version
|
228
|
-
version:
|
210
|
+
version: '0'
|
229
211
|
requirements: []
|
230
|
-
rubygems_version: 3.
|
231
|
-
signing_key:
|
212
|
+
rubygems_version: 3.5.11
|
213
|
+
signing_key:
|
232
214
|
specification_version: 4
|
233
215
|
summary: A shadow requesting library for rack based applications
|
234
216
|
test_files: []
|
data/.circleci/config.yml
DELETED
@@ -1,59 +0,0 @@
|
|
1
|
-
ruby: &ruby
|
2
|
-
image: carwow/ruby-ci:2.6
|
3
|
-
|
4
|
-
redis: &redis
|
5
|
-
image: redis
|
6
|
-
|
7
|
-
version: 2
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
bundle:
|
11
|
-
working_directory: ~/umbra
|
12
|
-
docker:
|
13
|
-
- *ruby
|
14
|
-
steps:
|
15
|
-
- checkout
|
16
|
-
- restore_cache:
|
17
|
-
keys:
|
18
|
-
- bundle-{{ checksum "Gemfile.lock" }}
|
19
|
-
- bundle-
|
20
|
-
- run: |
|
21
|
-
bundle config --local path vendor/bundle &&
|
22
|
-
bundle check || bundle install --jobs=4 --retry=3
|
23
|
-
- save_cache:
|
24
|
-
key: bundle-{{ checksum "Gemfile.lock" }}
|
25
|
-
paths: [~/umbra/vendor/bundle]
|
26
|
-
- persist_to_workspace:
|
27
|
-
root: '~'
|
28
|
-
paths: [umbra]
|
29
|
-
|
30
|
-
rubocop:
|
31
|
-
working_directory: ~/umbra
|
32
|
-
docker:
|
33
|
-
- *ruby
|
34
|
-
steps:
|
35
|
-
- attach_workspace:
|
36
|
-
at: '~'
|
37
|
-
- run: bundle exec rubocop
|
38
|
-
|
39
|
-
tests:
|
40
|
-
working_directory: ~/umbra
|
41
|
-
docker:
|
42
|
-
- *ruby
|
43
|
-
- *redis
|
44
|
-
steps:
|
45
|
-
- attach_workspace:
|
46
|
-
at: '~'
|
47
|
-
- run: |
|
48
|
-
bundle exec rspec
|
49
|
-
|
50
|
-
workflows:
|
51
|
-
version: 2
|
52
|
-
build:
|
53
|
-
jobs:
|
54
|
-
- bundle
|
55
|
-
- rubocop:
|
56
|
-
requires: [bundle]
|
57
|
-
- tests:
|
58
|
-
requires: [bundle]
|
59
|
-
|
data/.gitignore
DELETED
data/.rubocop.yml
DELETED
data/Gemfile.lock
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
umbra-rb (0.3.0.pre)
|
5
|
-
concurrent-ruby (~> 1.1)
|
6
|
-
multi_json (~> 1.13)
|
7
|
-
oj (~> 3.9)
|
8
|
-
redis (~> 4.1)
|
9
|
-
typhoeus (~> 1.3)
|
10
|
-
|
11
|
-
GEM
|
12
|
-
remote: https://rubygems.org/
|
13
|
-
specs:
|
14
|
-
addressable (2.7.0)
|
15
|
-
public_suffix (>= 2.0.2, < 5.0)
|
16
|
-
ast (2.4.0)
|
17
|
-
carwow_rubocop (3.2.1)
|
18
|
-
rubocop (>= 0.78)
|
19
|
-
rubocop-performance
|
20
|
-
rubocop-rspec
|
21
|
-
coderay (1.1.2)
|
22
|
-
concurrent-ruby (1.1.5)
|
23
|
-
crack (0.4.3)
|
24
|
-
safe_yaml (~> 1.0.0)
|
25
|
-
diff-lcs (1.3)
|
26
|
-
ethon (0.12.0)
|
27
|
-
ffi (>= 1.3.0)
|
28
|
-
ffi (1.12.1)
|
29
|
-
hashdiff (1.0.0)
|
30
|
-
jaro_winkler (1.5.4)
|
31
|
-
method_source (0.9.2)
|
32
|
-
multi_json (1.14.1)
|
33
|
-
oj (3.10.1)
|
34
|
-
parallel (1.19.1)
|
35
|
-
parser (2.7.0.2)
|
36
|
-
ast (~> 2.4.0)
|
37
|
-
pry (0.12.2)
|
38
|
-
coderay (~> 1.1.0)
|
39
|
-
method_source (~> 0.9.0)
|
40
|
-
public_suffix (4.0.3)
|
41
|
-
rack (2.1.1)
|
42
|
-
rainbow (3.0.0)
|
43
|
-
rake (13.0.1)
|
44
|
-
redis (4.1.3)
|
45
|
-
rspec (3.9.0)
|
46
|
-
rspec-core (~> 3.9.0)
|
47
|
-
rspec-expectations (~> 3.9.0)
|
48
|
-
rspec-mocks (~> 3.9.0)
|
49
|
-
rspec-core (3.9.0)
|
50
|
-
rspec-support (~> 3.9.0)
|
51
|
-
rspec-expectations (3.9.0)
|
52
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
53
|
-
rspec-support (~> 3.9.0)
|
54
|
-
rspec-mocks (3.9.0)
|
55
|
-
diff-lcs (>= 1.2.0, < 2.0)
|
56
|
-
rspec-support (~> 3.9.0)
|
57
|
-
rspec-support (3.9.0)
|
58
|
-
rubocop (0.79.0)
|
59
|
-
jaro_winkler (~> 1.5.1)
|
60
|
-
parallel (~> 1.10)
|
61
|
-
parser (>= 2.7.0.1)
|
62
|
-
rainbow (>= 2.2.2, < 4.0)
|
63
|
-
ruby-progressbar (~> 1.7)
|
64
|
-
unicode-display_width (>= 1.4.0, < 1.7)
|
65
|
-
rubocop-performance (1.5.2)
|
66
|
-
rubocop (>= 0.71.0)
|
67
|
-
rubocop-rspec (1.37.1)
|
68
|
-
rubocop (>= 0.68.1)
|
69
|
-
ruby-progressbar (1.10.1)
|
70
|
-
safe_yaml (1.0.5)
|
71
|
-
typhoeus (1.3.1)
|
72
|
-
ethon (>= 0.9.0)
|
73
|
-
unicode-display_width (1.6.0)
|
74
|
-
webmock (3.8.0)
|
75
|
-
addressable (>= 2.3.6)
|
76
|
-
crack (>= 0.3.2)
|
77
|
-
hashdiff (>= 0.4.0, < 2.0.0)
|
78
|
-
|
79
|
-
PLATFORMS
|
80
|
-
ruby
|
81
|
-
|
82
|
-
DEPENDENCIES
|
83
|
-
bundler (~> 2.0)
|
84
|
-
carwow_rubocop
|
85
|
-
pry
|
86
|
-
rack
|
87
|
-
rake (~> 13.0)
|
88
|
-
rspec (~> 3.0)
|
89
|
-
umbra-rb!
|
90
|
-
webmock (~> 3)
|
91
|
-
|
92
|
-
BUNDLED WITH
|
93
|
-
2.0.2
|
data/LICENSE.txt
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
The MIT License (MIT)
|
2
|
-
|
3
|
-
Copyright (c) 2019 Christian Gregg
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,100 +0,0 @@
|
|
1
|
-
# umbra :waning_crescent_moon:
|
2
|
-
|
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"
|
9
|
-
|
10
|
-
`umbra` is a rack middleware that allows you to create shadow requests via a redis pub/sub channel.
|
11
|
-
|
12
|
-
# Installation
|
13
|
-
|
14
|
-
Add this to your `Gemfile`
|
15
|
-
|
16
|
-
```ruby
|
17
|
-
gem 'umbra-rb'
|
18
|
-
```
|
19
|
-
|
20
|
-
And then execute:
|
21
|
-
|
22
|
-
$ bundle
|
23
|
-
|
24
|
-
Or install it yourself as:
|
25
|
-
|
26
|
-
$ gem install umbra-rb
|
27
|
-
|
28
|
-
|
29
|
-
## Usage
|
30
|
-
|
31
|
-
A minimal rack application using `umbra` would look like this:
|
32
|
-
|
33
|
-
```ruby
|
34
|
-
# /config.ru
|
35
|
-
require 'rack'
|
36
|
-
require 'rack/lobster'
|
37
|
-
require 'umbra'
|
38
|
-
|
39
|
-
Umbra.configure
|
40
|
-
|
41
|
-
use Umbra::Middleware
|
42
|
-
run Rack::Lobster.new
|
43
|
-
|
44
|
-
```
|
45
|
-
|
46
|
-
If using Rails you can achieve the same via an initializer:
|
47
|
-
|
48
|
-
```ruby
|
49
|
-
# /config/initializers/umbra.rb
|
50
|
-
require 'umbra'
|
51
|
-
|
52
|
-
Umbra.configure
|
53
|
-
|
54
|
-
Rails.application.config.middleware.use(Umbra::Middleware)
|
55
|
-
```
|
56
|
-
|
57
|
-
Then, in another process, you can start receiving each request via an `Umbra::Subscriber`.
|
58
|
-
`Umbra::Subscriber` can be initialized with anything response to `.call`. For example:
|
59
|
-
|
60
|
-
```ruby
|
61
|
-
Umbra::Subscriber.new(
|
62
|
-
proc { |payload| puts "New Request: #{payload}" }
|
63
|
-
).start
|
64
|
-
```
|
65
|
-
|
66
|
-
The `payload` is the encoded request and response, as defined by the configured encoder. By default, this is `Umbra::Encoder`.
|
67
|
-
|
68
|
-
`umbra` also provides some helper classes for common use cases:
|
69
|
-
|
70
|
-
- `Umbra::RequestBuilder` takes the default encoding and returns a `Typhoeus::Request` object.
|
71
|
-
- `Umbra::ShadowRequester` can be configured to shadow requests `count:` times using a `pool:` of threads via a thread queue.
|
72
|
-
- More to come...
|
73
|
-
|
74
|
-
|
75
|
-
# Config
|
76
|
-
|
77
|
-
`umbra` allows you to add custom configuration by passing a block to `Umbra.configure`. You may pass custom configuration in the following form:
|
78
|
-
|
79
|
-
```ruby
|
80
|
-
Umbra.configure do |config|
|
81
|
-
config.<config_option> = <config_value>
|
82
|
-
end
|
83
|
-
```
|
84
|
-
|
85
|
-
| config_option | default | description |
|
86
|
-
| ------------- | ------- | ----------- |
|
87
|
-
| publisher | `Umbra::Publisher` | Must respond to `call`. By default, pushes the encoded rack request/response to a `Queue` that is consumed in a different thread and publishes to `redis`. |
|
88
|
-
| request_selector | `Umbra::RequestSelector` / `proc { true }` | Must respond to `call`. Determines whether request/response will be published |
|
89
|
-
| encoder | `Umbra::Encoder` | Must response to `call`. Encodes the rack request/response for publishing |
|
90
|
-
| error_handler | `Umbra::SupressErrorHandler` / `proc { nil }` | Must respond to `call`. Called on exception, is always passed the exception as first argument, *may* be passed rack environment and response. |
|
91
|
-
| redis_options | `{}` | Hash of options passed to `Redis` client. See [`Redis::Client` docs](https://www.rubydoc.info/gems/redis/Redis/Client) |
|
92
|
-
| logger | `Logger.new(STDOUT)` | The logger to be used. |
|
93
|
-
|
94
|
-
## Contributing
|
95
|
-
|
96
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/carwow/umbra.
|
97
|
-
|
98
|
-
## License
|
99
|
-
|
100
|
-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Umbra
|
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
|
-
|
10
|
-
class << self
|
11
|
-
def call(env)
|
12
|
-
Typhoeus::Request.new(
|
13
|
-
base_url(env) + url(env),
|
14
|
-
method: method(env),
|
15
|
-
body: body(env),
|
16
|
-
headers: headers(env)
|
17
|
-
)
|
18
|
-
end
|
19
|
-
|
20
|
-
private
|
21
|
-
|
22
|
-
def headers(env)
|
23
|
-
request(env)
|
24
|
-
.fetch('headers')
|
25
|
-
.merge(UMBRA_HEADERS)
|
26
|
-
.transform_keys { |key| key.split('_').drop(1).map(&:capitalize).join('-') }
|
27
|
-
end
|
28
|
-
|
29
|
-
def method(env)
|
30
|
-
request(env).fetch('method').downcase.to_sym
|
31
|
-
end
|
32
|
-
|
33
|
-
def body(env)
|
34
|
-
request(env).fetch('body')
|
35
|
-
end
|
36
|
-
|
37
|
-
def url(env)
|
38
|
-
request = request(env)
|
39
|
-
query = request.fetch('query')
|
40
|
-
path = request.fetch('script_name') + request.fetch('path_info')
|
41
|
-
|
42
|
-
query.empty? ? path : path + "?#{query}"
|
43
|
-
end
|
44
|
-
|
45
|
-
def base_url(env)
|
46
|
-
request = request(env)
|
47
|
-
scheme = request.fetch('scheme')
|
48
|
-
host = request.fetch('host')
|
49
|
-
|
50
|
-
"#{scheme}://#{host}"
|
51
|
-
end
|
52
|
-
|
53
|
-
def request(env)
|
54
|
-
env.fetch('request')
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
module Umbra
|
2
|
-
class ShadowRequester
|
3
|
-
attr_reader :queue, :count
|
4
|
-
|
5
|
-
def initialize(count: 1, pool: 1, max_queue_size: 100)
|
6
|
-
@count = count
|
7
|
-
@queue ||= Concurrent::CachedThreadPool.new(
|
8
|
-
min_threads: 1,
|
9
|
-
max_threads: pool,
|
10
|
-
max_queue: max_queue_size,
|
11
|
-
fallback_policy: :abort
|
12
|
-
)
|
13
|
-
end
|
14
|
-
|
15
|
-
def call(env)
|
16
|
-
queue << proc { call!(env) }
|
17
|
-
|
18
|
-
true
|
19
|
-
rescue Concurrent::RejectedExecutionError
|
20
|
-
Umbra.logger.warn '[umbra] Shadowing queue at max - dropping items'
|
21
|
-
|
22
|
-
false
|
23
|
-
end
|
24
|
-
|
25
|
-
def call!(env)
|
26
|
-
hydra = Typhoeus::Hydra.new
|
27
|
-
request = RequestBuilder.call(env)
|
28
|
-
|
29
|
-
@count.times { hydra.queue(request) }
|
30
|
-
|
31
|
-
hydra.run
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
data/lib/umbra/subscriber.rb
DELETED