aws-sessionstore-dynamodb 3.0.0 → 3.1.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
  SHA256:
3
- metadata.gz: 36b57007b9df541572bec17e8f0a2c5d262dec1e3d3de5e48b30fbe16ac096a4
4
- data.tar.gz: 007b5941ae32f468df86712404ac6ba0a8f833096154f1365a98cc2cd800c56b
3
+ metadata.gz: 35f83cb5e399ca623bfbd56cfccc2e3682da31acce2008bb7e93f5e5a5db7afa
4
+ data.tar.gz: 409c03019e94db3d83c7db166b26645bb07ab1a4ff24fcb2a328e4f8987df0a9
5
5
  SHA512:
6
- metadata.gz: ab11030761f3ee4fcfe4531c6739d38c829d46404f0b9d7e9586681c13f7489acbbaa53700a198b6729b60d87a4f70ab9e87e686a17481b689fedd7bcac35e01
7
- data.tar.gz: e9040852ec704e117244b747914065a9b5bf07cdad378f40a0011e1dde42c447e296183b10eb2b5f2821291d8c78b3bba6f9fb95dd4330fbfa370e9aaead4c10
6
+ metadata.gz: ca6653d948cf8e8c8858ac200d92edc01d8b9036512bc7df51523d4ecc12d48527958b117993cdc284fe6235c71bd2aab5cfcf83594c66393f75a7046c3ab47d
7
+ data.tar.gz: 6e7f1d6aeb2878e46d567a5962c1011933845b9cdb11af9585e8a5d70dda2f564134c8b1670876a4363b60668882fa60dffbbd98c10c6f8370277b54a293d3f2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ 3.1.0 (2026-06-29)
2
+ ------------------
3
+
4
+ * Feature - Add `:serializer` configuration option (`:marshal`, `:json`, `:json_allow_marshal`). Default remains `:marshal` for backwards compatibility. Set to `:json` or `:json_allow_marshal` to use JSON serialization for session data.
5
+
6
+ 3.0.1 (2024-11-16)
7
+ ------------------
8
+
9
+ * Issue - `Configuration` now takes environment variables with precedence over YAML configuration.
10
+
11
+ * Issue - Use ENV variables that are prefixed by `AWS_`.
12
+
1
13
  3.0.0 (2024-10-29)
2
14
  ------------------
3
15
 
@@ -173,30 +173,3 @@
173
173
  defend, and hold each Contributor harmless for any liability
174
174
  incurred by, or claims asserted against, such Contributor by reason
175
175
  of your accepting any such warranty or additional liability.
176
-
177
- END OF TERMS AND CONDITIONS
178
-
179
- APPENDIX: How to apply the Apache License to your work.
180
-
181
- To apply the Apache License to your work, attach the following
182
- boilerplate notice, with the fields enclosed by brackets "[]"
183
- replaced with your own identifying information. (Don't include
184
- the brackets!) The text should be enclosed in the appropriate
185
- comment syntax for the file format. We also recommend that a
186
- file or class name and description of purpose be included on the
187
- same "printed page" as the copyright notice for easier
188
- identification within third-party archives.
189
-
190
- Copyright [yyyy] [name of copyright owner]
191
-
192
- Licensed under the Apache License, Version 2.0 (the "License");
193
- you may not use this file except in compliance with the License.
194
- You may obtain a copy of the License at
195
-
196
- http://www.apache.org/licenses/LICENSE-2.0
197
-
198
- Unless required by applicable law or agreed to in writing, software
199
- distributed under the License is distributed on an "AS IS" BASIS,
200
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
- See the License for the specific language governing permissions and
202
- limitations under the License.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0
1
+ 3.1.0
@@ -4,25 +4,25 @@ require 'aws-sdk-dynamodb'
4
4
 
5
5
  module Aws::SessionStore::DynamoDB
6
6
  # This class provides a Configuration object for all DynamoDB session store operations
7
- # by pulling configuration options from Runtime, a YAML file, the ENV, and default
7
+ # by pulling configuration options from Runtime, the ENV, a YAML file, and default
8
8
  # settings, in that order.
9
9
  #
10
- # == Environment Variables
10
+ # # Environment Variables
11
11
  # The Configuration object can load default values from your environment. All configuration
12
12
  # 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:
14
14
  #
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'
17
17
  #
18
- # == Locking Strategy
18
+ # # Locking Strategy
19
19
  # By default, locking is disabled for session store access. To enable locking, set the
20
20
  # `:enable_locking` option to true. The locking strategy is pessimistic, meaning that only one
21
21
  # read can be made on a session at once. While the session is being read by the process with the
22
22
  # lock, other processes may try to obtain a lock on the same session but will be blocked.
23
23
  # See the initializer for how to configure the pessimistic locking strategy to your needs.
24
24
  #
25
- # == Handling Errors
25
+ # # Handling Errors
26
26
  # There are two configurable options for error handling: `:raise_errors` and `:error_handler`.
27
27
  #
28
28
  # If you would like to use the Default Error Handler, you can decide to set `:raise_errors`
@@ -33,12 +33,12 @@ module Aws::SessionStore::DynamoDB
33
33
  # class and pass it into the `:error_handler` option.
34
34
  # @see BaseHandler Interface for Error Handling for DynamoDB Session Store.
35
35
  #
36
- # == DynamoDB Specific Options
36
+ # # DynamoDB Specific Options
37
37
  # You may configure the table name and table hash key value of your session table with
38
38
  # the `:table_name` and `:table_key` options. You may also configure performance options for
39
39
  # your table with the `:consistent_read`, `:read_capacity`, `:write_capacity`. For more information
40
40
  # about these configurations see
41
- # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#create_table-instance_method CreateTable }
41
+ # {https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/DynamoDB/Client.html#create_table-instance_method CreateTable}
42
42
  # method for Amazon DynamoDB.
43
43
  #
44
44
  class Configuration
@@ -58,12 +58,13 @@ module Aws::SessionStore::DynamoDB
58
58
  lock_expiry_time: 500,
59
59
  lock_retry_delay: 500,
60
60
  lock_max_wait_time: 1,
61
+ serializer: :marshal,
61
62
  config_file: nil,
62
63
  dynamo_db_client: nil
63
64
  }.freeze
64
65
 
65
66
  # Provides configuration object that allows access to options defined
66
- # during Runtime, in a YAML file, in the ENV, and by default.
67
+ # during Runtime, in the ENV, in a YAML file, and by default.
67
68
  #
68
69
  # @option options [String] :table_name ("sessions") Name of the session table.
69
70
  # @option options [String] :table_key ("session_id") The hash key of the session table.
@@ -94,13 +95,26 @@ module Aws::SessionStore::DynamoDB
94
95
  # to obtain lock once an attempt to obtain the lock has been made and has failed.
95
96
  # @option options [Integer] :lock_max_wait_time (500) Maximum time in seconds to wait to acquire the
96
97
  # lock before giving up.
98
+ # @option options [Symbol] :serializer (:marshal) The serializer for session data.
99
+ # - `:json` - Serialize and deserialize with JSON only. Raises an error if legacy
100
+ # Marshal-encoded data is encountered.
101
+ # - `:json_allow_marshal` - Serialize with JSON, but fall back to deserializing with
102
+ # Marshal if JSON parsing fails. Use this during migration from Marshal to JSON.
103
+ # - `:marshal` - Serialize and deserialize with Marshal only (legacy behavior, not
104
+ # recommended).
105
+ #
106
+ # Note: When using `:json` or `:json_allow_marshal`, session data must consist of
107
+ # JSON-compatible types only (strings, numbers, booleans, arrays, hashes with string
108
+ # keys). Symbol keys are converted to strings, and complex objects (e.g., Time, custom
109
+ # classes) are not preserved across serialization.
97
110
  # @option options [String, Pathname] :config_file
98
111
  # Path to a YAML file that contains configuration options.
99
112
  # @option options [Aws::DynamoDB::Client] :dynamo_db_client (Aws::DynamoDB::Client.new)
100
113
  # DynamoDB client used to perform database operations inside of the rack application.
101
114
  def initialize(options = {})
102
- opts = file_options(options).merge(options)
115
+ opts = options
103
116
  opts = env_options.merge(opts)
117
+ opts = file_options(opts).merge(opts)
104
118
  MEMBERS.each_pair do |opt_name, default_value|
105
119
  opts[opt_name] = default_value unless opts.key?(opt_name)
106
120
  end
@@ -137,21 +151,30 @@ module Aws::SessionStore::DynamoDB
137
151
  def env_options
138
152
  unsupported_keys = %i[dynamo_db_client error_handler]
139
153
  (MEMBERS.keys - unsupported_keys).each_with_object({}) do |opt_name, opts|
140
- key = "DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
154
+ key = env_key(opt_name)
141
155
  next unless ENV.key?(key)
142
156
 
143
157
  opts[opt_name] = parse_env_value(key)
144
158
  end
145
159
  end
146
160
 
147
- def parse_env_value(key)
148
- Integer(ENV.fetch(key, nil))
149
- rescue ArgumentError
150
- if ENV[key] == 'true' || ENV[key] == 'false'
151
- ENV[key] == 'true'
161
+ def env_key(opt_name)
162
+ # legacy - remove this in aws-sessionstore-dynamodb ~> 4
163
+ key = "DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
164
+ if ENV.key?(key)
165
+ Kernel.warn("The environment variable `#{key}` is deprecated.
166
+ Please use `AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}` instead.")
152
167
  else
153
- ENV.fetch(key, nil)
168
+ key = "AWS_DYNAMO_DB_SESSION_#{opt_name.to_s.upcase}"
154
169
  end
170
+ key
171
+ end
172
+
173
+ def parse_env_value(key)
174
+ val = ENV.fetch(key, nil)
175
+ Integer(val)
176
+ rescue ArgumentError
177
+ %w[true false].include?(val) ? val == 'true' : val
155
178
  end
156
179
 
157
180
  # @return [Hash] File options.
@@ -168,7 +191,8 @@ module Aws::SessionStore::DynamoDB
168
191
  require 'erb'
169
192
  require 'yaml'
170
193
  opts = YAML.safe_load(ERB.new(File.read(file_path)).result) || {}
171
- opts.transform_keys(&:to_sym)
194
+ unsupported_keys = %i[dynamo_db_client error_handler config_file]
195
+ opts.transform_keys(&:to_sym).reject { |k, _| unsupported_keys.include?(k) }
172
196
  end
173
197
 
174
198
  def set_attributes(options)
@@ -6,7 +6,7 @@ module Aws::SessionStore::DynamoDB::Errors
6
6
  # Each error handler must implement a handle_error method.
7
7
  #
8
8
  # @example Sample ErrorHandler class
9
- # class MyErrorHandler < BaseErrorHandler
9
+ # class MyErrorHandler < BaseHandler
10
10
  # # Handles error passed in
11
11
  # def handle_error(e, env = {})
12
12
  # File.open(path_to_file, 'w') {|f| f.write(e.message) }
@@ -17,7 +17,7 @@ module Aws::SessionStore::DynamoDB::Errors
17
17
  # An error and an environment (optionally) will be passed in to
18
18
  # this method and it will determine how to deal
19
19
  # with the error.
20
- # Must return false if you have handled the error but are not reraising the
20
+ # Must return false if you have handled the error but are not re-raising the
21
21
  # error up the stack.
22
22
  # You may reraise the error passed.
23
23
  #
@@ -25,7 +25,7 @@ module Aws::SessionStore::DynamoDB::Errors
25
25
  # Aws::SessionStore::DynamoDB::RackMiddleware.
26
26
  # @param [Rack::Request::Environment,nil] env Rack environment
27
27
  # @return [false] If exception was handled and will not reraise exception.
28
- # @raise [Aws::DynamoDB::Errors] If error has be reraised.
28
+ # @raise [Aws::DynamoDB::Errors] If error has be re-raised.
29
29
  def handle_error(error, env = {})
30
30
  raise NotImplementedError
31
31
  end
@@ -20,12 +20,14 @@ module Aws::SessionStore::DynamoDB::Errors
20
20
 
21
21
  # Raises {HARD_ERRORS} up the Rack stack.
22
22
  # Places all other errors in Racks error stream.
23
+ # rubocop:disable Naming/PredicateMethod
23
24
  def handle_error(error, env = {})
24
25
  raise error if HARD_ERRORS.include?(error.class) || @raise_errors
25
26
 
26
27
  store_error(error, env)
27
28
  false
28
29
  end
30
+ # rubocop:enable Naming/PredicateMethod
29
31
 
30
32
  # Sends error to error stream
31
33
  def store_error(error, env = {})
@@ -9,6 +9,7 @@ module Aws::SessionStore::DynamoDB
9
9
  class << self
10
10
  # Scans DynamoDB session table to find sessions that match the max age and
11
11
  # max stale period requirements. it then deletes all of the found sessions.
12
+ # @option (see Configuration#initialize)
12
13
  def collect_garbage(options = {})
13
14
  config = load_config(options)
14
15
  last_key = eliminate_unwanted_sessions(config)
@@ -92,7 +93,7 @@ module Aws::SessionStore::DynamoDB
92
93
  # Provides specified date attributes.
93
94
  def oldest_date(sec)
94
95
  {
95
- attribute_value_list: [n: (Time.now - sec).to_f.to_s],
96
+ attribute_value_list: [{ n: (Time.now - sec).to_f.to_s }],
96
97
  comparison_operator: 'LT'
97
98
  }
98
99
  end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  module Aws::SessionStore::DynamoDB::Locking
4
6
  # Handles session management.
5
7
  class Base
@@ -71,13 +73,29 @@ module Aws::SessionStore::DynamoDB::Locking
71
73
  merge_all(table_opts(sid), attribute_opts)
72
74
  end
73
75
 
74
- # Marshal the data.
75
76
  def pack_data(data)
76
- [Marshal.dump(data)].pack('m*')
77
+ case @config.serializer
78
+ when :marshal
79
+ [Marshal.dump(data)].pack('m*')
80
+ else
81
+ JSON.dump(data)
82
+ end
77
83
  end
78
84
 
79
- # Unmarshal the data.
80
85
  def unpack_data(packed_data)
86
+ case @config.serializer
87
+ when :marshal
88
+ Marshal.load(packed_data.unpack1('m*'))
89
+ when :json
90
+ JSON.parse(packed_data)
91
+ when :json_allow_marshal
92
+ handle_unpack_data_fallback(packed_data)
93
+ end
94
+ end
95
+
96
+ def handle_unpack_data_fallback(packed_data)
97
+ JSON.parse(packed_data)
98
+ rescue JSON::ParserError
81
99
  Marshal.load(packed_data.unpack1('m*'))
82
100
  end
83
101
 
@@ -59,7 +59,7 @@ module Aws::SessionStore::DynamoDB::Locking
59
59
  # @return [Time] Time stamp for which the session was locked.
60
60
  def lock_time(sid)
61
61
  result = @config.dynamo_db_client.get_item(get_lock_time_opts(sid))
62
- (result[:item]['locked_at']).to_f if result[:item]['locked_at']
62
+ result[:item]['locked_at']&.to_f
63
63
  end
64
64
 
65
65
  # @return [String] Session data.
@@ -138,7 +138,7 @@ module Aws::SessionStore::DynamoDB::Locking
138
138
  {
139
139
  expected: {
140
140
  'locked_at' => {
141
- value: (env['locked_at']).to_s,
141
+ value: env['locked_at'].to_s,
142
142
  exists: true
143
143
  }
144
144
  }
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Aws::SessionStore::DynamoDB
4
+ # @api private
5
+ module Locking; end
6
+ end
7
+
8
+ require_relative 'locking/base'
9
+ require_relative 'locking/null'
10
+ require_relative 'locking/pessimistic'
@@ -12,8 +12,6 @@ end
12
12
  require_relative 'aws/session_store/dynamo_db/configuration'
13
13
  require_relative 'aws/session_store/dynamo_db/errors'
14
14
  require_relative 'aws/session_store/dynamo_db/garbage_collection'
15
- require_relative 'aws/session_store/dynamo_db/locking/base'
16
- require_relative 'aws/session_store/dynamo_db/locking/null'
17
- require_relative 'aws/session_store/dynamo_db/locking/pessimistic'
15
+ require_relative 'aws/session_store/dynamo_db/locking'
18
16
  require_relative 'aws/session_store/dynamo_db/rack_middleware'
19
17
  require_relative 'aws/session_store/dynamo_db/table'
metadata CHANGED
@@ -1,64 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sessionstore-dynamodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amazon Web Services
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: aws-sdk-dynamodb
13
+ name: rack
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.85.0
18
+ version: '3'
23
19
  type: :runtime
24
20
  prerelease: false
25
21
  version_requirements: !ruby/object:Gem::Requirement
26
22
  requirements:
27
23
  - - "~>"
28
24
  - !ruby/object:Gem::Version
29
- version: '1'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.85.0
25
+ version: '3'
33
26
  - !ruby/object:Gem::Dependency
34
- name: rack
27
+ name: rack-session
35
28
  requirement: !ruby/object:Gem::Requirement
36
29
  requirements:
37
30
  - - "~>"
38
31
  - !ruby/object:Gem::Version
39
- version: '3'
32
+ version: '2'
40
33
  type: :runtime
41
34
  prerelease: false
42
35
  version_requirements: !ruby/object:Gem::Requirement
43
36
  requirements:
44
37
  - - "~>"
45
38
  - !ruby/object:Gem::Version
46
- version: '3'
39
+ version: '2'
47
40
  - !ruby/object:Gem::Dependency
48
- name: rack-session
41
+ name: aws-sdk-dynamodb
49
42
  requirement: !ruby/object:Gem::Requirement
50
43
  requirements:
51
44
  - - "~>"
52
45
  - !ruby/object:Gem::Version
53
- version: '2'
46
+ version: '1'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.85.0
54
50
  type: :runtime
55
51
  prerelease: false
56
52
  version_requirements: !ruby/object:Gem::Requirement
57
53
  requirements:
58
54
  - - "~>"
59
55
  - !ruby/object:Gem::Version
60
- version: '2'
61
- description:
56
+ version: '1'
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: 1.85.0
60
+ description: The Amazon DynamoDB Session Store handles sessions for Rack web applications
61
+ using a DynamoDB backend.
62
62
  email:
63
63
  - aws-dr-rubygems@amazon.com
64
64
  executables: []
@@ -66,7 +66,7 @@ extensions: []
66
66
  extra_rdoc_files: []
67
67
  files:
68
68
  - CHANGELOG.md
69
- - LICENSE.txt
69
+ - LICENSE
70
70
  - VERSION
71
71
  - lib/aws-sessionstore-dynamodb.rb
72
72
  - lib/aws/session_store/dynamo_db/configuration.rb
@@ -74,6 +74,7 @@ files:
74
74
  - lib/aws/session_store/dynamo_db/errors/base_handler.rb
75
75
  - lib/aws/session_store/dynamo_db/errors/default_handler.rb
76
76
  - lib/aws/session_store/dynamo_db/garbage_collection.rb
77
+ - lib/aws/session_store/dynamo_db/locking.rb
77
78
  - lib/aws/session_store/dynamo_db/locking/base.rb
78
79
  - lib/aws/session_store/dynamo_db/locking/null.rb
79
80
  - lib/aws/session_store/dynamo_db/locking/pessimistic.rb
@@ -83,7 +84,6 @@ homepage: https://github.com/aws/aws-sessionstore-dynamodb-ruby
83
84
  licenses:
84
85
  - Apache-2.0
85
86
  metadata: {}
86
- post_install_message:
87
87
  rdoc_options: []
88
88
  require_paths:
89
89
  - lib
@@ -98,9 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0'
100
100
  requirements: []
101
- rubygems_version: 3.5.11
102
- signing_key:
101
+ rubygems_version: 4.0.3
103
102
  specification_version: 4
104
- summary: The Amazon DynamoDB Session Store handles sessions for Rack web applications
105
- using a DynamoDB backend.
103
+ summary: Amazon DynamoDB Session Store for Rack web applications.
106
104
  test_files: []