alephant-lookup 2.0.2 → 2.1.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: deaebe646ca7347e5bb7d2ecd027faefd36afd1f
4
- data.tar.gz: 741d490929b137b788f302deba7737f5861e6fe9
3
+ metadata.gz: a20e83924522b6a80a8042132e7fd59511a7a635
4
+ data.tar.gz: 651101ad39d0187fba1d05c5d4857ad54d7ce36d
5
5
  SHA512:
6
- metadata.gz: 273c627e6a1944afe7dfa30366d1a8030711771e9c847f701c301eb38b3c18cff39810e327acebe7c4e53cd7fb47096a7f810a87c00a1682f2fbad6521c671d3
7
- data.tar.gz: ec3d7c1f449386a622666c3f66536f1dc03dc1cee6c07baa1962679810e4f3f35608d5688c877f67b0cdaf0316e24682048d385836e0d97894444ce408dc17ba
6
+ metadata.gz: e8d9c2010e6c9b70e20690c38ab6938c0e97c42179d689be18228a776327c3a4deda6f89e1562196537d6f160833e8e8a51a5d8abd7f3a36315ba2a21c9e6439
7
+ data.tar.gz: 63124e6a099f40062775a0fbd24c72be79e587406e6d4cc6b3fcc162a66fdf0c39c0c5bf67bea3908803cd0a85e967ae8c0597049223713f37145d6911f43cca
data/.gitignore CHANGED
@@ -3,6 +3,7 @@
3
3
  Gemfile.lock
4
4
  .rspec
5
5
  *.gem
6
+ *.log
6
7
 
7
8
  /pkg
8
9
  /tmp
@@ -1 +1 @@
1
- jruby-1.7.17
1
+ 2.3.1
@@ -1,20 +1,12 @@
1
- sudo: false
2
- cache: bundler
3
1
  language: ruby
4
-
5
- # Ruby build matrix
6
2
  rvm:
7
- - 2.0
8
- - 2.1
9
- - 2.2
10
- - 2.3.0
11
- - ruby
12
- - jruby
13
-
14
- # Ensure we don't build for *every* commit (doesn't apply to PR builds)
15
- branches:
16
- only:
17
- - master
18
-
3
+ - "2.3.1"
4
+ - "jruby"
19
5
  script:
20
6
  - bundle exec rspec --format documentation
7
+ notifications:
8
+ email:
9
+ recipients:
10
+ - D&ENewsFrameworksTeam@bbc.co.uk
11
+ on_failure: change
12
+ on_success: never
@@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
7
7
  spec.name = "alephant-lookup"
8
8
  spec.version = Alephant::Lookup::VERSION
9
9
  spec.authors = ["BBC News"]
10
- spec.email = ["FutureMediaNewsRubyGems@bbc.co.uk"]
10
+ spec.email = ["D&ENewsFrameworksTeam@bbc.co.uk"]
11
11
  spec.summary = "Lookup a location in S3 using DynamoDB."
12
12
  spec.homepage = "https://github.com/BBC-News/alephant-lookup"
13
13
  spec.license = "MIT"
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "bundler", "~> 1.5"
30
30
  spec.add_development_dependency "rake"
31
31
 
32
- spec.add_runtime_dependency "aws-sdk", "~> 1.0"
32
+ spec.add_runtime_dependency "aws-sdk-dynamodb"
33
33
  spec.add_runtime_dependency "alephant-logger"
34
34
  spec.add_runtime_dependency "alephant-support"
35
35
 
@@ -9,9 +9,11 @@ module Alephant
9
9
  attr_reader :table_name, :lookup_location
10
10
 
11
11
  def initialize(table_name, component_id, opts, batch_version)
12
- @client = AWS::DynamoDB::Client::V20120810.new
13
- @table_name = table_name
14
- @lookup_location = LookupLocation.new(component_id, opts, batch_version)
12
+ options = {}
13
+ options[:endpoint] = ENV['AWS_DYNAMO_DB_ENDPOINT'] if ENV['AWS_DYNAMO_DB_ENDPOINT']
14
+ @client = Aws::DynamoDB::Client.new(options)
15
+ @table_name = table_name
16
+ @lookup_location = LookupLocation.new(component_id, opts, batch_version)
15
17
 
16
18
  logger.info(
17
19
  "event" => "LookupQueryInitialized",
@@ -40,28 +42,21 @@ module Alephant
40
42
  private
41
43
 
42
44
  def s3_location_from(result)
43
- result[:count] == 1 ? result[:member].first["location"][:s] : nil
45
+ result.count == 1 ? result.items.first['location'] : nil
44
46
  end
45
47
 
46
48
  def to_q
47
49
  {
48
50
  :table_name => table_name,
49
51
  :consistent_read => true,
50
- :select => "SPECIFIC_ATTRIBUTES",
51
- :attributes_to_get => ["location"],
52
- :key_conditions => {
53
- "component_key" => {
54
- :comparison_operator => "EQ",
55
- :attribute_value_list => [
56
- { "s" => @lookup_location.component_key }
57
- ],
58
- },
59
- "batch_version" => {
60
- :comparison_operator => "EQ",
61
- :attribute_value_list => [
62
- { "n" => @lookup_location.batch_version.to_s }
63
- ]
64
- }
52
+ :projection_expression => '#loc',
53
+ :expression_attribute_names => {
54
+ '#loc' => 'location'
55
+ },
56
+ :key_condition_expression => 'component_key = :component_key AND batch_version = :batch_version',
57
+ :expression_attribute_values => {
58
+ ':component_key' => @lookup_location.component_key,
59
+ ':batch_version' => @lookup_location.batch_version.to_i # @TODO: Verify if this is nil as this would be 0
65
60
  }
66
61
  }
67
62
  end
@@ -1,4 +1,4 @@
1
- require "aws-sdk"
1
+ require "aws-sdk-dynamodb"
2
2
  require "thread"
3
3
  require "timeout"
4
4
 
@@ -12,8 +12,10 @@ module Alephant
12
12
  attr_reader :table_name, :client
13
13
 
14
14
  def initialize(table_name)
15
+ options = {}
16
+ options.merge!({endpoint: ENV['AWS_DYNAMO_DB_ENDPOINT']}) if ENV['AWS_DYNAMO_DB_ENDPOINT']
15
17
  @mutex = Mutex.new
16
- @client = AWS::DynamoDB::Client::V20120810.new
18
+ @client = Aws::DynamoDB::Client.new(options)
17
19
  @table_name = table_name
18
20
  logger.info(
19
21
  "event" => "LookupTableInitialized",
@@ -24,17 +26,11 @@ module Alephant
24
26
 
25
27
  def write(component_key, version, location)
26
28
  client.put_item({
27
- :table_name => table_name,
28
- :item => {
29
- 'component_key' => {
30
- 'S' => component_key.to_s
31
- },
32
- 'batch_version' => {
33
- 'N' => version.to_s
34
- },
35
- 'location' => {
36
- 'S' => location.to_s
37
- }
29
+ table_name: table_name,
30
+ item: {
31
+ 'component_key' => component_key.to_s,
32
+ 'batch_version' => version,
33
+ 'location' => location.to_s
38
34
  }
39
35
  }).tap do
40
36
  logger.info(
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Lookup
3
- VERSION = "2.0.2".freeze
3
+ VERSION = "2.1.0".freeze
4
4
  end
5
5
  end
@@ -2,9 +2,9 @@ require "spec_helper"
2
2
 
3
3
  describe Alephant::Lookup do
4
4
  describe ".create" do
5
- it "returns a lookup" do
6
- expect_any_instance_of(Alephant::Lookup::LookupHelper).to receive(:initialize)
5
+ subject { Alephant::Lookup }
7
6
 
7
+ it "returns a lookup" do
8
8
  expect(subject.create(:table_name)).to be_a Alephant::Lookup::LookupHelper
9
9
  end
10
10
  end
@@ -23,44 +23,30 @@ describe Alephant::Lookup do
23
23
  describe "#read" do
24
24
  let(:expected_query) do
25
25
  {
26
- :table_name=>"table_name",
27
- :consistent_read=>true,
28
- :select=>"SPECIFIC_ATTRIBUTES",
29
- :attributes_to_get=>["location"],
30
- :key_conditions=>{
31
- "component_key"=> {
32
- :comparison_operator=>"EQ",
33
- :attribute_value_list=>[{"s"=>"id/218c835cec343537589dbf1619532e4d"}]
34
- },
35
- "batch_version"=>{
36
- :comparison_operator=>"EQ",
37
- :attribute_value_list=>[{"n"=>"0"}]
38
- }
26
+ :table_name => 'table_name',
27
+ :consistent_read => true,
28
+ :projection_expression => '#loc',
29
+ :expression_attribute_names => {
30
+ '#loc' => 'location'
31
+ },
32
+ :key_condition_expression => 'component_key = :component_key AND batch_version = :batch_version',
33
+ :expression_attribute_values => {
34
+ ':component_key' => 'id/218c835cec343537589dbf1619532e4d',
35
+ ':batch_version' => 0 # @TODO: Verify if this is nil as this would be 0
39
36
  }
40
37
  }
41
38
  end
42
39
 
43
40
  it "queries DynamoDb and returns a location when not in cache" do
44
- expect_any_instance_of(Dalli::ElastiCache).to receive(:initialize)
45
41
  expect_any_instance_of(Dalli::ElastiCache).to receive(:client).and_return(Dalli::Client.new)
46
42
 
47
43
  expect_any_instance_of(Dalli::Client).to receive(:get)
48
44
  expect_any_instance_of(Dalli::Client).to receive(:set)
49
45
 
50
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810)
51
- .to receive(:initialize)
52
-
53
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810)
46
+ expect_any_instance_of(Aws::DynamoDB::Client)
54
47
  .to receive(:query)
55
48
  .with(expected_query)
56
- .and_return(
57
- {
58
- :count => 1,
59
- :member => [
60
- { "location" => { :s => "/location" } }
61
- ]
62
- }
63
- )
49
+ .and_return(double(count: 1, items: [{ "location" => "/location"}]))
64
50
 
65
51
  table = double().as_null_object
66
52
  expect(table).to receive(:table_name).and_return("table_name").exactly(4).times
@@ -76,7 +62,6 @@ describe Alephant::Lookup do
76
62
  it "reads location from the cache when in cache" do
77
63
  lookup_location = Alephant::Lookup::LookupLocation.new("id", {:variant => "foo"}, 0, "/location")
78
64
 
79
- expect_any_instance_of(Dalli::ElastiCache).to receive(:initialize)
80
65
  expect_any_instance_of(Dalli::ElastiCache).to receive(:client).and_return(Dalli::Client.new)
81
66
 
82
67
  expect_any_instance_of(Dalli::Client).to receive(:get)
@@ -84,9 +69,7 @@ describe Alephant::Lookup do
84
69
  .and_return(lookup_location)
85
70
  expect_any_instance_of(Dalli::Client).to_not receive(:set)
86
71
 
87
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to_not receive(:initialize)
88
-
89
- expect_any_instance_of(AWS::DynamoDB::Client::V20120810).to_not receive(:query)
72
+ expect_any_instance_of(Aws::DynamoDB::Client).to_not receive(:query)
90
73
 
91
74
  table = double().as_null_object
92
75
  expect(table).to receive(:table_name).and_return("table_name").twice
@@ -5,3 +5,4 @@ require 'alephant/lookup'
5
5
  require 'crimp'
6
6
  require 'logger'
7
7
 
8
+ ENV['AWS_REGION'] = 'eu-west-1'
metadata CHANGED
@@ -1,236 +1,236 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alephant-lookup
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BBC News
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2018-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
15
  requirement: !ruby/object:Gem::Requirement
21
16
  requirements:
22
- - - '>='
17
+ - - ">="
23
18
  - !ruby/object:Gem::Version
24
19
  version: '0'
25
- prerelease: false
26
20
  type: :development
27
- - !ruby/object:Gem::Dependency
28
- name: rspec-nc
21
+ prerelease: false
29
22
  version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
- - - '>='
24
+ - - ">="
32
25
  - !ruby/object:Gem::Version
33
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec-nc
34
29
  requirement: !ruby/object:Gem::Requirement
35
30
  requirements:
36
- - - '>='
31
+ - - ">="
37
32
  - !ruby/object:Gem::Version
38
33
  version: '0'
39
- prerelease: false
40
34
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: guard
35
+ prerelease: false
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
- - - '>='
38
+ - - ">="
46
39
  - !ruby/object:Gem::Version
47
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard
48
43
  requirement: !ruby/object:Gem::Requirement
49
44
  requirements:
50
- - - '>='
45
+ - - ">="
51
46
  - !ruby/object:Gem::Version
52
47
  version: '0'
53
- prerelease: false
54
48
  type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: guard-rspec
49
+ prerelease: false
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
- - - '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
62
57
  requirement: !ruby/object:Gem::Requirement
63
58
  requirements:
64
- - - '>='
59
+ - - ">="
65
60
  - !ruby/object:Gem::Version
66
61
  version: '0'
67
- prerelease: false
68
62
  type: :development
69
- - !ruby/object:Gem::Dependency
70
- name: pry
63
+ prerelease: false
71
64
  version_requirements: !ruby/object:Gem::Requirement
72
65
  requirements:
73
- - - '>='
66
+ - - ">="
74
67
  - !ruby/object:Gem::Version
75
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
76
71
  requirement: !ruby/object:Gem::Requirement
77
72
  requirements:
78
- - - '>='
73
+ - - ">="
79
74
  - !ruby/object:Gem::Version
80
75
  version: '0'
81
- prerelease: false
82
76
  type: :development
83
- - !ruby/object:Gem::Dependency
84
- name: pry-remote
77
+ prerelease: false
85
78
  version_requirements: !ruby/object:Gem::Requirement
86
79
  requirements:
87
- - - '>='
80
+ - - ">="
88
81
  - !ruby/object:Gem::Version
89
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry-remote
90
85
  requirement: !ruby/object:Gem::Requirement
91
86
  requirements:
92
- - - '>='
87
+ - - ">="
93
88
  - !ruby/object:Gem::Version
94
89
  version: '0'
95
- prerelease: false
96
90
  type: :development
97
- - !ruby/object:Gem::Dependency
98
- name: pry-nav
91
+ prerelease: false
99
92
  version_requirements: !ruby/object:Gem::Requirement
100
93
  requirements:
101
- - - '>='
94
+ - - ">="
102
95
  - !ruby/object:Gem::Version
103
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-nav
104
99
  requirement: !ruby/object:Gem::Requirement
105
100
  requirements:
106
- - - '>='
101
+ - - ">="
107
102
  - !ruby/object:Gem::Version
108
103
  version: '0'
109
- prerelease: false
110
104
  type: :development
111
- - !ruby/object:Gem::Dependency
112
- name: listen
105
+ prerelease: false
113
106
  version_requirements: !ruby/object:Gem::Requirement
114
107
  requirements:
115
- - - <=
108
+ - - ">="
116
109
  - !ruby/object:Gem::Version
117
- version: 3.0.8
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: listen
118
113
  requirement: !ruby/object:Gem::Requirement
119
114
  requirements:
120
- - - <=
115
+ - - "<="
121
116
  - !ruby/object:Gem::Version
122
117
  version: 3.0.8
123
- prerelease: false
124
118
  type: :development
125
- - !ruby/object:Gem::Dependency
126
- name: bundler
119
+ prerelease: false
127
120
  version_requirements: !ruby/object:Gem::Requirement
128
121
  requirements:
129
- - - ~>
122
+ - - "<="
130
123
  - !ruby/object:Gem::Version
131
- version: '1.5'
124
+ version: 3.0.8
125
+ - !ruby/object:Gem::Dependency
126
+ name: bundler
132
127
  requirement: !ruby/object:Gem::Requirement
133
128
  requirements:
134
- - - ~>
129
+ - - "~>"
135
130
  - !ruby/object:Gem::Version
136
131
  version: '1.5'
137
- prerelease: false
138
132
  type: :development
139
- - !ruby/object:Gem::Dependency
140
- name: rake
133
+ prerelease: false
141
134
  version_requirements: !ruby/object:Gem::Requirement
142
135
  requirements:
143
- - - '>='
136
+ - - "~>"
144
137
  - !ruby/object:Gem::Version
145
- version: '0'
138
+ version: '1.5'
139
+ - !ruby/object:Gem::Dependency
140
+ name: rake
146
141
  requirement: !ruby/object:Gem::Requirement
147
142
  requirements:
148
- - - '>='
143
+ - - ">="
149
144
  - !ruby/object:Gem::Version
150
145
  version: '0'
151
- prerelease: false
152
146
  type: :development
153
- - !ruby/object:Gem::Dependency
154
- name: aws-sdk
147
+ prerelease: false
155
148
  version_requirements: !ruby/object:Gem::Requirement
156
149
  requirements:
157
- - - ~>
150
+ - - ">="
158
151
  - !ruby/object:Gem::Version
159
- version: '1.0'
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: aws-sdk-dynamodb
160
155
  requirement: !ruby/object:Gem::Requirement
161
156
  requirements:
162
- - - ~>
157
+ - - ">="
163
158
  - !ruby/object:Gem::Version
164
- version: '1.0'
165
- prerelease: false
159
+ version: '0'
166
160
  type: :runtime
167
- - !ruby/object:Gem::Dependency
168
- name: alephant-logger
161
+ prerelease: false
169
162
  version_requirements: !ruby/object:Gem::Requirement
170
163
  requirements:
171
- - - '>='
164
+ - - ">="
172
165
  - !ruby/object:Gem::Version
173
166
  version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: alephant-logger
174
169
  requirement: !ruby/object:Gem::Requirement
175
170
  requirements:
176
- - - '>='
171
+ - - ">="
177
172
  - !ruby/object:Gem::Version
178
173
  version: '0'
179
- prerelease: false
180
174
  type: :runtime
181
- - !ruby/object:Gem::Dependency
182
- name: alephant-support
175
+ prerelease: false
183
176
  version_requirements: !ruby/object:Gem::Requirement
184
177
  requirements:
185
- - - '>='
178
+ - - ">="
186
179
  - !ruby/object:Gem::Version
187
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: alephant-support
188
183
  requirement: !ruby/object:Gem::Requirement
189
184
  requirements:
190
- - - '>='
185
+ - - ">="
191
186
  - !ruby/object:Gem::Version
192
187
  version: '0'
193
- prerelease: false
194
188
  type: :runtime
195
- - !ruby/object:Gem::Dependency
196
- name: dalli-elasticache
189
+ prerelease: false
197
190
  version_requirements: !ruby/object:Gem::Requirement
198
191
  requirements:
199
- - - '>='
192
+ - - ">="
200
193
  - !ruby/object:Gem::Version
201
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: dalli-elasticache
202
197
  requirement: !ruby/object:Gem::Requirement
203
198
  requirements:
204
- - - '>='
199
+ - - ">="
205
200
  - !ruby/object:Gem::Version
206
201
  version: '0'
207
- prerelease: false
208
202
  type: :runtime
209
- - !ruby/object:Gem::Dependency
210
- name: crimp
203
+ prerelease: false
211
204
  version_requirements: !ruby/object:Gem::Requirement
212
205
  requirements:
213
- - - '>='
206
+ - - ">="
214
207
  - !ruby/object:Gem::Version
215
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: crimp
216
211
  requirement: !ruby/object:Gem::Requirement
217
212
  requirements:
218
- - - '>='
213
+ - - ">="
219
214
  - !ruby/object:Gem::Version
220
215
  version: '0'
221
- prerelease: false
222
216
  type: :runtime
223
- description:
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
223
+ description:
224
224
  email:
225
- - FutureMediaNewsRubyGems@bbc.co.uk
225
+ - D&ENewsFrameworksTeam@bbc.co.uk
226
226
  executables: []
227
227
  extensions: []
228
228
  extra_rdoc_files: []
229
229
  files:
230
- - .gitignore
231
- - .hound.yml
232
- - .ruby-version
233
- - .travis.yml
230
+ - ".gitignore"
231
+ - ".hound.yml"
232
+ - ".ruby-version"
233
+ - ".travis.yml"
234
234
  - Gemfile
235
235
  - Guardfile
236
236
  - LICENSE.txt
@@ -250,24 +250,24 @@ homepage: https://github.com/BBC-News/alephant-lookup
250
250
  licenses:
251
251
  - MIT
252
252
  metadata: {}
253
- post_install_message:
253
+ post_install_message:
254
254
  rdoc_options: []
255
255
  require_paths:
256
256
  - lib
257
257
  required_ruby_version: !ruby/object:Gem::Requirement
258
258
  requirements:
259
- - - '>='
259
+ - - ">="
260
260
  - !ruby/object:Gem::Version
261
261
  version: '0'
262
262
  required_rubygems_version: !ruby/object:Gem::Requirement
263
263
  requirements:
264
- - - '>='
264
+ - - ">="
265
265
  - !ruby/object:Gem::Version
266
266
  version: '0'
267
267
  requirements: []
268
- rubyforge_project:
269
- rubygems_version: 2.1.9
270
- signing_key:
268
+ rubyforge_project:
269
+ rubygems_version: 2.6.12
270
+ signing_key:
271
271
  specification_version: 4
272
272
  summary: Lookup a location in S3 using DynamoDB.
273
273
  test_files: