magic_pipe 0.1.0 → 0.2.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/.travis.yml +4 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile.lock +1 -1
- data/README.md +40 -1
- data/lib/magic_pipe/codecs/base.rb +9 -4
- data/lib/magic_pipe/config.rb +21 -1
- data/lib/magic_pipe/transports/https.rb +17 -3
- data/lib/magic_pipe/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18fc9852ccb722d15f8d65698d45fb83123aebe7
|
4
|
+
data.tar.gz: 7762b69a3dedfa880e5111cee8f91cd9a031c5e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 100dd028a5f518b410990725bbbc2d85d4e015d74f5aed6dea0e59417335e23a84d579fdb6cdae21f89c9c0f13b097c7a344bcf87c6165f770e0f4dd51c6c2e7
|
7
|
+
data.tar.gz: f2d5f95580ab2cc93ab3614bf16721c3c36c6c1dc43a7fdbdbee2370bc43c8efe889ff67b515d777953b1032159dc47674587cdb44b4fbd6fe1c2779765140cd
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -127,6 +127,9 @@ require "magic_pipe/transports/https"
|
|
127
127
|
require "magic_pipe/transports/sqs"
|
128
128
|
|
129
129
|
$magic_pipe = MagicPipe.build do |mp|
|
130
|
+
mp.client_name = :my_magic_pipe
|
131
|
+
mp.producer_name = "My Awesome Service (Production)"
|
132
|
+
|
130
133
|
mp.sender = :async
|
131
134
|
mp.loader = :simple_active_record
|
132
135
|
|
@@ -138,7 +141,7 @@ $magic_pipe = MagicPipe.build do |mp|
|
|
138
141
|
}
|
139
142
|
mp.https_transport_options = {
|
140
143
|
url: "https://my.receiver.service/foo",
|
141
|
-
|
144
|
+
basic_auth_user: "bar",
|
142
145
|
}
|
143
146
|
mp.sqs_transport_options = {
|
144
147
|
queue: "my_data_stream"
|
@@ -202,6 +205,42 @@ export AWS_SECRET_ACCESS_KEY='bar'
|
|
202
205
|
export AWS_REGION='us-east-1'
|
203
206
|
```
|
204
207
|
|
208
|
+
#### Transport: HTTPS
|
209
|
+
|
210
|
+
This transport builds a [Faraday](https://github.com/lostisland/faraday) connection. A number of options can be configured:
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
$magic_pipe = MagicPipe.build do |mp|
|
214
|
+
mp.transport = :https
|
215
|
+
|
216
|
+
mp.https_transport_options = {
|
217
|
+
url: "https://my.receiver.service/messages",
|
218
|
+
dynamic_path_builder: -> (topic) { topic }
|
219
|
+
|
220
|
+
basic_auth_user: "foo",
|
221
|
+
basic_auth_password: "bar",
|
222
|
+
|
223
|
+
timeout: 2,
|
224
|
+
open_timeout: 3,
|
225
|
+
}
|
226
|
+
end
|
227
|
+
```
|
228
|
+
|
229
|
+
The `dynamic_path_builder` setting should be a callable that will receive the topic name. It defaults to `nil`, in which case the base URL will be used as is. If present, its return value will be used in Faraday as:
|
230
|
+
|
231
|
+
```ruby
|
232
|
+
faraday_connection.post do |r|
|
233
|
+
r.url dynamic_path_builder.call(metadata[:topic])
|
234
|
+
end
|
235
|
+
```
|
236
|
+
|
237
|
+
Which will result in requests as:
|
238
|
+
|
239
|
+
```
|
240
|
+
HTTP POST https://my.receiver.service/messages/a-topic-name
|
241
|
+
```
|
242
|
+
|
243
|
+
|
205
244
|
## Dependencies
|
206
245
|
|
207
246
|
Becasuse of MagicPipe's modular design, and in order to keep a small installation footprint, all of its dependencies are optional. Users of the library need to manually install the required dependencies in their projects.
|
@@ -7,17 +7,22 @@ module MagicPipe
|
|
7
7
|
# to an ActiveModel::Serializer or
|
8
8
|
# ActiveRecord object.
|
9
9
|
#
|
10
|
-
def initialize(
|
11
|
-
@
|
10
|
+
def initialize(envelope)
|
11
|
+
@envelope = envelope
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_reader :
|
15
|
-
alias_method :
|
14
|
+
attr_reader :envelope
|
15
|
+
alias_method :object, :envelope
|
16
|
+
alias_method :o, :envelope
|
16
17
|
|
17
18
|
def encode
|
18
19
|
raise NotImplementedError
|
19
20
|
end
|
20
21
|
|
22
|
+
def inner_object
|
23
|
+
@envelope.body
|
24
|
+
end
|
25
|
+
|
21
26
|
def type
|
22
27
|
self.class.const_get(:TYPE)
|
23
28
|
end
|
data/lib/magic_pipe/config.rb
CHANGED
@@ -54,8 +54,28 @@ module MagicPipe
|
|
54
54
|
return unless @https_transport_options
|
55
55
|
|
56
56
|
defaults = {
|
57
|
+
# The base URL. It can contain a path
|
58
|
+
#
|
57
59
|
url: "https://localhost:8080/foo",
|
58
|
-
|
60
|
+
#
|
61
|
+
# A callable that receives the topic name.
|
62
|
+
# For example if you want to use the topic
|
63
|
+
# as sub path, provide an identity proc:
|
64
|
+
#
|
65
|
+
# -> (t) { t }
|
66
|
+
#
|
67
|
+
# The callable should return an absolute "/my/path"
|
68
|
+
# value to replace the entire path of the configured
|
69
|
+
# URL. It should return a relative "my/path" value
|
70
|
+
# to simply append the dynamic path to the base URL.
|
71
|
+
#
|
72
|
+
# When this parameter is nil, the configured URL
|
73
|
+
# will be used as is.
|
74
|
+
#
|
75
|
+
dynamic_path_builder: nil,
|
76
|
+
|
77
|
+
basic_auth_user: "missing",
|
78
|
+
basic_auth_password: "x",
|
59
79
|
timeout: 2,
|
60
80
|
open_timeout: 3,
|
61
81
|
}
|
@@ -11,6 +11,7 @@ module MagicPipe
|
|
11
11
|
super(config, metrics)
|
12
12
|
@options = @config.https_transport_options
|
13
13
|
@conn = build_connection
|
14
|
+
@path_builder = @options[:dynamic_path_builder]
|
14
15
|
end
|
15
16
|
|
16
17
|
attr_reader :conn
|
@@ -21,6 +22,9 @@ module MagicPipe
|
|
21
22
|
#
|
22
23
|
def submit(payload, metadata)
|
23
24
|
@conn.post do |r|
|
25
|
+
path = dynamic_path(metadata[:topic])
|
26
|
+
r.url(path) if path
|
27
|
+
|
24
28
|
r.body = payload
|
25
29
|
r.headers["X-MagicPipe-Sent-At"] = metadata[:time]
|
26
30
|
r.headers["X-MagicPipe-Topic"] = metadata[:topic]
|
@@ -31,12 +35,22 @@ module MagicPipe
|
|
31
35
|
|
32
36
|
private
|
33
37
|
|
38
|
+
|
39
|
+
def dynamic_path(topic)
|
40
|
+
return nil unless !!@path_builder
|
41
|
+
@path_builder.call(topic)
|
42
|
+
end
|
43
|
+
|
34
44
|
def url
|
35
45
|
@options.fetch(:url)
|
36
46
|
end
|
37
47
|
|
38
|
-
def
|
39
|
-
@options.fetch(:
|
48
|
+
def basic_auth_user
|
49
|
+
@options.fetch(:basic_auth_user)
|
50
|
+
end
|
51
|
+
|
52
|
+
def basic_auth_password
|
53
|
+
@options.fetch(:basic_auth_password)
|
40
54
|
end
|
41
55
|
|
42
56
|
def timeout
|
@@ -64,7 +78,7 @@ module MagicPipe
|
|
64
78
|
def build_connection
|
65
79
|
Faraday.new(url) do |f|
|
66
80
|
f.request :retry, max: 2, interval: 0.1, backoff_factor: 2
|
67
|
-
f.request :basic_auth,
|
81
|
+
f.request :basic_auth, basic_auth_user, basic_auth_password
|
68
82
|
|
69
83
|
f.headers['Content-Type'] = content_type
|
70
84
|
f.headers['User-Agent'] = user_agent
|
data/lib/magic_pipe/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: magic_pipe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tommaso Pavese
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-02-
|
11
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|