Skip to content

Commit 284e409

Browse files
authored
Improve User-Agent tracking (#31)
1 parent 51b8ea3 commit 284e409

File tree

9 files changed

+50
-9
lines changed

9 files changed

+50
-9
lines changed

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
pull_request:
9+
branches:
10+
- main
11+
12+
jobs:
13+
test:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
ruby: [2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, 3.2, jruby-9.1, jruby-9.2, jruby-9.3, jruby-9.4]
19+
20+
steps:
21+
- name: Setup
22+
uses: ruby/setup-ruby@v1
23+
with:
24+
ruby-version: ${{ matrix.ruby }}
25+
26+
- uses: actions/checkout@v2
27+
28+
- name: Install
29+
run: bundle install --without docs
30+
31+
- name: Test
32+
run: bundle exec rake spec

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ coverage
33
.yardoc
44
Gemfile.lock
55
.release
6+
.idea/

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Unreleased Changes
22
------------------
33

4+
* Issue - Improve User-Agent tracking and bump minimum DynamoDB version.
5+
46
2.0.1 (2020-11-16)
57
------------------
68

Gemfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ group :test do
1313
gem 'rspec'
1414
gem 'simplecov', require: false
1515
gem 'rack-test'
16+
17+
if RUBY_VERSION >= '3.0'
18+
gem 'rexml'
19+
end
1620
end

aws-sessionstore-dynamodb.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Gem::Specification.new do |spec|
1515
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
1616
spec.require_paths = ["lib"]
1717

18-
spec.add_dependency 'aws-sdk-dynamodb', '~> 1'
18+
# Require 1.85.0 for user_agent_frameworks config
19+
spec.add_dependency 'aws-sdk-dynamodb', '~> 1', '>= 1.85.0'
1920
spec.add_dependency 'rack', '~> 2'
2021
end

lib/aws/session_store/dynamo_db/configuration.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ def to_hash
192192

193193
# @return [Hash] DDB client.
194194
def gen_dynamo_db_client
195-
client_opts = { user_agent_suffix: " aws-sessionstore/#{VERSION}" }
196-
client = Aws::DynamoDB::Client
197-
dynamo_db_client = @options[:dynamo_db_client] || client.new(client_opts)
195+
dynamo_db_client = @options[:dynamo_db_client] || Aws::DynamoDB::Client.new
196+
# this used to be aws-sessionstore/version on user_agent_suffix
197+
dynamo_db_client.config.user_agent_frameworks << "aws-sessionstore-dynamodb"
198198
{:dynamo_db_client => dynamo_db_client}
199199
end
200200

spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
let(:base_app) { MultiplierApplication.new }
2828
let(:app) { Aws::SessionStore::DynamoDB::RackMiddleware.new(base_app, @options) }
29-
let(:client) { double('Aws::DynamoDB::Client') }
29+
let(:client) { double('Aws::DynamoDB::Client', config: double(user_agent_frameworks: [])) }
3030

3131
context 'Error handling for Rack Middleware with default error handler' do
3232
it 'raises error for missing secret key' do

spec/aws/session_store/dynamo_db/garbage_collection_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ def collect_garbage
124124
expect(dynamo_db_client).to receive(:scan).
125125
exactly(1).times.and_return(scan_resp3)
126126
expect(dynamo_db_client).to receive(:batch_write_item).ordered.
127-
with(request_items: { 'sessions' => format_scan_result }).
127+
with({request_items: { 'sessions' => format_scan_result }}).
128128
and_return(write_resp2)
129-
expect(dynamo_db_client).to receive(:batch_write_item).ordered.with(
129+
expect(dynamo_db_client).to receive(:batch_write_item).ordered.with({
130130
request_items: {
131131
'sessions' => [
132132
{
@@ -151,7 +151,7 @@ def collect_garbage
151151
}
152152
]
153153
}
154-
).and_return(write_resp1)
154+
}).and_return(write_resp1)
155155
collect_garbage
156156
end
157157
end

spec/aws/session_store/dynamo_db/rack_middleware_spec.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def ensure_data_updated(mutated_data)
5353
delete_item: 'Deleted',
5454
list_tables: { table_names: ['Sessions'] },
5555
get_item: { item: { 'data' => sample_packed_data } },
56-
update_item: { attributes: { created_at: 'now' } }
56+
update_item: { attributes: { created_at: 'now' } },
57+
config: double(user_agent_frameworks: [])
5758
)
5859
end
5960

0 commit comments

Comments
 (0)