magic_pipe 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: a16af40ae46abcba5bafeca16db82382e91bd4ee
4
- data.tar.gz: 31eb6c6e23ce061727e467879869a749adf7af08
3
+ metadata.gz: 18fc9852ccb722d15f8d65698d45fb83123aebe7
4
+ data.tar.gz: 7762b69a3dedfa880e5111cee8f91cd9a031c5e3
5
5
  SHA512:
6
- metadata.gz: 4cfebdd5448a995c0a93b0f10b1ac5f950e9ed9c2d94c1eeed99020da205d1943d520d2c24fa91279e48eb779f27cf5f2de7fb5ad469277fb2f083675abc66c2
7
- data.tar.gz: 82cfe543de0788e2e3cf758450396de4707fa7255b0bc90564465203b3d6f439e23120cc85a38c20ac1c72ca23edee4fa3d738399c3f314f778a71dd406ecff1
6
+ metadata.gz: 100dd028a5f518b410990725bbbc2d85d4e015d74f5aed6dea0e59417335e23a84d579fdb6cdae21f89c9c0f13b097c7a344bcf87c6165f770e0f4dd51c6c2e7
7
+ data.tar.gz: f2d5f95580ab2cc93ab3614bf16721c3c36c6c1dc43a7fdbdbee2370bc43c8efe889ff67b515d777953b1032159dc47674587cdb44b4fbd6fe1c2779765140cd
data/.travis.yml CHANGED
@@ -6,3 +6,7 @@ rvm:
6
6
  - 2.2.9
7
7
  script:
8
8
  - bundle exec rspec
9
+ notifications:
10
+ email:
11
+ on_success: never
12
+ on_failure: never
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # MagicPipe Changelog
2
2
 
3
+ ## v0.2.0
4
+
5
+ Enhancing the HTTPS transport:
6
+
7
+ * Allow to configure both user and password for HTTP Basic Auth.
8
+ * Allow to configure a callable to use dynamic URL paths.
9
+
3
10
  ## v0.1.0
4
11
 
5
12
  Initial release.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magic_pipe (0.1.0)
4
+ magic_pipe (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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
- auth_token: "bar",
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(object)
11
- @object = object
10
+ def initialize(envelope)
11
+ @envelope = envelope
12
12
  end
13
13
 
14
- attr_reader :object
15
- alias_method :o, :object
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
@@ -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
- auth_token: "missing",
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 auth_token
39
- @options.fetch(:auth_token)
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, auth_token, 'x'
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
@@ -1,3 +1,3 @@
1
1
  module MagicPipe
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-04 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler