magic_pipe 0.2.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18fc9852ccb722d15f8d65698d45fb83123aebe7
4
- data.tar.gz: 7762b69a3dedfa880e5111cee8f91cd9a031c5e3
3
+ metadata.gz: a3eadd291f2aa10633773f3cd5bf74a032300941
4
+ data.tar.gz: 3f78a0d8475045c972cdbcb20b39331e2290cd8d
5
5
  SHA512:
6
- metadata.gz: 100dd028a5f518b410990725bbbc2d85d4e015d74f5aed6dea0e59417335e23a84d579fdb6cdae21f89c9c0f13b097c7a344bcf87c6165f770e0f4dd51c6c2e7
7
- data.tar.gz: f2d5f95580ab2cc93ab3614bf16721c3c36c6c1dc43a7fdbdbee2370bc43c8efe889ff67b515d777953b1032159dc47674587cdb44b4fbd6fe1c2779765140cd
6
+ metadata.gz: fcb5e475d09bb7cdea135a7850a70f0d5168015a77f5a60153bfddf66c110a00ccf25051a2c4a4e770183265f4e232f39d321c645321936510b425be9fa6955b
7
+ data.tar.gz: bfb8dc0ac117ca58a78af84c94869e1e017206ff573980b94e544075a81b6d5cd1a9c4360d0936f6998fdae3baa4148b30ba0400a12e07e1e476d905b351b2ca
@@ -1,5 +1,28 @@
1
1
  # MagicPipe Changelog
2
2
 
3
+ ## v0.3.0
4
+
5
+ * Allow to set the `basic_auth` config as a proc which gets the topic name passed. (thanks @Crunch09, https://github.com/tompave/magic_pipe/pull/1)
6
+
7
+ Example:
8
+
9
+ ```ruby
10
+ basic_auth: ->(topic) {
11
+ username = ENV["TOPIC_#{topic.singularize.upcase}_USER"]
12
+ password = ENV["SECRET_PASSWORD"]
13
+ "#{username}:#{password}"
14
+ }
15
+ ```
16
+
17
+ It should always return a string in the format `USERNAME:PASSWORD`. Instead
18
+ of using a proc this string can be set directly:
19
+
20
+ ```ruby
21
+ basic_auth: "foo:bar"
22
+ ```
23
+
24
+ In favor of this `basic_auth_user` and `basic_auth_password` have been removed.
25
+
3
26
  ## v0.2.0
4
27
 
5
28
  Enhancing the HTTPS transport:
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magic_pipe (0.2.0)
4
+ magic_pipe (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -141,7 +141,7 @@ $magic_pipe = MagicPipe.build do |mp|
141
141
  }
142
142
  mp.https_transport_options = {
143
143
  url: "https://my.receiver.service/foo",
144
- basic_auth_user: "bar",
144
+ basic_auth: "bar:foo",
145
145
  }
146
146
  mp.sqs_transport_options = {
147
147
  queue: "my_data_stream"
@@ -217,8 +217,7 @@ $magic_pipe = MagicPipe.build do |mp|
217
217
  url: "https://my.receiver.service/messages",
218
218
  dynamic_path_builder: -> (topic) { topic }
219
219
 
220
- basic_auth_user: "foo",
221
- basic_auth_password: "bar",
220
+ basic_auth: "foo:bar",
222
221
 
223
222
  timeout: 2,
224
223
  open_timeout: 3,
@@ -230,7 +229,7 @@ The `dynamic_path_builder` setting should be a callable that will receive the to
230
229
 
231
230
  ```ruby
232
231
  faraday_connection.post do |r|
233
- r.url dynamic_path_builder.call(metadata[:topic])
232
+ r.url dynamic_path_builder.call(current_topic)
234
233
  end
235
234
  ```
236
235
 
@@ -74,8 +74,7 @@ module MagicPipe
74
74
  #
75
75
  dynamic_path_builder: nil,
76
76
 
77
- basic_auth_user: "missing",
78
- basic_auth_password: "x",
77
+ basic_auth: "missing:x",
79
78
  timeout: 2,
80
79
  open_timeout: 3,
81
80
  }
@@ -21,6 +21,8 @@ module MagicPipe
21
21
  # So that it can be retried?
22
22
  #
23
23
  def submit(payload, metadata)
24
+ username, password = basic_auth(metadata[:topic])
25
+ @conn.basic_auth(username, password || "x")
24
26
  @conn.post do |r|
25
27
  path = dynamic_path(metadata[:topic])
26
28
  r.url(path) if path
@@ -45,12 +47,14 @@ module MagicPipe
45
47
  @options.fetch(:url)
46
48
  end
47
49
 
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)
50
+ def basic_auth(topic)
51
+ user_auth = @options.fetch(:basic_auth)
52
+ credentials = if user_auth.respond_to?(:call)
53
+ user_auth.call(topic)
54
+ else
55
+ user_auth
56
+ end
57
+ credentials.split(':')
54
58
  end
55
59
 
56
60
  def timeout
@@ -78,7 +82,6 @@ module MagicPipe
78
82
  def build_connection
79
83
  Faraday.new(url) do |f|
80
84
  f.request :retry, max: 2, interval: 0.1, backoff_factor: 2
81
- f.request :basic_auth, basic_auth_user, basic_auth_password
82
85
 
83
86
  f.headers['Content-Type'] = content_type
84
87
  f.headers['User-Agent'] = user_agent
@@ -1,3 +1,3 @@
1
1
  module MagicPipe
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.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.2.0
4
+ version: 0.3.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-13 00:00:00.000000000 Z
11
+ date: 2018-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -254,4 +254,3 @@ specification_version: 4
254
254
  summary: A Magic Pipe to send data in arbitrary formats to configurable backends,
255
255
  with topics.
256
256
  test_files: []
257
- has_rdoc: