Skip to content

Commit f2503f7

Browse files
authored
Use AWS_ prefixed environment keys (#40)
1 parent a94ff8d commit f2503f7

File tree

4 files changed

+36
-23
lines changed

4 files changed

+36
-23
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@ documentation.
4949
All Configuration options can be loaded from the environment except for
5050
`:dynamo_db_client` and `:error_handler`, which must be set in Ruby code
5151
directly if needed. The environment options must be prefixed with
52-
`DYNAMO_DB_SESSION_` and then the name of the option:
52+
`AWS_DYNAMO_DB_SESSION_` and then the name of the option:
5353

54-
DYNAMO_DB_SESSION_<name-of-option>
54+
AWS_DYNAMO_DB_SESSION_<name-of-option>
5555

5656
The example below would be a valid way to set the session table name:
5757

58-
export DYNAMO_DB_SESSION_TABLE_NAME='your-table-name'
58+
export AWS_DYNAMO_DB_SESSION_TABLE_NAME='your-table-name'
5959

6060
### YAML Configuration
6161

6262
You can create a YAML configuration file to set the options. The file must be
6363
passed into Configuration as the `:config_file` option or with the
64-
`DYNAMO_DB_SESSION_CONFIG_FILE` environment variable.
64+
`AWS_DYNAMO_DB_SESSION_CONFIG_FILE` environment variable.
6565

6666
## Creating the session table
6767

aws-sessionstore-dynamodb.gemspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ Gem::Specification.new do |spec|
1414
spec.license = 'Apache-2.0'
1515
spec.files = Dir['LICENSE', 'CHANGELOG.md', 'VERSION', 'lib/**/*']
1616

17-
# Require 1.85.0 for user_agent_frameworks config
18-
spec.add_dependency 'aws-sdk-dynamodb', '~> 1', '>= 1.85.0'
1917
spec.add_dependency 'rack', '~> 3'
2018
spec.add_dependency 'rack-session', '~> 2'
2119

20+
# Require 1.85.0 for user_agent_frameworks config
21+
spec.add_dependency 'aws-sdk-dynamodb', '~> 1', '>= 1.85.0'
22+
2223
spec.required_ruby_version = '>= 2.7'
2324
end

lib/aws/session_store/dynamo_db/configuration.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ module Aws::SessionStore::DynamoDB
1010
# == Environment Variables
1111
# The Configuration object can load default values from your environment. All configuration
1212
# keys are supported except for `:dynamo_db_client` and `:error_handler`. The keys take the form
13-
# of DYNAMO_DB_SESSION_<KEY_NAME>. Example:
13+
# of AWS_DYNAMO_DB_SESSION_<KEY_NAME>. Example:
1414
#
15-
# export DYNAMO_DB_SESSION_TABLE_NAME='Sessions'
16-
# export DYNAMO_DB_SESSION_TABLE_KEY='id'
15+
# export AWS_DYNAMO_DB_SESSION_TABLE_NAME='Sessions'
16+
# export AWS_DYNAMO_DB_SESSION_TABLE_KEY='id'
1717
#
1818
# == Locking Strategy
1919
# By default, locking is disabled for session store access. To enable locking, set the
@@ -138,13 +138,25 @@ def default_error_handler(options)
138138
def env_options
139139
unsupported_keys = %i[dynamo_db_client error_handler]
140140
(MEMBERS.keys - unsupported_keys).each_with_object({}) do |opt_name, opts|
141-
key = "DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
141+
key = env_key(opt_name)
142142
next unless ENV.key?(key)
143143

144144
opts[opt_name] = parse_env_value(key)
145145
end
146146
end
147147

148+
def env_key(opt_name)
149+
# legacy - remove this in aws-sessionstore-dynamodb ~> 4
150+
key = "DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
151+
if ENV.key?(key)
152+
Kernel.warn("The environment variable `#{key}` is deprecated.
153+
Please use `AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}` instead.")
154+
else
155+
key = "AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
156+
end
157+
key
158+
end
159+
148160
def parse_env_value(key)
149161
val = ENV.fetch(key, nil)
150162
Integer(val)

spec/aws/session_store/dynamo_db/configuration_spec.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@
2727

2828
def setup_env(options)
2929
options.each do |k, v|
30-
ENV["DYNAMO_DB_SESSION_#{k.to_s.upcase}"] = v.to_s
30+
ENV["AWS_DYNAMO_DB_SESSION_#{k.to_s.upcase}"] = v.to_s
3131
end
3232
end
3333

3434
def teardown_env(options)
35-
options.each_key { |k| ENV.delete("DYNAMO_DB_SESSION_#{k.to_s.upcase}") }
35+
options.each_key { |k| ENV.delete("AWS_DYNAMO_DB_SESSION_#{k.to_s.upcase}") }
3636
end
3737

3838
let(:client) { Aws::DynamoDB::Client.new(stub_responses: true) }
@@ -47,7 +47,7 @@ def teardown_env(options)
4747
end
4848

4949
it 'configures with YAML with precedence over defaults' do
50-
Tempfile.create('dynamo_db_session_store.yml') do |f|
50+
Tempfile.create('aws_dynamo_db_session_store.yml') do |f|
5151
f << options.transform_keys(&:to_s).to_yaml
5252
f.rewind
5353
cfg = Aws::SessionStore::DynamoDB::Configuration.new(config_file: f.path)
@@ -57,7 +57,7 @@ def teardown_env(options)
5757

5858
it 'configures with ENV with precedence over YAML' do
5959
setup_env(options)
60-
Tempfile.create('dynamo_db_session_store.yml') do |f|
60+
Tempfile.create('aws_dynamo_db_session_store.yml') do |f|
6161
f << { table_name: 'OldTable', table_key: 'OldKey' }.transform_keys(&:to_s).to_yaml
6262
f.rewind
6363
cfg = Aws::SessionStore::DynamoDB::Configuration.new(config_file: f.path)
@@ -70,7 +70,7 @@ def teardown_env(options)
7070
it 'configures in code with full precedence' do
7171
old = { table_name: 'OldTable', table_key: 'OldKey' }
7272
setup_env(options.merge(old))
73-
Tempfile.create('dynamo_db_session_store.yml') do |f|
73+
Tempfile.create('aws_dynamo_db_session_store.yml') do |f|
7474
f << old.transform_keys(&:to_s).to_yaml
7575
f.rewind
7676
cfg = Aws::SessionStore::DynamoDB::Configuration.new(options.merge(config_file: f.path))
@@ -81,29 +81,29 @@ def teardown_env(options)
8181
end
8282

8383
it 'allows for config file to be configured with ENV' do
84-
Tempfile.create('dynamo_db_session_store.yml') do |f|
84+
Tempfile.create('aws_dynamo_db_session_store.yml') do |f|
8585
f << options.transform_keys(&:to_s).to_yaml
8686
f.rewind
87-
ENV['DYNAMO_DB_SESSION_CONFIG_FILE'] = f.path
87+
ENV['AWS_DYNAMO_DB_SESSION_CONFIG_FILE'] = f.path
8888
cfg = Aws::SessionStore::DynamoDB::Configuration.new
8989
expect(cfg.to_hash).to include(options)
9090
ensure
91-
ENV.delete('DYNAMO_DB_SESSION_CONFIG_FILE')
91+
ENV.delete('AWS_DYNAMO_DB_SESSION_CONFIG_FILE')
9292
end
9393
end
9494

9595
it 'ignores unsupported keys in ENV' do
96-
ENV['DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT'] = 'Client'
97-
ENV['DYNAMO_DB_SESSION_ERROR_HANDLER'] = 'Handler'
96+
ENV['AWS_DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT'] = 'Client'
97+
ENV['AWS_DYNAMO_DB_SESSION_ERROR_HANDLER'] = 'Handler'
9898
cfg = Aws::SessionStore::DynamoDB::Configuration.new
9999
expect(cfg.to_hash).to include(defaults)
100100
ensure
101-
ENV.delete('DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT')
102-
ENV.delete('DYNAMO_DB_SESSION_ERROR_HANDLER')
101+
ENV.delete('AWS_DYNAMO_DB_SESSION_DYNAMO_DB_CLIENT')
102+
ENV.delete('AWS_DYNAMO_DB_SESSION_ERROR_HANDLER')
103103
end
104104

105105
it 'ignores unsupported keys in YAML' do
106-
Tempfile.create('dynamo_db_session_store.yml') do |f|
106+
Tempfile.create('aws_dynamo_db_session_store.yml') do |f|
107107
options = { dynamo_db_client: 'Client', error_handler: 'Handler', config_file: 'File' }
108108
f << options.transform_keys(&:to_s).to_yaml
109109
f.rewind

0 commit comments

Comments
 (0)