ldap_tools 0.8.2 → 0.9.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8600db31c87bf3b7a5bc6c4317bda3a14a72072c
4
- data.tar.gz: c9e9f42d262b867d908fd88f46fc664a0e078f5f
3
+ metadata.gz: ea0fa0ebe1c98580e3e623f810c1b036c5002ff9
4
+ data.tar.gz: 6e56df2eb8f7caed546bfec945cb070c162d2b99
5
5
  SHA512:
6
- metadata.gz: 060fbd893561bb81c9db96196f6303d4c03235eaaf2d4757d1d68f651c77a6a98aa2573e47906f94067d51308a2864d044eb49c5b46f74dd0b1da192db0f3197
7
- data.tar.gz: a9925e2a36bf9cc30f3183f6b04a1cd399426db1f87b9a8e926f00337b09f59000d71630b2521144cdf942aaf8f7a35189fe068c53583a6ea7e1f92624d27754
6
+ metadata.gz: 98bb0f41e0ec6df27863a2d4917a28e6d24cd7d4bc7c7966e9375decf4c1b4e7c9760c9d6431127b10238593f96581a454727129329530c26f402da980fca62d
7
+ data.tar.gz: 3108815f8a5ec38c43917a7b0111f255aeb83c068d42e30dace52d59a40126586fd81edcd9a36716520f3515e1360b2acaf784db7581d9eb2921c59846444343
@@ -2,5 +2,3 @@
2
2
  require 'tapjoy/ldap'
3
3
 
4
4
  Tapjoy::LDAP::CLI.commands
5
- # Tapjoy::LDAP::API::User.create('ali', 'tayarani', 'user', 'users')
6
- # Tapjoy::LDAP::API::User.destroy('ali.tayarani', 'user')
@@ -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
@@ -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
- @ldap_info = YAML.load_file(ldap_config_file)
12
- @hosts = @ldap_info['servers']
13
- @basedn = @ldap_info['basedn']
14
- @conn = find_valid_host(ldap_password_file)
15
- @service_ou = @ldap_info['service_ou']
16
- @email_domain = @ldap_info['email_domain']
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, ldap_password_file)
142
- port = @ldap_info['port']
148
+ def ldap_connect(host)
143
149
  auth = {
144
150
  method: :simple,
145
- username: @ldap_info['rootdn'],
146
- password: File.read(ldap_password_file).chomp
151
+ username: @rootdn,
152
+ password: @ldap_password
147
153
  }
148
154
 
149
- Net::LDAP.new(host: host, port: port, base: @base, auth: auth)
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(ldap_password_file)
159
+ def find_valid_host
154
160
  @hosts.each do |host|
155
- @ldap = ldap_connect(host, ldap_password_file)
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
@@ -0,0 +1,12 @@
1
+ module Tapjoy
2
+ module LDAP
3
+ module Errors
4
+ # Raise if error LDAP_SERVERS is incorrect
5
+ class UndefinedServers < NoMethodError
6
+ def initialize
7
+ abort("FATAL: LDAP_SERVERS is undefined.")
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,7 +2,7 @@ module Tapjoy
2
2
  module LDAP
3
3
  module Version
4
4
  MAJOR = 0
5
- MINOR = 8
5
+ MINOR = 9
6
6
  PATCH = 2
7
7
  end
8
8
 
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.8.2
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: 2016-07-13 00:00:00.000000000 Z
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: