Commit 41a3c84e authored by Jacob Vosmaer's avatar Jacob Vosmaer

Add logging code for LDAP keys

parent 526959ab
......@@ -63,13 +63,20 @@ module Gitlab
ldap_user = Gitlab::LDAP::Person.find_by_dn(user.extern_uid)
user.keys.ldap.where.not(key: ldap_user.ssh_keys).each do |deleted_key|
deleted_key.destroy
Rails.logger.info "#{self.class.name}: removing LDAP SSH key #{deleted_key.key} from #{user.name} (#{user.id})"
unless deleted_key.destroy
Rails.logger.error "#{self.class.name}: failed to remove LDAP SSH key #{key.inspect} from #{user.name} (#{user.id})"
end
end
(ldap_user.ssh_keys - user.keys.ldap.pluck(:key)).each do |key|
Rails.logger.info "#{self.class.name}: adding LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})"
new_key = LDAPKey.new(title: "LDAP - #{Gitlab.config.ldap['sync_ssh_keys']}", key: key)
new_key.user = user
new_key.save
unless new_key.save
Rails.logger.error "#{self.class.name}: failed to add LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})\n"\
"error messages: #{new_key.errors.messages}"
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment