fastly_nsq 0.3.1 → 0.4.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: 950954fc2bf0edcea6b24e7c364003e49c9e63e4
4
- data.tar.gz: c38bb4c70dc6f506f6c9a34f69bde87f52c5ca81
3
+ metadata.gz: 7d55c09a395246d423966f21f8dc1d7ee1b29da7
4
+ data.tar.gz: d1499d0fee9093424f9134137e80637f0459c490
5
5
  SHA512:
6
- metadata.gz: da7ead45aae0e4f3d60ce118f72caff6f5c3aa51906a22de672a76e232a18803d9ee1a63c9f2e362710239a611ba302ad63bf398414136921b7f6441e4031e50
7
- data.tar.gz: 2fef46fb498b71900ad877ccfcd614f9e1b8dafc2efd48e8cbfef0cd4e438ae831299142c26036f6336f8ecaf4c77feeffe62663a526036bdac4a25fb499c583
6
+ metadata.gz: 646415b3b22eca19dc1cf8882ec7dde9187baee661f802fa73703ef74638ee38c45561489aa747380d48e9357b83a20286c4d29d581b58700dd42848370bf653
7
+ data.tar.gz: 3549a0dfd59543708a28185358d36cd48a5880eb2695b1b0a99408822267b31139a2700e90964547d179386244d9184e3628f6de0df504665aafe2a0c6d21f12
data/fastly_nsq.gemspec CHANGED
@@ -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.5.0', '>= 1.5.0'
34
+ gem.add_dependency 'nsq-ruby', '~> 1.6.0', '>= 1.6.0'
35
35
  end
@@ -22,7 +22,7 @@ module FakeMessageQueue
22
22
  end
23
23
 
24
24
  class Producer
25
- def initialize(nsqd:, topic:)
25
+ def initialize(nsqd:, topic:, ssl_context: nil)
26
26
  end
27
27
 
28
28
  def write(string)
@@ -44,7 +44,7 @@ module FakeMessageQueue
44
44
  class Consumer
45
45
  SECONDS_BETWEEN_QUEUE_CHECKS = 0.5
46
46
 
47
- def initialize(nsqlookupd:, topic:, channel:)
47
+ def initialize(nsqlookupd:, topic:, channel:, ssl_context: nil)
48
48
  end
49
49
 
50
50
  def pop
@@ -4,6 +4,7 @@ require_relative 'message_queue/listener'
4
4
  require_relative 'message_queue/producer'
5
5
  require_relative 'message_queue/consumer'
6
6
  require_relative 'message_queue/strategy'
7
+ require_relative 'ssl_context'
7
8
 
8
9
  module MessageQueue
9
10
  FALSY_VALUES = [false, 0, '0', 'false', 'FALSE', 'off', 'OFF', nil].freeze
@@ -2,9 +2,10 @@ class InvalidParameterError < StandardError; end
2
2
 
3
3
  module MessageQueue
4
4
  class Consumer
5
- def initialize(topic:, channel:)
5
+ def initialize(topic:, channel:, ssl_context: nil)
6
6
  @topic = topic
7
7
  @channel = channel
8
+ @ssl_context = SSLContext.new(ssl_context)
8
9
  end
9
10
 
10
11
  def connection
@@ -17,7 +18,7 @@ module MessageQueue
17
18
 
18
19
  private
19
20
 
20
- attr_reader :channel, :topic
21
+ attr_reader :channel, :topic, :ssl_context
21
22
 
22
23
  def consumer
23
24
  Strategy.for_queue::Consumer
@@ -28,6 +29,7 @@ module MessageQueue
28
29
  nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
29
30
  topic: topic,
30
31
  channel: channel,
32
+ ssl_context: ssl_context.to_h,
31
33
  }
32
34
  end
33
35
  end
@@ -2,8 +2,9 @@ class InvalidParameterError < StandardError; end
2
2
 
3
3
  module MessageQueue
4
4
  class Producer
5
- def initialize(topic:)
5
+ def initialize(topic:, ssl_context: nil)
6
6
  @topic = topic
7
+ @ssl_context = SSLContext.new(ssl_context)
7
8
  end
8
9
 
9
10
  def connection
@@ -16,7 +17,7 @@ module MessageQueue
16
17
 
17
18
  private
18
19
 
19
- attr_reader :topic
20
+ attr_reader :topic, :ssl_context
20
21
 
21
22
  def producer
22
23
  Strategy.for_queue::Producer
@@ -26,6 +27,7 @@ module MessageQueue
26
27
  {
27
28
  nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
28
29
  topic: topic,
30
+ ssl_context: ssl_context.to_h,
29
31
  }
30
32
  end
31
33
  end
@@ -0,0 +1,44 @@
1
+ class SSLContext
2
+ def initialize(context = nil)
3
+ @context = context || {}
4
+ end
5
+
6
+ def to_h
7
+ merge_contexts
8
+ if empty_context?
9
+ nil
10
+ else
11
+ @context
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def env_key
18
+ ENV.fetch('NSQ_SSL_KEY', nil)
19
+ end
20
+
21
+ def env_certificate
22
+ ENV.fetch('NSQ_SSL_CERTIFICATE', nil)
23
+ end
24
+
25
+ def env_ca_certificate
26
+ ENV.fetch('NSQ_SSL_CA_CERTIFICATE', nil)
27
+ end
28
+
29
+ def env_default_hash
30
+ {
31
+ key: env_key,
32
+ certificate: env_certificate,
33
+ ca_certificate: env_ca_certificate,
34
+ }
35
+ end
36
+
37
+ def merge_contexts
38
+ @context = env_default_hash.merge(@context)
39
+ end
40
+
41
+ def empty_context?
42
+ @context.all? { |_key, value| value.nil? }
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module FastlyNsq
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
@@ -15,6 +15,7 @@ RSpec.describe MessageQueue::Consumer do
15
15
  nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
16
16
  topic: topic,
17
17
  channel: channel,
18
+ ssl_context: nil,
18
19
  ).at_least(:once)
19
20
  end
20
21
  end
@@ -32,6 +33,7 @@ RSpec.describe MessageQueue::Consumer do
32
33
  nsqlookupd: ENV.fetch('NSQLOOKUPD_HTTP_ADDRESS'),
33
34
  topic: topic,
34
35
  channel: channel,
36
+ ssl_context: nil,
35
37
  ).at_least(:once)
36
38
  end
37
39
  end
@@ -13,6 +13,7 @@ RSpec.describe MessageQueue::Producer do
13
13
  with(
14
14
  nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
15
15
  topic: topic,
16
+ ssl_context: nil,
16
17
  ).at_least(:once)
17
18
  end
18
19
  end
@@ -28,6 +29,7 @@ RSpec.describe MessageQueue::Producer do
28
29
  with(
29
30
  nsqd: ENV.fetch('NSQD_TCP_ADDRESS'),
30
31
  topic: topic,
32
+ ssl_context: nil,
31
33
  ).at_least(:once)
32
34
  end
33
35
  end
@@ -0,0 +1,74 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe 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 = 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 = 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 = 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 = 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 = SSLContext.new(certificate: passed_certificate)
69
+
70
+ expect(context.to_h).to eq(expected_hash)
71
+ end
72
+ end
73
+ end
74
+ 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.3.1
4
+ version: 0.4.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-03-29 00:00:00.000000000 Z
12
+ date: 2016-04-21 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.5.0
160
+ version: 1.6.0
161
161
  - - ">="
162
162
  - !ruby/object:Gem::Version
163
- version: 1.5.0
163
+ version: 1.6.0
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.5.0
170
+ version: 1.6.0
171
171
  - - ">="
172
172
  - !ruby/object:Gem::Version
173
- version: 1.5.0
173
+ version: 1.6.0
174
174
  description: Helper classes for Fastly's NSQ Services
175
175
  email: tommy@fastly.com
176
176
  executables: []
@@ -203,6 +203,7 @@ files:
203
203
  - lib/fastly_nsq/message_queue/strategy.rb
204
204
  - lib/fastly_nsq/rake_task.rb
205
205
  - lib/fastly_nsq/sample_message_processor.rb
206
+ - lib/fastly_nsq/ssl_context.rb
206
207
  - lib/fastly_nsq/version.rb
207
208
  - spec/lib/fastly_nsq/fake_message_queue_spec.rb
208
209
  - spec/lib/fastly_nsq/fastly_nsq_spec.rb
@@ -213,6 +214,7 @@ files:
213
214
  - spec/lib/fastly_nsq/message_queue_spec.rb
214
215
  - spec/lib/fastly_nsq/rake_task_spec.rb
215
216
  - spec/lib/fastly_nsq/sample_message_processor_spec.rb
217
+ - spec/lib/fastly_nsq/ssl_context_spec.rb
216
218
  - spec/spec_helper.rb
217
219
  - spec/support/env_helpers.rb
218
220
  homepage: https://github.com/fastly/fastly-nsq