redis_connection_ssl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/redis/connection/ssl.rb +65 -0
- data/lib/redis_connection_ssl.rb +1 -0
- metadata +95 -0
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'redis/connection/ruby'
|
2
|
+
require 'openssl'
|
3
|
+
|
4
|
+
class Redis::Connection::SSL < Redis::Connection::Ruby
|
5
|
+
|
6
|
+
# ::OpenSSL::SSL::SSLSocket doesn't raise Errno::EWOULDBLOCK
|
7
|
+
# Helper to catch blocks
|
8
|
+
def self.retry_on_would_block(sock, timeout)
|
9
|
+
yield
|
10
|
+
rescue ::OpenSSL::SSL::SSLError => e
|
11
|
+
if e.message !~ /would block/
|
12
|
+
raise
|
13
|
+
elsif IO.select([sock], nil, nil, timeout)
|
14
|
+
retry
|
15
|
+
else
|
16
|
+
raise Redis::TimeoutError
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Socket class
|
21
|
+
class Socket < ::OpenSSL::SSL::SSLSocket
|
22
|
+
include Redis::Connection::SocketMixin
|
23
|
+
|
24
|
+
# Override, catch SSL blocks
|
25
|
+
def _read_from_socket(*)
|
26
|
+
Redis::Connection::SSL.retry_on_would_block(self, @timeout) { super }
|
27
|
+
end
|
28
|
+
|
29
|
+
# Socket.connect
|
30
|
+
def self.connect(host, port, timeout)
|
31
|
+
tcp = ::TCPSocket.new(host, port)
|
32
|
+
tcp.setsockopt ::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1
|
33
|
+
|
34
|
+
ssl = new(tcp)
|
35
|
+
begin
|
36
|
+
ssl.connect
|
37
|
+
rescue Errno::EINPROGRESS
|
38
|
+
if IO.select(nil, [ssl], nil, timeout) == nil
|
39
|
+
raise Redis::TimeoutError
|
40
|
+
end
|
41
|
+
|
42
|
+
begin
|
43
|
+
ssl.connect
|
44
|
+
rescue Errno::EISCONN
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ssl
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
# Connect method
|
54
|
+
def self.connect(config)
|
55
|
+
return super unless config[:scheme] == "redis+ssl"
|
56
|
+
|
57
|
+
sock = self::Socket.connect(config[:host], config[:port], config[:timeout])
|
58
|
+
instance = new(sock)
|
59
|
+
instance.timeout = config[:timeout]
|
60
|
+
instance
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
Redis::Connection.drivers << Redis::Connection::SSL
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'redis/connection/ssl'
|
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: redis_connection_ssl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Black Square Media Ltd
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redis
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Connect to Redis via SSL sockets
|
63
|
+
email: info@blacksquaremedia.com
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- lib/redis/connection/ssl.rb
|
69
|
+
- lib/redis_connection_ssl.rb
|
70
|
+
homepage: https://github.com/bsm/redis-connection-ssl
|
71
|
+
licenses: []
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options: []
|
74
|
+
require_paths:
|
75
|
+
- lib
|
76
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ! '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.0
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 1.3.6
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 1.8.24
|
91
|
+
signing_key:
|
92
|
+
specification_version: 3
|
93
|
+
summary: Secure Redis Connections
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|