soar_ldap 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +1 -1
- data/lib/soar_ldap/version.rb +1 -1
- data/lib/soar_ldap.rb +27 -3
- data/soar_ldap.gemspec +1 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aeab37faf22561ddb7bcf9cd8396c3b2ee77e06
|
4
|
+
data.tar.gz: 6a4b2419b20f709a5bed4135359f5ea83ce33090
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29eca42f9801790ca53f6100125e1c102ccbf7a9821e437924a3b4ff6eb69086a1ffaa6045a5cb3688808d07c1d913960a5a8a6907358fbce296503345cbadd0
|
7
|
+
data.tar.gz: 6b992d84ea125fd9b46c9bca4993a3675e07265fd5d7fc5bb9d19bae7fa024d214b26c844125641344ef0c53ebc8003af2f0493085d18a3f5b6dce3618a94b1a
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -27,7 +27,7 @@ Or install it yourself as:
|
|
27
27
|
bundle exec irb
|
28
28
|
|
29
29
|
require 'soar_ldap'
|
30
|
-
configuration = { 'server' => 'my.server.com', 'port' => 389, 'node' => '
|
30
|
+
configuration = { 'server' => 'my.server.com', 'port' => 389, 'node' => 'ou=people,dc=my,dc=server,dc=com', freshness => 0 }
|
31
31
|
credentials = { 'username' => 'ldap-user', 'password' => 'ldap-password' }
|
32
32
|
@soar_ldap = SoarLdap::LdapProvider.new(configuration)
|
33
33
|
@soar_ldap.authenticate(credentials)
|
data/lib/soar_ldap/version.rb
CHANGED
data/lib/soar_ldap.rb
CHANGED
@@ -2,7 +2,8 @@ require "soar_ldap/version"
|
|
2
2
|
require 'ldap'
|
3
3
|
require 'ldap/control'
|
4
4
|
require 'soar_idm/directory_provider'
|
5
|
-
|
5
|
+
require 'persistent-cache'
|
6
|
+
require 'byebug'
|
6
7
|
|
7
8
|
module SoarLdap
|
8
9
|
class SoarLdapError < StandardError
|
@@ -17,8 +18,9 @@ module SoarLdap
|
|
17
18
|
attr_reader :username
|
18
19
|
attr_reader :password
|
19
20
|
attr_reader :connection
|
21
|
+
attr_reader :cache
|
20
22
|
|
21
|
-
def initialize(configuration)
|
23
|
+
def initialize(configuration)
|
22
24
|
bootstrap(configuration)
|
23
25
|
end
|
24
26
|
|
@@ -26,6 +28,9 @@ module SoarLdap
|
|
26
28
|
@configuration = nil
|
27
29
|
validate_configuration(configuration)
|
28
30
|
remember_configuration(configuration)
|
31
|
+
@freshness = configuration['freshness']
|
32
|
+
@freshness ||= 0
|
33
|
+
@cache = ::Persistent::Cache.new("soar_ldap", @freshness, Persistent::Cache::STORAGE_RAM)
|
29
34
|
end
|
30
35
|
|
31
36
|
def bootstrapped?
|
@@ -63,7 +68,11 @@ module SoarLdap
|
|
63
68
|
|
64
69
|
def get_entity(identifier)
|
65
70
|
connect if not connected?
|
66
|
-
|
71
|
+
cached = retrieve_from_cache(@connection, identifier)
|
72
|
+
return cached if cached
|
73
|
+
result = find_entity(@connection, identifier)
|
74
|
+
cache_result(@connection, identifier, result)
|
75
|
+
result
|
67
76
|
|
68
77
|
rescue => ex
|
69
78
|
raise SoarLdapError.new("Lookup error, #{ex}")
|
@@ -112,5 +121,20 @@ module SoarLdap
|
|
112
121
|
@username = @credentials['username']
|
113
122
|
@password = @credentials['password']
|
114
123
|
end
|
124
|
+
|
125
|
+
def retrieve_from_cache(connection, identifier)
|
126
|
+
cached_connection = @cache[connection.to_s]
|
127
|
+
if cached_connection
|
128
|
+
cached_value = @cache[connection.to_s][identifier]
|
129
|
+
return cached_value if cached_value
|
130
|
+
end
|
131
|
+
nil
|
132
|
+
end
|
133
|
+
|
134
|
+
def cache_result(connection, identifier, result)
|
135
|
+
return if @freshness == 0
|
136
|
+
@cache[connection.to_s] ||= {}
|
137
|
+
@cache[connection.to_s][identifier] = result
|
138
|
+
end
|
115
139
|
end
|
116
140
|
end
|
data/soar_ldap.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: soar_ldap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ernst van Graan
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
description: LDAP client library allowing easy acces to entries on LDAP servers
|
98
112
|
email:
|
99
113
|
- ernst.van.graan@hetzner.co.za
|