rack-redic 0.0.9
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 +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +66 -0
- data/Rakefile +3 -0
- data/bin/console +6 -0
- data/bin/setup +8 -0
- data/lib/rack/session/redic.rb +116 -0
- data/rack-redic.gemspec +17 -0
- metadata +82 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 89dbdee0222ddd8f07c8649924aca577ac8a42b1
|
4
|
+
data.tar.gz: df6c71a5eadc62632208e36295d44031fc05b32b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f676a33174d537d2b3b95385b4dc3cdc45a3f77c7906b0126163c6ee017e26364207037bbae4b4747953541c601a07315a3d83403dc2921c32ab843707ca5a14
|
7
|
+
data.tar.gz: 0fd50ee339a37fd7425ec16e4d653c9880ba71512d4f3158e50d61543349e50d3ce31d8152c87385fffae6da167a021549ae16e9f1301a42a35f986eb5414a7f
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at evan@lecklider.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Evan Lecklider
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
# Rack::Redic
|
2
|
+
|
3
|
+
Rack::Session::Redic provides simple cookie based session management.
|
4
|
+
Session data is stored in Redis via the Redic gem. The corresponding
|
5
|
+
session key is maintained in the cookie.
|
6
|
+
|
7
|
+
You may optionally supply the class/module you would like to use when
|
8
|
+
marshalling objects in and out of Redis. All that is required is that
|
9
|
+
this class respond to the `load` and `dump` methods, returning the
|
10
|
+
session hash and a string respectively.
|
11
|
+
|
12
|
+
Addtionally, you may pass in the URL for your Redis server. The default
|
13
|
+
URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku and
|
14
|
+
others' practices.
|
15
|
+
|
16
|
+
Any other options will get passed to Rack::Session::Abstract::Persisted.
|
17
|
+
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
gem 'rack-redic', require: 'rack/session/redic'
|
25
|
+
```
|
26
|
+
|
27
|
+
And then execute:
|
28
|
+
|
29
|
+
$ bundle
|
30
|
+
|
31
|
+
Or install it yourself as:
|
32
|
+
|
33
|
+
$ gem install rack-redic
|
34
|
+
|
35
|
+
|
36
|
+
## Usage
|
37
|
+
|
38
|
+
Anywhere in your Rack application just add:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
# Most basic usage.
|
42
|
+
use Rack::Session::Redic
|
43
|
+
|
44
|
+
# Optionally pass in a marshaller.
|
45
|
+
use Rack::Session::Redic, marshaller: Oj
|
46
|
+
|
47
|
+
# And/or pass in the URL of your Redis server.
|
48
|
+
use Rack::Session::Redic, marshaller: Oj, url: 'redis://host'
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
## Development
|
53
|
+
|
54
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
55
|
+
|
56
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
57
|
+
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/evanleck/rack-redic. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
62
|
+
|
63
|
+
|
64
|
+
## License
|
65
|
+
|
66
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'rack/session/abstract/id'
|
4
|
+
require 'zlib'
|
5
|
+
|
6
|
+
module Rack
|
7
|
+
module Session
|
8
|
+
#
|
9
|
+
# Rack::Session::Redic provides simple cookie based session management.
|
10
|
+
# Session data is stored in Redis via the Redic gem. The corresponding
|
11
|
+
# session key is maintained in the cookie.
|
12
|
+
#
|
13
|
+
# You may optionally supply the class/module you would like to use when
|
14
|
+
# marshalling objects in and out of Redis. All that is required is that
|
15
|
+
# this class respond to the `load` and `dump` methods, returning the
|
16
|
+
# session hash and a string respectively.
|
17
|
+
#
|
18
|
+
# Addtionally, you may pass in the URL for your Redis server. The default
|
19
|
+
# URL is fetched from the ENV as 'REDIS_URL' in keeping with Heroku and
|
20
|
+
# others' practices.
|
21
|
+
#
|
22
|
+
# Any other options will get passed to Rack::Session::Abstract::Persisted.
|
23
|
+
#
|
24
|
+
class Redic < Abstract::Persisted
|
25
|
+
def initialize(app, options = {})
|
26
|
+
super
|
27
|
+
|
28
|
+
@mutex = Mutex.new
|
29
|
+
@marshaller = options.delete(:marshaller) { Marshal }
|
30
|
+
@storage = StorageWrapper.new(@marshaller, options.delete(:url) { ENV.fetch('REDIS_URL') })
|
31
|
+
end
|
32
|
+
|
33
|
+
# Only accept a generated session ID if it doesn't exist.
|
34
|
+
def generate_sid
|
35
|
+
loop do
|
36
|
+
sid = super
|
37
|
+
break sid unless @storage.exists?(sid)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Find the session (or generate a blank one).
|
42
|
+
def find_session(req, sid)
|
43
|
+
@mutex.synchronize do
|
44
|
+
unless sid and session = @storage.get(sid)
|
45
|
+
sid, session = generate_sid, {}
|
46
|
+
@storage.set(sid, session)
|
47
|
+
end
|
48
|
+
|
49
|
+
[sid, session]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Write the session.
|
54
|
+
def write_session(req, session_id, new_session, options)
|
55
|
+
@mutex.synchronize do
|
56
|
+
@storage.set(session_id, new_session)
|
57
|
+
|
58
|
+
session_id
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
# Kill the session.
|
63
|
+
def delete_session(req, session_id, options)
|
64
|
+
@mutex.synchronize do
|
65
|
+
@storage.delete(session_id)
|
66
|
+
generate_sid unless options[:drop]
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
# Generic storage wrapper.
|
73
|
+
# Currently using Redis via Redic.
|
74
|
+
class StorageWrapper
|
75
|
+
DELETE = 'DEL'
|
76
|
+
EXISTS = 'EXISTS'
|
77
|
+
GET = 'GET'
|
78
|
+
SET = 'SET'
|
79
|
+
|
80
|
+
def initialize(marshaller, url)
|
81
|
+
@marshaller = marshaller
|
82
|
+
@storage = ::Redic.new(url)
|
83
|
+
end
|
84
|
+
|
85
|
+
def exists?(id)
|
86
|
+
@storage.call(EXISTS, id) != 0
|
87
|
+
end
|
88
|
+
|
89
|
+
def get(id)
|
90
|
+
deserialize(@storage.call(GET, id))
|
91
|
+
end
|
92
|
+
|
93
|
+
def set(id, object)
|
94
|
+
@storage.call(SET, id, serialize(object))
|
95
|
+
end
|
96
|
+
|
97
|
+
def delete(id)
|
98
|
+
@storage.call(DELETE, id)
|
99
|
+
end
|
100
|
+
|
101
|
+
private
|
102
|
+
|
103
|
+
# Should always return a string.
|
104
|
+
def serialize(object)
|
105
|
+
[Zlib::Deflate.deflate(@marshaller.dump(object))].pack('m')
|
106
|
+
end
|
107
|
+
|
108
|
+
# Should always return the session object.
|
109
|
+
def deserialize(string)
|
110
|
+
return unless string
|
111
|
+
@marshaller.load(Zlib::Inflate.inflate(string.unpack('m').first))
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/rack-redic.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rack-redic'
|
5
|
+
spec.version = '0.0.9'
|
6
|
+
spec.authors = ['Evan Lecklider']
|
7
|
+
spec.email = ['evan@lecklider.com']
|
8
|
+
|
9
|
+
spec.summary = 'Rack::Session in Redis via Redic'
|
10
|
+
spec.description = 'Rack::Session in Redis via Redic'
|
11
|
+
spec.homepage = 'https://github.com/evanleck/rack-redic'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.files = `git ls-files`.split("\n")
|
14
|
+
|
15
|
+
spec.add_dependency 'rack'
|
16
|
+
spec.add_dependency 'redic'
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rack-redic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evan Lecklider
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Rack::Session in Redis via Redic
|
42
|
+
email:
|
43
|
+
- evan@lecklider.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- CODE_OF_CONDUCT.md
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/rack/session/redic.rb
|
57
|
+
- rack-redic.gemspec
|
58
|
+
homepage: https://github.com/evanleck/rack-redic
|
59
|
+
licenses:
|
60
|
+
- MIT
|
61
|
+
metadata: {}
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubyforge_project:
|
78
|
+
rubygems_version: 2.6.4
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Rack::Session in Redis via Redic
|
82
|
+
test_files: []
|