Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 03c7d90

Browse files
author
Dave Sims
committed
Added documentation; no need to create reference to search result
1 parent e3f791c commit 03c7d90

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

lib/github/ldap/forest_search.rb

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,43 @@ class Ldap
77
class ForestSearch
88
include Instrumentation
99

10+
# Build a new GitHub::Ldap::ForestSearch instance
11+
#
12+
# connection: GitHub::Ldap object representing the main AD connection.
13+
# naming_context: The Distinguished Name (DN) of this forest's Configuration
14+
# Naming Context, e.g., "CN=Configuration,DC=ad,DC=ghe,DC=com"
15+
#
16+
# See: https://technet.microsoft.com/en-us/library/aa998375(v=exchg.65).aspx
17+
#
1018
def initialize(connection, naming_context)
1119
@naming_context = naming_context
1220
@connection = connection
13-
@forest = get_domain_forest
1421
end
1522

23+
# Search over all domain controllers in the ActiveDirectory forest.
24+
#
25+
# options: options hash passed in from GitHub::Ldap#search
26+
# &block: optional block passed in from GitHub::Ldap#search
27+
#
28+
# If no domain controllers are found in the forest, fall back on searching
29+
# the main GitHub::Ldap object in @connection.
30+
#
31+
# If @forest is populated, iterate over each domain controller and perform
32+
# the requested search, excluding domain controllers whose naming context
33+
# is not in scope for the search base DN defined in options[:base].
34+
#
1635
def search(options, &block)
17-
instrument "forest_search.github_ldap" do |payload|
18-
result =
19-
if @forest.empty?
20-
@connection.search(options, &block)
21-
else
22-
@forest.each_with_object([]) do |(rootdn, server), res|
23-
if options[:base].end_with?(rootdn)
24-
rs = server.search(options, &block)
25-
res.concat Array(rs) unless rs == false
26-
end
36+
instrument "forest_search.github_ldap" do
37+
if forest.empty?
38+
@connection.search(options, &block)
39+
else
40+
forest.each_with_object([]) do |(ncname, connection), res|
41+
if options[:base].end_with?(ncname)
42+
rs = connection.search(options, &block)
43+
res.concat Array(rs) unless rs == false
2744
end
2845
end
29-
return result
46+
end
3047
end
3148
end
3249

0 commit comments

Comments
 (0)