aws-sessionstore-dynamodb 2.2.0 → 3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/LICENSE +172 -9
- data/VERSION +1 -1
- data/lib/aws/session_store/dynamo_db/configuration.rb +134 -208
- data/lib/aws/session_store/dynamo_db/errors/base_handler.rb +5 -3
- data/lib/aws/session_store/dynamo_db/errors/default_handler.rb +13 -12
- data/lib/aws/session_store/dynamo_db/errors.rb +27 -0
- data/lib/aws/session_store/dynamo_db/garbage_collection.rb +85 -93
- data/lib/aws/session_store/dynamo_db/locking/base.rb +31 -32
- data/lib/aws/session_store/dynamo_db/locking/null.rb +4 -3
- data/lib/aws/session_store/dynamo_db/locking/pessimistic.rb +32 -20
- data/lib/aws/session_store/dynamo_db/locking.rb +10 -0
- data/lib/aws/session_store/dynamo_db/rack_middleware.rb +45 -49
- data/lib/aws/session_store/dynamo_db/table.rb +64 -67
- data/lib/aws-sessionstore-dynamodb.rb +12 -14
- metadata +25 -70
- data/.github/PULL_REQUEST_TEMPLATE.md +0 -6
- data/.github/workflows/ci.yml +0 -39
- data/.gitignore +0 -12
- data/.gitmodules +0 -3
- data/.yardopts +0 -4
- data/CODE_OF_CONDUCT.md +0 -4
- data/CONTRIBUTING.md +0 -61
- data/Gemfile +0 -24
- data/README.md +0 -125
- data/Rakefile +0 -35
- data/aws-sessionstore-dynamodb.gemspec +0 -24
- data/doc-src/templates/default/layout/html/footer.erb +0 -6
- data/doc-src/templates/default/layout/html/layout.erb +0 -31
- data/lib/aws/session_store/dynamo_db/invalid_id_error.rb +0 -7
- data/lib/aws/session_store/dynamo_db/lock_wait_timeout_error.rb +0 -7
- data/lib/aws/session_store/dynamo_db/missing_secret_key_error.rb +0 -7
- data/lib/aws/session_store/dynamo_db/version.rb +0 -7
- data/spec/aws/session_store/dynamo_db/app_config.yml +0 -16
- data/spec/aws/session_store/dynamo_db/configuration_spec.rb +0 -81
- data/spec/aws/session_store/dynamo_db/error/default_error_handler_spec.rb +0 -64
- data/spec/aws/session_store/dynamo_db/garbage_collection_spec.rb +0 -158
- data/spec/aws/session_store/dynamo_db/locking/threaded_sessions_spec.rb +0 -96
- data/spec/aws/session_store/dynamo_db/rack_middleware_database_spec.rb +0 -130
- data/spec/aws/session_store/dynamo_db/rack_middleware_spec.rb +0 -148
- data/spec/aws/session_store/dynamo_db/table_spec.rb +0 -48
- data/spec/spec_helper.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c47a85cf680544f7ae67c8001202f12183ef7c820ae2a08807ae577b43ab610a
|
4
|
+
data.tar.gz: fe33ca1aaf6a21a3e12064290c329184ed071bde6765103c656ecbb200334d37
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 525409e21cd2766373652e93bd7f5284b6e8f277a6715b06f126dcfa3286cb26882665786e4cb8c9d06c4b5bf202334b6dde66e25ddf6ba79dc1afc0ac19c165
|
7
|
+
data.tar.gz: 2842691bc6bda28038e4bf93fb63672b06aba06bcbc09b7a82d1a851ab58388bd13f33b62bef804963fba73b57a0169257a875be1e57ee3fbde125084bdc8c8e
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
3.0.1 (2024-11-16)
|
2
|
+
------------------
|
3
|
+
|
4
|
+
* Issue - `Configuration` now takes environment variables with precedence over YAML configuration.
|
5
|
+
|
6
|
+
* Issue - Use ENV variables that are prefixed by `AWS_`.
|
7
|
+
|
8
|
+
3.0.0 (2024-10-29)
|
9
|
+
------------------
|
10
|
+
|
11
|
+
* Feature - Uses `rack ~> 3` as the minimum.
|
12
|
+
|
13
|
+
* Feature - Drop support for Ruby 2.5 and 2.6.
|
14
|
+
|
15
|
+
* Feature - Support additional configuration options through ENV.
|
16
|
+
|
17
|
+
* Feature - Moves error classes into the `Errors` module.
|
18
|
+
|
19
|
+
* Issue - Set `RackMiddleware`'s `#find_session`, `#write_session`, and `#delete_session` as public.
|
20
|
+
|
21
|
+
* Issue - Validate `Configuration` has a secret key on `RackMiddleware#initialize` instead of on `#find_session`.
|
22
|
+
|
1
23
|
2.2.0 (2024-01-25)
|
2
24
|
------------------
|
3
25
|
|
data/LICENSE
CHANGED
@@ -1,12 +1,175 @@
|
|
1
|
-
Copyright 2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
3.0.1
|
@@ -1,264 +1,190 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'aws-sdk-dynamodb'
|
3
4
|
|
4
5
|
module Aws::SessionStore::DynamoDB
|
5
|
-
# This class provides a Configuration object for all DynamoDB
|
6
|
-
# by pulling configuration options from Runtime, a YAML file,
|
7
|
-
#
|
6
|
+
# This class provides a Configuration object for all DynamoDB session store operations
|
7
|
+
# by pulling configuration options from Runtime, the ENV, a YAML file, and default
|
8
|
+
# settings, in that order.
|
9
|
+
#
|
10
|
+
# # Environment Variables
|
11
|
+
# The Configuration object can load default values from your environment. All configuration
|
12
|
+
# keys are supported except for `:dynamo_db_client` and `:error_handler`. The keys take the form
|
13
|
+
# of AWS_DYNAMO_DB_SESSION_<KEY_NAME>. Example:
|
8
14
|
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# of setting and environment variable is below:
|
15
|
+
# export AWS_DYNAMO_DB_SESSION_TABLE_NAME='Sessions'
|
16
|
+
# export AWS_DYNAMO_DB_SESSION_TABLE_KEY='id'
|
12
17
|
#
|
13
|
-
#
|
18
|
+
# # Locking Strategy
|
19
|
+
# By default, locking is disabled for session store access. To enable locking, set the
|
20
|
+
# `:enable_locking` option to true. The locking strategy is pessimistic, meaning that only one
|
21
|
+
# read can be made on a session at once. While the session is being read by the process with the
|
22
|
+
# lock, other processes may try to obtain a lock on the same session but will be blocked.
|
23
|
+
# See the initializer for how to configure the pessimistic locking strategy to your needs.
|
14
24
|
#
|
15
|
-
#
|
16
|
-
# There are two configurable options for error handling:
|
25
|
+
# # Handling Errors
|
26
|
+
# There are two configurable options for error handling: `:raise_errors` and `:error_handler`.
|
17
27
|
#
|
18
|
-
# If you would like to use the Default Error Handler, you can decide to set
|
19
|
-
# to true or false depending on whether you want all errors,
|
28
|
+
# If you would like to use the Default Error Handler, you can decide to set `:raise_errors`
|
29
|
+
# to true or false depending on whether you want all errors, regardless of class, to be raised
|
20
30
|
# up the stack and essentially throw a 500.
|
21
31
|
#
|
22
|
-
# If you decide to use your own Error Handler
|
23
|
-
#
|
32
|
+
# If you decide to use your own Error Handler, you must implement the `BaseErrorHandler`
|
33
|
+
# class and pass it into the `:error_handler` option.
|
24
34
|
# @see BaseHandler Interface for Error Handling for DynamoDB Session Store.
|
25
35
|
#
|
26
|
-
#
|
27
|
-
# By default, locking is not implemented for the session store. You must trigger the
|
28
|
-
# locking strategy through the configuration of the session store. Pessimistic locking,
|
29
|
-
# in this case, means that only one read can be made on a session at once. While the session
|
30
|
-
# is being read by the process with the lock, other processes may try to obtain a lock on
|
31
|
-
# the same session but will be blocked. See the accessors with lock in their name for
|
32
|
-
# how to configure the pessimistic locking strategy to your needs.
|
33
|
-
#
|
34
|
-
# == DynamoDB Specific Options
|
36
|
+
# # DynamoDB Specific Options
|
35
37
|
# You may configure the table name and table hash key value of your session table with
|
36
|
-
# the
|
37
|
-
# your table with the
|
38
|
-
# about these configurations see
|
38
|
+
# the `:table_name` and `:table_key` options. You may also configure performance options for
|
39
|
+
# your table with the `:consistent_read`, `:read_capacity`, `:write_capacity`. For more information
|
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}
|
42
|
+
# method for Amazon DynamoDB.
|
39
43
|
#
|
40
44
|
class Configuration
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
:
|
49
|
-
:
|
50
|
-
|
51
|
-
|
52
|
-
:
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
56
|
-
:
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
# @return [String] Session table name.
|
62
|
-
attr_reader :table_name
|
63
|
-
|
64
|
-
# @return [String] Session table hash key name.
|
65
|
-
attr_reader :table_key
|
66
|
-
|
67
|
-
# @return [true] If a strongly consistent read is used
|
68
|
-
# @return [false] If an eventually consistent read is used.
|
69
|
-
# See AWS DynamoDB documentation for table consistent_read for more
|
70
|
-
# information on this setting.
|
71
|
-
attr_reader :consistent_read
|
72
|
-
|
73
|
-
# @return [Integer] Maximum number of reads consumed per second before
|
74
|
-
# DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
|
75
|
-
# for table read_capacity for more information on this setting.
|
76
|
-
attr_reader :read_capacity
|
77
|
-
|
78
|
-
# @return [Integer] Maximum number of writes consumed per second before
|
79
|
-
# DynamoDB returns a ThrottlingException. See AWS DynamoDB documentation
|
80
|
-
# for table write_capacity for more information on this setting.
|
81
|
-
attr_reader :write_capacity
|
82
|
-
|
83
|
-
# @return [true] All errors are raised up the stack when default ErrorHandler
|
84
|
-
# is used.
|
85
|
-
# @return [false] Only specified errors are raised up the stack when default
|
86
|
-
# ErrorHandler is used.
|
87
|
-
attr_reader :raise_errors
|
88
|
-
|
89
|
-
# @return [Integer] Maximum number of seconds earlier
|
90
|
-
# from the current time that a session was created.
|
91
|
-
attr_reader :max_age
|
92
|
-
|
93
|
-
# @return [Integer] Maximum number of seconds
|
94
|
-
# before the current time that the session was last accessed.
|
95
|
-
attr_reader :max_stale
|
96
|
-
|
97
|
-
# @return [true] Pessimistic locking strategy will be implemented for
|
98
|
-
# all session accesses.
|
99
|
-
# @return [false] No locking strategy will be implemented for
|
100
|
-
# all session accesses.
|
101
|
-
attr_reader :enable_locking
|
102
|
-
|
103
|
-
# @return [Integer] Time in milleseconds after which lock will expire.
|
104
|
-
attr_reader :lock_expiry_time
|
105
|
-
|
106
|
-
# @return [Integer] Time in milleseconds to wait before retrying to obtain
|
107
|
-
# lock once an attempt to obtain lock has been made and has failed.
|
108
|
-
attr_reader :lock_retry_delay
|
109
|
-
|
110
|
-
# @return [Integer] Maximum time in seconds to wait to acquire lock
|
111
|
-
# before giving up.
|
112
|
-
attr_reader :lock_max_wait_time
|
113
|
-
|
114
|
-
# @return [String] The secret key for HMAC encryption.
|
115
|
-
attr_reader :secret_key
|
116
|
-
|
117
|
-
# @return [String,Pathname]
|
118
|
-
attr_reader :config_file
|
119
|
-
|
120
|
-
### Client and Error Handling options
|
121
|
-
|
122
|
-
# @return [DynamoDB Client] DynamoDB client.
|
123
|
-
attr_reader :dynamo_db_client
|
124
|
-
|
125
|
-
# @return [Error Handler] An error handling object that handles all exceptions
|
126
|
-
# thrown during execution of the AWS DynamoDB Session Store Rack Middleware.
|
127
|
-
# For more information see the Handling Errors Section.
|
128
|
-
attr_reader :error_handler
|
45
|
+
# @api private
|
46
|
+
MEMBERS = {
|
47
|
+
table_name: 'sessions',
|
48
|
+
table_key: 'session_id',
|
49
|
+
secret_key: nil,
|
50
|
+
consistent_read: true,
|
51
|
+
read_capacity: 10,
|
52
|
+
write_capacity: 5,
|
53
|
+
raise_errors: false,
|
54
|
+
error_handler: nil,
|
55
|
+
max_age: nil,
|
56
|
+
max_stale: nil,
|
57
|
+
enable_locking: false,
|
58
|
+
lock_expiry_time: 500,
|
59
|
+
lock_retry_delay: 500,
|
60
|
+
lock_max_wait_time: 1,
|
61
|
+
config_file: nil,
|
62
|
+
dynamo_db_client: nil
|
63
|
+
}.freeze
|
129
64
|
|
130
65
|
# Provides configuration object that allows access to options defined
|
131
|
-
# during Runtime, in a YAML file,
|
66
|
+
# during Runtime, in the ENV, in a YAML file, and by default.
|
132
67
|
#
|
133
|
-
# @option options [String] :table_name ("
|
134
|
-
#
|
135
|
-
# @option options [String] :
|
136
|
-
#
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
#
|
142
|
-
# DynamoDB raises a ThrottlingException. See AWS DynamoDB documentation
|
143
|
-
# for table read_capacity for more information on this setting.
|
68
|
+
# @option options [String] :table_name ("sessions") Name of the session table.
|
69
|
+
# @option options [String] :table_key ("session_id") The hash key of the session table.
|
70
|
+
# @option options [String] :secret_key Secret key for HMAC encryption.
|
71
|
+
# @option options [Boolean] :consistent_read (true) If true, a strongly consistent read is used.
|
72
|
+
# If false, an eventually consistent read is used.
|
73
|
+
# @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/HowItWorks.ReadConsistency.html
|
74
|
+
# @option options [Integer] :read_capacity (10) The maximum number of strongly consistent reads
|
75
|
+
# consumed per second before DynamoDB raises a ThrottlingException.
|
76
|
+
# @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html
|
144
77
|
# @option options [Integer] :write_capacity (5) The maximum number of writes
|
145
78
|
# consumed per second before DynamoDB returns a ThrottlingException.
|
146
|
-
#
|
147
|
-
#
|
148
|
-
#
|
149
|
-
#
|
150
|
-
#
|
151
|
-
#
|
152
|
-
# raised up the stack when default ErrorHandler. If false, Only specified
|
153
|
-
# errors are raised up the stack when default ErrorHandler is used.
|
154
|
-
# @option options [Error Handler] :error_handler (DefaultErrorHandler)
|
155
|
-
# An error handling object that handles all exceptions thrown during
|
156
|
-
# execution of the AWS DynamoDB Session Store Rack Middleware.
|
157
|
-
# For more information see the Handling Errors Section.
|
79
|
+
# @see https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/read-write-operations.html
|
80
|
+
# @option options [Boolean] :raise_errors (false) If true, all errors are raised up the stack
|
81
|
+
# when default ErrorHandler. If false, Only specified errors are raised up the stack when
|
82
|
+
# the default ErrorHandler is used.
|
83
|
+
# @option options [#handle_error] :error_handler (Errors::DefaultHandler) An error handling object
|
84
|
+
# that handles all exceptions thrown during execution of the rack application.
|
158
85
|
# @option options [Integer] :max_age (nil) Maximum number of seconds earlier
|
159
86
|
# from the current time that a session was created.
|
160
87
|
# @option options [Integer] :max_stale (nil) Maximum number of seconds
|
161
88
|
# before current time that session was last accessed.
|
162
|
-
# @option options [
|
163
|
-
#
|
164
|
-
#
|
165
|
-
#
|
166
|
-
#
|
167
|
-
#
|
168
|
-
#
|
169
|
-
#
|
170
|
-
#
|
171
|
-
#
|
172
|
-
# @option options [
|
173
|
-
#
|
174
|
-
# @option options [String] :secret_key (SecureRandom.hex(64))
|
175
|
-
# Secret key for HMAC encription.
|
89
|
+
# @option options [Integer] :enable_locking (false) If true, a pessimistic locking strategy will be
|
90
|
+
# used for all session accesses.
|
91
|
+
# @option options [Integer] :lock_expiry_time (500) Time in milliseconds after which the lock
|
92
|
+
# expires on session.
|
93
|
+
# @option options [Integer] :lock_retry_delay (500) Time in milliseconds to wait before retrying
|
94
|
+
# to obtain lock once an attempt to obtain the lock has been made and has failed.
|
95
|
+
# @option options [Integer] :lock_max_wait_time (500) Maximum time in seconds to wait to acquire the
|
96
|
+
# lock before giving up.
|
97
|
+
# @option options [String, Pathname] :config_file
|
98
|
+
# Path to a YAML file that contains configuration options.
|
99
|
+
# @option options [Aws::DynamoDB::Client] :dynamo_db_client (Aws::DynamoDB::Client.new)
|
100
|
+
# DynamoDB client used to perform database operations inside of the rack application.
|
176
101
|
def initialize(options = {})
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
102
|
+
opts = options
|
103
|
+
opts = env_options.merge(opts)
|
104
|
+
opts = file_options(opts).merge(opts)
|
105
|
+
MEMBERS.each_pair do |opt_name, default_value|
|
106
|
+
opts[opt_name] = default_value unless opts.key?(opt_name)
|
107
|
+
end
|
108
|
+
opts = opts.merge(dynamo_db_client: default_dynamo_db_client(opts))
|
109
|
+
opts = opts.merge(error_handler: default_error_handler(opts)) unless opts[:error_handler]
|
110
|
+
|
111
|
+
set_attributes(opts)
|
112
|
+
end
|
113
|
+
|
114
|
+
MEMBERS.each_key do |attr_name|
|
115
|
+
attr_reader(attr_name)
|
184
116
|
end
|
185
117
|
|
186
118
|
# @return [Hash] The merged configuration hash.
|
187
119
|
def to_hash
|
188
|
-
|
120
|
+
MEMBERS.each_with_object({}) do |(key, _), hash|
|
121
|
+
hash[key] = send(key)
|
122
|
+
end
|
189
123
|
end
|
190
124
|
|
191
125
|
private
|
192
126
|
|
193
|
-
|
194
|
-
|
195
|
-
dynamo_db_client
|
196
|
-
|
197
|
-
dynamo_db_client.config.user_agent_frameworks << "aws-sessionstore-dynamodb"
|
198
|
-
{:dynamo_db_client => dynamo_db_client}
|
127
|
+
def default_dynamo_db_client(options)
|
128
|
+
dynamo_db_client = options[:dynamo_db_client] || Aws::DynamoDB::Client.new
|
129
|
+
dynamo_db_client.config.user_agent_frameworks << 'aws-sessionstore-dynamodb'
|
130
|
+
dynamo_db_client
|
199
131
|
end
|
200
132
|
|
201
|
-
|
202
|
-
|
203
|
-
default_handler = Aws::SessionStore::DynamoDB::Errors::DefaultHandler
|
204
|
-
error_handler = @options[:error_handler] ||
|
205
|
-
default_handler.new(@options[:raise_errors])
|
206
|
-
{:error_handler => error_handler}
|
133
|
+
def default_error_handler(options)
|
134
|
+
Aws::SessionStore::DynamoDB::Errors::DefaultHandler.new(options[:raise_errors])
|
207
135
|
end
|
208
136
|
|
209
|
-
# @return [Hash]
|
210
|
-
def
|
211
|
-
|
212
|
-
|
137
|
+
# @return [Hash] Environment options.
|
138
|
+
def env_options
|
139
|
+
unsupported_keys = %i[dynamo_db_client error_handler]
|
140
|
+
(MEMBERS.keys - unsupported_keys).each_with_object({}) do |opt_name, opts|
|
141
|
+
key = env_key(opt_name)
|
142
|
+
next unless ENV.key?(key)
|
213
143
|
|
214
|
-
|
215
|
-
|
216
|
-
DEFAULTS
|
144
|
+
opts[opt_name] = parse_env_value(key)
|
145
|
+
end
|
217
146
|
end
|
218
147
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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}"
|
225
156
|
end
|
157
|
+
key
|
158
|
+
end
|
159
|
+
|
160
|
+
def parse_env_value(key)
|
161
|
+
val = ENV.fetch(key, nil)
|
162
|
+
Integer(val)
|
163
|
+
rescue ArgumentError
|
164
|
+
%w[true false].include?(val) ? val == 'true' : val
|
226
165
|
end
|
227
166
|
|
228
167
|
# @return [Hash] File options.
|
229
168
|
def file_options(options = {})
|
230
|
-
|
231
|
-
|
232
|
-
load_from_file(file_path)
|
169
|
+
if options[:config_file]
|
170
|
+
load_from_file(options[:config_file])
|
233
171
|
else
|
234
172
|
{}
|
235
173
|
end
|
236
174
|
end
|
237
175
|
|
238
|
-
# Load options from YAML file
|
176
|
+
# Load options from the YAML file.
|
239
177
|
def load_from_file(file_path)
|
240
|
-
require
|
241
|
-
|
242
|
-
|
178
|
+
require 'erb'
|
179
|
+
require 'yaml'
|
180
|
+
opts = YAML.safe_load(ERB.new(File.read(file_path)).result) || {}
|
181
|
+
unsupported_keys = %i[dynamo_db_client error_handler config_file]
|
182
|
+
opts.transform_keys(&:to_sym).reject { |k, _| unsupported_keys.include?(k) }
|
243
183
|
end
|
244
184
|
|
245
|
-
# @return [String] Configuration path found in environment or YAML file.
|
246
|
-
def config_file_path(options)
|
247
|
-
options[:config_file] || ENV["DYNAMO_DB_SESSION_CONFIG_FILE"]
|
248
|
-
end
|
249
|
-
|
250
|
-
# Set accessible attributes after merged options.
|
251
185
|
def set_attributes(options)
|
252
|
-
|
253
|
-
instance_variable_set("@#{
|
254
|
-
end
|
255
|
-
end
|
256
|
-
|
257
|
-
# @return [Hash] Hash with all symbolized keys.
|
258
|
-
def symbolize_keys(options)
|
259
|
-
options.inject({}) do |opts, (opt_name, opt_value)|
|
260
|
-
opts[opt_name.to_sym] = opt_value
|
261
|
-
opts
|
186
|
+
MEMBERS.each_key do |attr_name|
|
187
|
+
instance_variable_set("@#{attr_name}", options[attr_name])
|
262
188
|
end
|
263
189
|
end
|
264
190
|
end
|