ldap_tools 0.8.2 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/ldaptools +0 -2
- data/lib/tapjoy/ldap.rb +2 -0
- data/lib/tapjoy/ldap/base.rb +49 -13
- data/lib/tapjoy/ldap/errors.rb +12 -0
- data/lib/tapjoy/ldap/version.rb +1 -1
- metadata +31 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0fa0ebe1c98580e3e623f810c1b036c5002ff9
|
4
|
+
data.tar.gz: 6e56df2eb8f7caed546bfec945cb070c162d2b99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98bb0f41e0ec6df27863a2d4917a28e6d24cd7d4bc7c7966e9375decf4c1b4e7c9760c9d6431127b10238593f96581a454727129329530c26f402da980fca62d
|
7
|
+
data.tar.gz: 3108815f8a5ec38c43917a7b0111f255aeb83c068d42e30dace52d59a40126586fd81edcd9a36716520f3515e1360b2acaf784db7581d9eb2921c59846444343
|
data/bin/ldaptools
CHANGED
data/lib/tapjoy/ldap.rb
CHANGED
@@ -2,11 +2,13 @@ require 'net/ldap'
|
|
2
2
|
require 'yaml'
|
3
3
|
require 'trollop'
|
4
4
|
require 'memoist'
|
5
|
+
require 'pry'
|
5
6
|
require_relative 'ldap/cli'
|
6
7
|
require_relative 'ldap/base'
|
7
8
|
require_relative 'ldap/key'
|
8
9
|
require_relative 'ldap/audit'
|
9
10
|
require_relative 'ldap/version'
|
11
|
+
require_relative 'ldap/errors'
|
10
12
|
|
11
13
|
|
12
14
|
module Tapjoy
|
data/lib/tapjoy/ldap/base.rb
CHANGED
@@ -8,12 +8,19 @@ module Tapjoy
|
|
8
8
|
def initialize
|
9
9
|
ldap_config_file = "#{ldap_config_directory}/ldap_info.yaml"
|
10
10
|
ldap_password_file = "#{ldap_config_directory}/ldap.secret"
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
11
|
+
|
12
|
+
begin
|
13
|
+
if can_read_files?(ldap_config_file, ldap_password_file)
|
14
|
+
load_config_from_files(ldap_config_file, ldap_password_file)
|
15
|
+
else
|
16
|
+
load_config_from_env
|
17
|
+
end
|
18
|
+
rescue => err
|
19
|
+
STDERR.puts "Error message: #{err.inspect}"
|
20
|
+
abort("Config not specified. Either provide #{ldap_config_file} and #{ldap_password_file} or environment variables")
|
21
|
+
else
|
22
|
+
@conn = find_valid_host
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
# Set LDAP Config Directory
|
@@ -138,21 +145,20 @@ module Tapjoy
|
|
138
145
|
private
|
139
146
|
|
140
147
|
# Connect to LDAP server
|
141
|
-
def ldap_connect(host
|
142
|
-
port = @ldap_info['port']
|
148
|
+
def ldap_connect(host)
|
143
149
|
auth = {
|
144
150
|
method: :simple,
|
145
|
-
username: @
|
146
|
-
password:
|
151
|
+
username: @rootdn,
|
152
|
+
password: @ldap_password
|
147
153
|
}
|
148
154
|
|
149
|
-
Net::LDAP.new(host: host, port: port, base: @
|
155
|
+
Net::LDAP.new(host: host, port: @port, base: @basedn, auth: auth)
|
150
156
|
end
|
151
157
|
|
152
158
|
# Find valid LDAP host
|
153
|
-
def find_valid_host
|
159
|
+
def find_valid_host
|
154
160
|
@hosts.each do |host|
|
155
|
-
@ldap = ldap_connect(host
|
161
|
+
@ldap = ldap_connect(host)
|
156
162
|
begin
|
157
163
|
if @ldap.bind
|
158
164
|
return @ldap
|
@@ -181,6 +187,36 @@ module Tapjoy
|
|
181
187
|
|
182
188
|
return minID, maxID
|
183
189
|
end
|
190
|
+
|
191
|
+
# Load config from files
|
192
|
+
def load_config_from_files(ldap_config_file, ldap_password_file)
|
193
|
+
ldap_info = YAML.load_file(ldap_config_file)
|
194
|
+
@rootdn = ldap_info['rootdn']
|
195
|
+
@hosts = ldap_info['servers']
|
196
|
+
@basedn = ldap_info['basedn']
|
197
|
+
@service_ou = ldap_info['service_ou']
|
198
|
+
@email_domain = ldap_info['email_domain']
|
199
|
+
@port = ldap_info['port']
|
200
|
+
@ldap_password = File.read(ldap_password_file).chomp
|
201
|
+
end
|
202
|
+
|
203
|
+
# Load config from ENV
|
204
|
+
def load_config_from_env
|
205
|
+
raise Tapjoy::LDAP::Errors::UndefinedServers if ENV['LDAP_SERVERS'].nil?
|
206
|
+
|
207
|
+
@rootdn = ENV['LDAP_BIND_DN']
|
208
|
+
@basedn = ENV['LDAP_BASE_DN']
|
209
|
+
@service_ou = ENV['LDAP_SERVICE_OU']
|
210
|
+
@email_domain = ENV['LDAP_EMAIL_DOMAIN']
|
211
|
+
@port = ENV['LDAP_PORT']
|
212
|
+
@ldap_password = ENV['LDAP_BIND_PASS']
|
213
|
+
@hosts = ENV['LDAP_SERVERS'].split(',')
|
214
|
+
end
|
215
|
+
|
216
|
+
# Check if config files are readable
|
217
|
+
def can_read_files?(ldap_config_file, ldap_password_file)
|
218
|
+
File.readable?(ldap_config_file) && File.readable?(ldap_password_file)
|
219
|
+
end
|
184
220
|
end
|
185
221
|
end
|
186
222
|
end
|
data/lib/tapjoy/ldap/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ldap_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ali Tayarani
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: trollop
|
@@ -192,6 +192,34 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '1.0'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: pry
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - ">="
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: pry-byebug
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - ">="
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0'
|
195
223
|
description: A set of tools to make managing LDAP users, groups, and keys easier
|
196
224
|
email: ali.tayarani@tapjoy.com
|
197
225
|
executables:
|
@@ -218,6 +246,7 @@ files:
|
|
218
246
|
- lib/tapjoy/ldap/cli/user/create.rb
|
219
247
|
- lib/tapjoy/ldap/cli/user/delete.rb
|
220
248
|
- lib/tapjoy/ldap/cli/user/show.rb
|
249
|
+
- lib/tapjoy/ldap/errors.rb
|
221
250
|
- lib/tapjoy/ldap/key.rb
|
222
251
|
- lib/tapjoy/ldap/key/add.rb
|
223
252
|
- lib/tapjoy/ldap/key/install.rb
|
@@ -249,4 +278,3 @@ signing_key:
|
|
249
278
|
specification_version: 4
|
250
279
|
summary: Tapjoy LDAP Tools
|
251
280
|
test_files: []
|
252
|
-
has_rdoc:
|