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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: def8660c3a9aab179dcb6135d71ef1bc7b44d498
4
- data.tar.gz: 203eae89e13f58d405fc0d99fb60ba15a84f9ae7
3
+ metadata.gz: 9aeab37faf22561ddb7bcf9cd8396c3b2ee77e06
4
+ data.tar.gz: 6a4b2419b20f709a5bed4135359f5ea83ce33090
5
5
  SHA512:
6
- metadata.gz: dddbeba8a02711054d8a89324db8109dc9aa4c8be371969a00317a036c1ee6c7bf3ed0d0bad1bd18ff69d02bbed209192b36aed9afdee0310744bbe12d943a5b
7
- data.tar.gz: c329706fef6bd445f5f42fa45210bb3e5a10245f336a1baf05a59eb416d70bd68ec76b0894e54d5375bca658d2a76917bed70769ffcb9776b59d149d7d0b8c47
6
+ metadata.gz: 29eca42f9801790ca53f6100125e1c102ccbf7a9821e437924a3b4ff6eb69086a1ffaa6045a5cb3688808d07c1d913960a5a8a6907358fbce296503345cbadd0
7
+ data.tar.gz: 6b992d84ea125fd9b46c9bca4993a3675e07265fd5d7fc5bb9d19bae7fa024d214b26c844125641344ef0c53ebc8003af2f0493085d18a3f5b6dce3618a94b1a
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
  /spec/reports/
10
10
  /tmp/
11
11
  *.gem
12
+ sanity_test.rb
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' => 'dc=directory,dc=my,dc=server,dc=com', freshness => 0 }
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)
@@ -1,3 +1,3 @@
1
1
  module SoarLdap
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
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
- #require 'byebug'
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
- find_entity(@connection, identifier)
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
@@ -29,6 +29,6 @@ Gem::Specification.new do |spec|
29
29
  spec.add_development_dependency "jruby-ldap"
30
30
  else
31
31
  spec.add_development_dependency "ruby-ldap"
32
- #spec.add_development_dependency "byebug"
32
+ spec.add_development_dependency "byebug"
33
33
  end
34
34
  end
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.1
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