fastly_nsq 0.7.1 → 0.8.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: 1980f54ed1aa7fe8ef369d7dfb3f9bf969a7c662
4
- data.tar.gz: c8c5e7ffa1cb2131f206842f54b6e8c6f5f7e076
3
+ metadata.gz: b2f03d7a90d220d61bbbab80806d305f49017361
4
+ data.tar.gz: fa5f44e2035bd6a9bf655040498bbdeb9b378b37
5
5
  SHA512:
6
- metadata.gz: c92d2a3dd4f552c2a9bdd27aa78732d35078baab9a2d391836d3c599371b594ff8751b547dd709aa38b45388eba25770a42fe305a6f4d690279ad64274b72e0e
7
- data.tar.gz: 33f3cc6eafb6eaec16e48205813cdc60ee99c0149773f2a5637fdadd1001e45c75d76ebb4ab58e4db1380c89638ac33d5a086e0caeb852a98ed37a380ae2a21d
6
+ metadata.gz: f34fd7c48a23702fb39115295110d3b1a1aab08f882a514cb83ad9eddcfe7a75e2d67f64a5b6414c543bd557e44c113479d64d45b47e7d010747a8559988169f
7
+ data.tar.gz: 4a68b4cab8892638444669e2ce3c3780b9df7596a0ebd9753df6f4dd1909a33f7b4ba96c90fc0027de3066da937d9b49486bcc12f43956b476d7c18c7ff3d31c
@@ -1,3 +1,9 @@
1
+ ### 0.8.0 / 2016-11-23
2
+
3
+ * Upgrade nsq-ruby to version 2.0.3
4
+ * Support passing `verify_mode` in parameters and through ENV
5
+ * Change SSLContext class to be TlsOptions class to match gem needs
6
+
1
7
  ### 0.1.0 / 2016-01-25
2
8
 
3
9
  * Initial release:
@@ -31,5 +31,5 @@ Gem::Specification.new do |gem|
31
31
  gem.add_development_dependency 'rubocop', '~> 0.39.0'
32
32
  gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
33
33
 
34
- gem.add_dependency 'nsq-ruby', '~> 1.6.0', '>= 1.6.0'
34
+ gem.add_dependency 'nsq-ruby', '~> 2.0', '>= 2.0.3'
35
35
  end
@@ -5,7 +5,7 @@ require 'fastly_nsq/listener'
5
5
  require 'fastly_nsq/message'
6
6
  require 'fastly_nsq/producer'
7
7
  require 'fastly_nsq/strategy'
8
- require 'fastly_nsq/ssl_context'
8
+ require 'fastly_nsq/tls_options'
9
9
  require 'fastly_nsq/version'
10
10
 
11
11
  module FastlyNsq
@@ -8,16 +8,16 @@ module FastlyNsq
8
8
  def_delegator :connection, :size
9
9
  def_delegator :connection, :terminate
10
10
 
11
- def initialize(topic:, channel:, ssl_context: nil, connector: nil)
11
+ def initialize(topic:, channel:, tls_options: nil, connector: nil)
12
12
  @topic = topic
13
13
  @channel = channel
14
- @ssl_context = SSLContext.new(ssl_context)
14
+ @tls_options = TlsOptions.as_hash(tls_options)
15
15
  @connector = connector
16
16
  end
17
17
 
18
18
  private
19
19
 
20
- attr_reader :channel, :topic, :ssl_context
20
+ attr_reader :channel, :topic, :tls_options
21
21
 
22
22
  def connection
23
23
  @connection ||= connector.new(params)
@@ -32,8 +32,7 @@ module FastlyNsq
32
32
  nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS').split(',').map(&:strip),
33
33
  topic: topic,
34
34
  channel: channel,
35
- ssl_context: ssl_context.to_h,
36
- }
35
+ }.merge(tls_options)
37
36
  end
38
37
  end
39
38
  end
@@ -33,7 +33,7 @@ module FastlyNsq
33
33
  end
34
34
 
35
35
  class Producer
36
- def initialize(topic:, nsqd: nil, ssl_context: nil)
36
+ def initialize(topic:, nsqd: nil, tls_v1: nil, tls_options: nil)
37
37
  end
38
38
 
39
39
  def write(string)
@@ -53,7 +53,7 @@ module FastlyNsq
53
53
  end
54
54
 
55
55
  class Consumer
56
- def initialize(nsqlookupd: nil, topic:, channel:, ssl_context: nil)
56
+ def initialize(nsqlookupd: nil, topic:, channel:, tls_v1: nil, tls_options: nil)
57
57
  end
58
58
 
59
59
  def pop(delay = FakeBackend.delay)
@@ -6,15 +6,15 @@ module FastlyNsq
6
6
  def_delegator :connection, :terminate
7
7
  def_delegator :connection, :write
8
8
 
9
- def initialize(topic:, ssl_context: nil, connector: nil)
9
+ def initialize(topic:, tls_options: nil, connector: nil)
10
10
  @topic = topic
11
- @ssl_context = SSLContext.new(ssl_context)
11
+ @tls_options = TlsOptions.as_hash(tls_options)
12
12
  @connector = connector
13
13
  end
14
14
 
15
15
  private
16
16
 
17
- attr_reader :topic, :ssl_context
17
+ attr_reader :topic, :tls_options
18
18
 
19
19
  def connection
20
20
  @connection ||= connector.new(params)
@@ -28,8 +28,7 @@ module FastlyNsq
28
28
  {
29
29
  nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
30
30
  topic: topic,
31
- ssl_context: ssl_context.to_h,
32
- }
31
+ }.merge(tls_options)
33
32
  end
34
33
  end
35
34
  end
@@ -1,15 +1,22 @@
1
1
  module FastlyNsq
2
- class SSLContext
2
+ class TlsOptions
3
+ def self.as_hash(context = nil)
4
+ new(context).to_h
5
+ end
6
+
3
7
  def initialize(context = nil)
4
8
  @context = context || {}
5
9
  end
6
10
 
7
11
  def to_h
8
12
  merge_contexts
9
- if empty_context?
10
- nil
13
+ if @context.empty?
14
+ {}
11
15
  else
12
- @context
16
+ {
17
+ tls_v1: true,
18
+ tls_options: @context,
19
+ }
13
20
  end
14
21
  end
15
22
 
@@ -27,20 +34,21 @@ module FastlyNsq
27
34
  ENV.fetch('NSQ_SSL_CA_CERTIFICATE', nil)
28
35
  end
29
36
 
37
+ def verify_mode
38
+ ENV.fetch('NSQ_SSL_VERIFY_MODE', nil)
39
+ end
40
+
30
41
  def env_default_hash
31
42
  {
32
43
  key: env_key,
33
44
  certificate: env_certificate,
34
45
  ca_certificate: env_ca_certificate,
46
+ verify_mode: verify_mode,
35
47
  }
36
48
  end
37
49
 
38
50
  def merge_contexts
39
- @context = env_default_hash.merge(@context)
40
- end
41
-
42
- def empty_context?
43
- @context.all? { |_key, value| value.nil? }
51
+ @context = env_default_hash.merge(@context).delete_if { |_, v| v.nil? }
44
52
  end
45
53
  end
46
54
  end
@@ -1,3 +1,3 @@
1
1
  module FastlyNsq
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.8.0'.freeze
3
3
  end
@@ -0,0 +1,119 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe FastlyNsq::TlsOptions do
4
+ describe 'when SSL ENV variables are not set' do
5
+ describe '.to_h' do
6
+ it 'returns nil when initialized without parameters' do
7
+ context = FastlyNsq::TlsOptions.new
8
+
9
+ expect(context.to_h).to eq({})
10
+ end
11
+
12
+ it 'returns an equivalent hash when all variables are defined' do
13
+ tls_options_hash = {
14
+ key: 'key',
15
+ certificate: 'certificate',
16
+ ca_certificate: 'ca_certificate',
17
+ }
18
+ context = FastlyNsq::TlsOptions.new(tls_options_hash)
19
+
20
+ expected_output = {
21
+ tls_v1: true,
22
+ tls_options: {
23
+ key: 'key',
24
+ certificate: 'certificate',
25
+ ca_certificate: 'ca_certificate',
26
+ },
27
+ }
28
+ expect(context.to_h).to eq(expected_output)
29
+ end
30
+
31
+ it 'does not add keys with nil values' do
32
+ tls_options_hash = {
33
+ key: 'key',
34
+ certificate: 'certificate',
35
+ }
36
+ context = FastlyNsq::TlsOptions.new(tls_options_hash)
37
+ ca_certificate = context.to_h[:ca_certificate]
38
+
39
+ expect(ca_certificate).to be_nil
40
+ end
41
+ end
42
+ end
43
+
44
+ describe 'when SSL ENV variables are set' do
45
+ before do
46
+ ENV['NSQ_SSL_KEY'] = '/some/key'
47
+ ENV['NSQ_SSL_CERTIFICATE'] = '/some/certificate'
48
+ ENV['NSQ_SSL_CA_CERTIFICATE'] = '/some/ca_certificate'
49
+ ENV['NSQ_SSL_VERIFY_MODE'] = 'value'
50
+ end
51
+
52
+ after do
53
+ ENV['NSQ_SSL_KEY'] = nil
54
+ ENV['NSQ_SSL_CERTIFICATE'] = nil
55
+ ENV['NSQ_SSL_CA_CERTIFICATE'] = nil
56
+ ENV['NSQ_SSL_VERIFY_MODE'] = nil
57
+ end
58
+
59
+ describe '.to_h' do
60
+ it 'returns a hash of the env variables when no parameters are passed' do
61
+ expected_hash = {
62
+ tls_v1: true,
63
+ tls_options: {
64
+ key: ENV['NSQ_SSL_KEY'],
65
+ certificate: ENV['NSQ_SSL_CERTIFICATE'],
66
+ ca_certificate: ENV['NSQ_SSL_CA_CERTIFICATE'],
67
+ verify_mode: ENV['NSQ_SSL_VERIFY_MODE'],
68
+ },
69
+ }
70
+ context = FastlyNsq::TlsOptions.new
71
+
72
+ expect(context.to_h).to eq(expected_hash)
73
+ end
74
+
75
+ it 'merges passed parameters and env variables' do
76
+ passed_certificate = '/passed/certificate'
77
+ expected_hash = {
78
+ tls_v1: true,
79
+ tls_options: {
80
+ key: ENV['NSQ_SSL_KEY'],
81
+ certificate: passed_certificate,
82
+ ca_certificate: ENV['NSQ_SSL_CA_CERTIFICATE'],
83
+ verify_mode: ENV['NSQ_SSL_VERIFY_MODE'],
84
+ },
85
+ }
86
+ context = FastlyNsq::TlsOptions.new(certificate: passed_certificate)
87
+
88
+ expect(context.to_h).to eq(expected_hash)
89
+ end
90
+
91
+ it 'removes keys that are nil' do
92
+ expected_hash = {
93
+ tls_v1: true,
94
+ tls_options: {
95
+ ca_certificate: ENV['NSQ_SSL_CA_CERTIFICATE'],
96
+ verify_mode: ENV['NSQ_SSL_VERIFY_MODE'],
97
+ },
98
+ }
99
+ context = FastlyNsq::TlsOptions.new(key: nil, certificate: nil)
100
+
101
+ expect(context.to_h).to eq(expected_hash)
102
+ end
103
+ end
104
+ end
105
+
106
+ describe 'as_hash' do
107
+ it 'returns an tls_options hash' do
108
+ expected_hash = {
109
+ tls_v1: true,
110
+ tls_options: {
111
+ key: 'joe',
112
+ certificate: 'biden',
113
+ },
114
+ }
115
+ output_hash = FastlyNsq::TlsOptions.as_hash(key: 'joe', certificate: 'biden')
116
+ expect(output_hash).to eq(expected_hash)
117
+ end
118
+ end
119
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastly_nsq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tommy O'Neil
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-10-26 00:00:00.000000000 Z
12
+ date: 2016-11-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: awesome_print
@@ -157,20 +157,20 @@ dependencies:
157
157
  requirements:
158
158
  - - "~>"
159
159
  - !ruby/object:Gem::Version
160
- version: 1.6.0
160
+ version: '2.0'
161
161
  - - ">="
162
162
  - !ruby/object:Gem::Version
163
- version: 1.6.0
163
+ version: 2.0.3
164
164
  type: :runtime
165
165
  prerelease: false
166
166
  version_requirements: !ruby/object:Gem::Requirement
167
167
  requirements:
168
168
  - - "~>"
169
169
  - !ruby/object:Gem::Version
170
- version: 1.6.0
170
+ version: '2.0'
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 1.6.0
173
+ version: 2.0.3
174
174
  description: Helper classes for Fastly's NSQ Services
175
175
  email: tommy@fastly.com
176
176
  executables: []
@@ -201,8 +201,8 @@ files:
201
201
  - lib/fastly_nsq/message.rb
202
202
  - lib/fastly_nsq/producer.rb
203
203
  - lib/fastly_nsq/rake_task.rb
204
- - lib/fastly_nsq/ssl_context.rb
205
204
  - lib/fastly_nsq/strategy.rb
205
+ - lib/fastly_nsq/tls_options.rb
206
206
  - lib/fastly_nsq/version.rb
207
207
  - spec/lib/fastly_nsq/consumer_spec.rb
208
208
  - spec/lib/fastly_nsq/fake_backend_spec.rb
@@ -211,8 +211,8 @@ files:
211
211
  - spec/lib/fastly_nsq/message_spec.rb
212
212
  - spec/lib/fastly_nsq/producer_spec.rb
213
213
  - spec/lib/fastly_nsq/rake_task_spec.rb
214
- - spec/lib/fastly_nsq/ssl_context_spec.rb
215
214
  - spec/lib/fastly_nsq/strategy_spec.rb
215
+ - spec/lib/fastly_nsq/tls_options_spec.rb
216
216
  - spec/lib/fastly_nsq_spec.rb
217
217
  - spec/spec_helper.rb
218
218
  - spec/support/env_helpers.rb
@@ -1,74 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe FastlyNsq::SSLContext do
4
- describe 'when SSL ENV variables are not set' do
5
- describe '.to_h' do
6
- it 'returns nil when initialized without parameters' do
7
- context = FastlyNsq::SSLContext.new
8
-
9
- expect(context.to_h).to be_nil
10
- end
11
-
12
- it 'returns an equivalent hash when all variables are defined' do
13
- ssl_context_hash = {
14
- key: 'key',
15
- certificate: 'certificate',
16
- ca_certificate: 'ca_certificate',
17
- }
18
- context = FastlyNsq::SSLContext.new(ssl_context_hash)
19
-
20
- expect(context.to_h).to eq(ssl_context_hash)
21
- end
22
-
23
- it 'does not add keys with nil values' do
24
- ssl_context_hash = {
25
- key: 'key',
26
- certificate: 'certificate',
27
- }
28
- context = FastlyNsq::SSLContext.new(ssl_context_hash)
29
- ca_certificate = context.to_h[:ca_certificate]
30
-
31
- expect(ca_certificate).to be_nil
32
- end
33
- end
34
- end
35
-
36
- describe 'when SSL ENV variables are set' do
37
- before do
38
- ENV['NSQ_SSL_KEY'] = '/some/key'
39
- ENV['NSQ_SSL_CERTIFICATE'] = '/some/certificate'
40
- ENV['NSQ_SSL_CA_CERTIFICATE'] = '/some/ca_certificate'
41
- end
42
-
43
- after do
44
- ENV['NSQ_SSL_KEY'] = nil
45
- ENV['NSQ_SSL_CERTIFICATE'] = nil
46
- ENV['NSQ_SSL_CA_CERTIFICATE'] = nil
47
- end
48
-
49
- describe '.to_h' do
50
- it 'returns a hash of the env variables when no parameters are passed' do
51
- expected_hash = {
52
- key: ENV['NSQ_SSL_KEY'],
53
- certificate: ENV['NSQ_SSL_CERTIFICATE'],
54
- ca_certificate: ENV['NSQ_SSL_CA_CERTIFICATE'],
55
- }
56
- context = FastlyNsq::SSLContext.new
57
-
58
- expect(context.to_h).to eq(expected_hash)
59
- end
60
-
61
- it 'merges passed parameters and env variables' do
62
- passed_certificate = '/passed/certificate'
63
- expected_hash = {
64
- key: ENV['NSQ_SSL_KEY'],
65
- certificate: passed_certificate,
66
- ca_certificate: ENV['NSQ_SSL_CA_CERTIFICATE'],
67
- }
68
- context = FastlyNsq::SSLContext.new(certificate: passed_certificate)
69
-
70
- expect(context.to_h).to eq(expected_hash)
71
- end
72
- end
73
- end
74
- end