Commit 9f4909faadcd3aa9bf85cd2bbf5bdb0c1eecf385

Authored by Jacob Vosmaer
1 parent 038b3049

Add LDAP check to rake gitlab:check

Showing 1 changed file with 36 additions and 0 deletions   Show diff stats
lib/tasks/gitlab/check.rake
... ... @@ -3,6 +3,7 @@ namespace :gitlab do
3 3 task check: %w{gitlab:env:check
4 4 gitlab:gitlab_shell:check
5 5 gitlab:sidekiq:check
  6 + gitlab:ldap:check
6 7 gitlab:app:check}
7 8  
8 9  
... ... @@ -679,6 +680,41 @@ namespace :gitlab do
679 680 end
680 681 end
681 682  
  683 + namespace :ldap do
  684 + task check: :environment do
  685 + next unless ldap_config.enabled
  686 +
  687 + warn_user_is_not_gitlab
  688 + start_checking "LDAP"
  689 +
  690 + print_users
  691 +
  692 + finished_checking "LDAP"
  693 + end
  694 +
  695 + def print_users
  696 + puts 'The following LDAP users can log in to your GitLab server:'
  697 + ldap.search(attributes: attributes, filter: filter, return_result: false) do |entry|
  698 + puts "DN: #{entry.dn}\t#{ldap_config.uid}: #{entry[ldap_config.uid]}"
  699 + end
  700 + end
  701 +
  702 + def attributes
  703 + [ldap_config.uid]
  704 + end
  705 +
  706 + def filter
  707 + Net::LDAP::Filter.present?(ldap_config.uid)
  708 + end
  709 +
  710 + def ldap
  711 + @ldap ||= OmniAuth::LDAP::Adaptor.new(ldap_config).connection
  712 + end
  713 +
  714 + def ldap_config
  715 + @ldap_config ||= Gitlab.config.ldap
  716 + end
  717 + end
682 718  
683 719 # Helper methods
684 720 ##########################
... ...