bps-stan 0.1.3 → 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
  SHA256:
3
- metadata.gz: fd81b99b13cfa8b5be0f5d16ac87bfe1b1fadf2fbe15f7e64a35aa03b7738434
4
- data.tar.gz: 981a5ffacde21e61b6e40e04d933cbc25ed684dfc8d2ed70829a088affa61890
3
+ metadata.gz: e6d0067ac2cf8b4ee41b4f7ff5f33c1ee6eff75304cd4c5775b753b1f126f100
4
+ data.tar.gz: 64c67e20c09fbe73f8e72512a4d9320551d518c962e2297f536a806270351748
5
5
  SHA512:
6
- metadata.gz: 5df714f945e601d841a5bce43760b354494f83b97eb4544c8c515fecc87026de44ebb343ab657fed2910880f6beb9cf7d212e703a05ee4036b41a5d6e14f795d
7
- data.tar.gz: 03cafb2a8283b7875f353f9c8ccef57752e1f5d4b18e165b85ff8e1cc4a16523c96f06c11aa1cd6ad409d1a9951b7ae700aa4bfd18661bb4aed15b921590b75b
6
+ metadata.gz: 80d8471eb192dd551615b1c0f8c8278dd3bc9e578dc4ebdf1a0844162a95a32c639eb3047572c692323756085b3bacb5d3c658dd4e1f73c27637e86335fda151
7
+ data.tar.gz: 3af18785c7eb3ab110dc0966e7800797fe1b387104311c6736f1ad91621152a4b2d27b628021d7bcbeae880dd39ea4d90b7a8053ebdf986928f31527d2360bf0
@@ -18,5 +18,5 @@ Gem::Specification.new do |s|
18
18
  s.required_ruby_version = '>= 2.6.0'
19
19
 
20
20
  s.add_dependency 'bps', s.version
21
- s.add_dependency 'nats-streaming', '= 0.2.2'
21
+ s.add_dependency 'nats-streaming', '~> 0.2.2'
22
22
  end
@@ -28,6 +28,7 @@ module BPS
28
28
  reconnect_time_wait: :float,
29
29
  max_reconnect_attempts: :int,
30
30
  connect_timeout: :float,
31
+ tls_ca_file: :string,
31
32
  # TODO: review, list all of them: https://github.com/nats-io/nats.rb (there's tls config etc)
32
33
  },
33
34
  }.freeze
@@ -36,10 +37,10 @@ module BPS
36
37
  port = url.port&.to_s || '4222'
37
38
  servers = CGI.unescape(url.host).split(',').map do |host|
38
39
  addr = "nats://#{host}"
39
- addr << ':' << port unless addr.match(/:\d+$/)
40
+ addr << ':' << port unless /:\d+$/.match?(addr)
40
41
  addr
41
42
  end
42
- opts = CGI.parse(url.query).transform_values {|v| v.size == 1 ? v[0] : v }
43
+ opts = CGI.parse(url.query || '').transform_values {|v| v.size == 1 ? v[0] : v }
43
44
  cluster_id = opts.delete('cluster_id')
44
45
  client_id = opts.delete('client_id')
45
46
  [cluster_id, client_id, { nats: { servers: servers } }]
@@ -56,6 +57,14 @@ module BPS
56
57
  def initialize(cluster_id, client_id, nats: {}, **opts)
57
58
  super()
58
59
 
60
+ # handle TLS if CA file is provided:
61
+ if !nats[:tls] && nats[:tls_ca_file]
62
+ ctx = OpenSSL::SSL::SSLContext.new
63
+ ctx.set_params
64
+ ctx.ca_file = nats.delete(:tls_ca_file)
65
+ nats[:tls] = ctx
66
+ end
67
+
59
68
  @topics = {}
60
69
  @client = ::STAN::Client.new
61
70
  @client.connect(cluster_id, client_id, nats: nats, **opts.slice(*CLIENT_OPTS.keys))
@@ -2,28 +2,29 @@ require 'bps/stan'
2
2
  require 'spec_helper'
3
3
 
4
4
  RSpec.describe 'STAN', stan: true do
5
- context 'resolve addrs' do
6
- let(:publisher) { double('BPS::Publisher::STAN') }
5
+ context 'with addr resolving' do
6
+ let(:publisher) { instance_double('BPS::Publisher::STAN') }
7
+
7
8
  before { allow(BPS::Publisher::STAN).to receive(:new).and_return(publisher) }
8
9
 
9
- it 'should resolve simple URLs' do
10
- expect(BPS::Publisher::STAN)
10
+ it 'resolves simple URLs' do
11
+ allow(BPS::Publisher::STAN)
11
12
  .to receive(:new)
12
13
  .with('CLUSTER', 'CLIENT', nats: { servers: ['nats://test.host:4222'] })
13
14
  .and_return(publisher)
14
15
  BPS::Publisher.resolve(URI.parse('stan://test.host:4222?cluster_id=CLUSTER&client_id=CLIENT'))
15
16
  end
16
17
 
17
- it 'should resolve URLs with multiple hosts' do
18
- expect(BPS::Publisher::STAN)
18
+ it 'resolves URLs with multiple hosts' do
19
+ allow(BPS::Publisher::STAN)
19
20
  .to receive(:new)
20
21
  .with('CLUSTER', 'CLIENT', nats: { servers: ['nats://foo.host:4222', 'nats://bar.host:4222'] })
21
22
  .and_return(publisher)
22
23
  BPS::Publisher.resolve(URI.parse('stan://foo.host,bar.host:4222?cluster_id=CLUSTER&client_id=CLIENT'))
23
24
  end
24
25
 
25
- it 'should resolve URLs with multiple hosts/ports' do
26
- expect(BPS::Publisher::STAN)
26
+ it 'resolves URLs with multiple hosts/ports' do
27
+ allow(BPS::Publisher::STAN)
27
28
  .to receive(:new)
28
29
  .with('CLUSTER', 'CLIENT', nats: { servers: ['nats://foo.host:4223', 'nats://bar.host:4222'] })
29
30
  .and_return(publisher)
@@ -35,7 +36,7 @@ RSpec.describe 'STAN', stan: true do
35
36
  let(:cluster_id) { 'test-cluster' } # this is a default cluster for https://hub.docker.com/_/nats-streaming
36
37
  let(:client_id) { 'bps-test' }
37
38
 
38
- let(:nats_servers) { ENV.fetch('NATS_SERVERS', '127.0.0.1:4222').split(',') }
39
+ let(:nats_servers) { ENV.fetch('STAN_SERVERS', '127.0.0.1:4222').split(',') }
39
40
  let(:nats_servers_with_scheme) { nats_servers.map {|s| "nats://#{s}" } }
40
41
 
41
42
  let(:publisher_url) { "stan://#{CGI.escape(nats_servers.join(','))}/?cluster_id=#{cluster_id}&client_id=#{client_id}" }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bps-stan
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Black Square Media
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-24 00:00:00.000000000 Z
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bps
@@ -16,26 +16,26 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.3
19
+ version: 0.2.0
20
20
  type: :runtime
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: 0.1.3
26
+ version: 0.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: nats-streaming
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: 0.2.2
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.2
41
41
  description: https://github.com/bsm/bps
@@ -68,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0'
70
70
  requirements: []
71
- rubygems_version: 3.1.2
71
+ rubygems_version: 3.1.4
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: BPS adapter for nats-streaming