aws-sessionstore-dynamodb 3.0.1 → 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: c47a85cf680544f7ae67c8001202f12183ef7c820ae2a08807ae577b43ab610a
4
- data.tar.gz: fe33ca1aaf6a21a3e12064290c329184ed071bde6765103c656ecbb200334d37
3
+ metadata.gz: 35f83cb5e399ca623bfbd56cfccc2e3682da31acce2008bb7e93f5e5a5db7afa
4
+ data.tar.gz: 409c03019e94db3d83c7db166b26645bb07ab1a4ff24fcb2a328e4f8987df0a9
5
5
  SHA512:
6
- metadata.gz: 525409e21cd2766373652e93bd7f5284b6e8f277a6715b06f126dcfa3286cb26882665786e4cb8c9d06c4b5bf202334b6dde66e25ddf6ba79dc1afc0ac19c165
7
- data.tar.gz: 2842691bc6bda28038e4bf93fb63672b06aba06bcbc09b7a82d1a851ab58388bd13f33b62bef804963fba73b57a0169257a875be1e57ee3fbde125084bdc8c8e
6
+ metadata.gz: ca6653d948cf8e8c8858ac200d92edc01d8b9036512bc7df51523d4ecc12d48527958b117993cdc284fe6235c71bd2aab5cfcf83594c66393f75a7046c3ab47d
7
+ data.tar.gz: 6e7f1d6aeb2878e46d567a5962c1011933845b9cdb11af9585e8a5d70dda2f564134c8b1670876a4363b60668882fa60dffbbd98c10c6f8370277b54a293d3f2
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
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
+
1
6
  3.0.1 (2024-11-16)
2
7
  ------------------
3
8
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.1.0
@@ -58,6 +58,7 @@ 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
@@ -94,6 +95,18 @@ 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)
@@ -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 = {})
@@ -93,7 +93,7 @@ module Aws::SessionStore::DynamoDB
93
93
  # Provides specified date attributes.
94
94
  def oldest_date(sec)
95
95
  {
96
- attribute_value_list: [n: (Time.now - sec).to_f.to_s],
96
+ attribute_value_list: [{ n: (Time.now - sec).to_f.to_s }],
97
97
  comparison_operator: 'LT'
98
98
  }
99
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
  }
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aws-sessionstore-dynamodb
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
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-11-16 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
13
  name: rack
@@ -85,7 +84,6 @@ homepage: https://github.com/aws/aws-sessionstore-dynamodb-ruby
85
84
  licenses:
86
85
  - Apache-2.0
87
86
  metadata: {}
88
- post_install_message:
89
87
  rdoc_options: []
90
88
  require_paths:
91
89
  - lib
@@ -100,8 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
98
  - !ruby/object:Gem::Version
101
99
  version: '0'
102
100
  requirements: []
103
- rubygems_version: 3.5.11
104
- signing_key:
101
+ rubygems_version: 4.0.3
105
102
  specification_version: 4
106
103
  summary: Amazon DynamoDB Session Store for Rack web applications.
107
104
  test_files: []