Skip to content

Commit

Permalink
Fix rake gitlab:ldap:check
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
  • Loading branch information
dzaporozhets committed Oct 22, 2014
1 parent a54d5dc commit 37e0985
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 31 deletions.
6 changes: 5 additions & 1 deletion lib/gitlab/ldap/adapter.rb
Expand Up @@ -22,7 +22,7 @@ def config
Gitlab::LDAP::Config.new(provider)
end

def users(field, value)
def users(field, value, limit = nil)
if field.to_sym == :dn
options = {
base: value,
Expand All @@ -45,6 +45,10 @@ def users(field, value)
end
end

if limit.present?
options.merge!(size: limit)
end

entries = ldap_search(options).select do |entry|
entry.respond_to? config.uid
end
Expand Down
40 changes: 10 additions & 30 deletions lib/tasks/gitlab/check.rake
Expand Up @@ -664,7 +664,7 @@ namespace :gitlab do
warn_user_is_not_gitlab
start_checking "LDAP"

if ldap_config.enabled
if Gitlab::LDAP::Config.enabled?
print_users(args.limit)
else
puts 'LDAP is disabled in config/gitlab.yml'
Expand All @@ -675,39 +675,19 @@ namespace :gitlab do

def print_users(limit)
puts "LDAP users with access to your GitLab server (only showing the first #{limit} results)"
ldap.search(attributes: attributes, filter: filter, size: limit, return_result: false) do |entry|
puts "DN: #{entry.dn}\t#{ldap_config.uid}: #{entry[ldap_config.uid]}"
end
end

def attributes
[ldap_config.uid]
end

def filter
uid_filter = Net::LDAP::Filter.present?(ldap_config.uid)
if user_filter
Net::LDAP::Filter.join(uid_filter, user_filter)
else
uid_filter
end
end
servers = Gitlab.config.ldap.servers.keys

def user_filter
if ldap_config['user_filter'] && ldap_config.user_filter.present?
Net::LDAP::Filter.construct(ldap_config.user_filter)
else
nil
servers.each do |server|
puts "Server: #{server}"
Gitlab::LDAP::Adapter.open("ldap#{server}") do |adapter|
users = adapter.users(adapter.config.uid, '*', 100)
users.each do |user|
puts "\tDN: #{user.dn}\t #{adapter.config.uid}: #{user.uid}"
end
end
end
end

def ldap
@ldap ||= OmniAuth::LDAP::Adaptor.new(ldap_config).connection
end

def ldap_config
@ldap_config ||= Gitlab.config.ldap
end
end

# Helper methods
Expand Down

0 comments on commit 37e0985

Please sign in to comment.