Commit a05820b8 authored by Rajendra Kadam's avatar Rajendra Kadam Committed by Peter Leitzen

Use applogger in update_mirror_worker, access.rb and group.rb

parent 3aefe1d1
---
title: Use applogger in group.rb, access.rb and repo update mirror worker
merge_request: 41049
author: Rajendra Kadam
type: other
......@@ -37,33 +37,30 @@ class RepositoryUpdateMirrorWorker # rubocop:disable Scalability/IdempotentWorke
private
# rubocop:disable Gitlab/RailsLogger
def start_mirror(project)
import_state = project.import_state
if start(import_state)
Rails.logger.info("Mirror update for #{project.full_path} started. Waiting duration: #{import_state.mirror_waiting_duration}")
Gitlab::AppLogger.info("Mirror update for #{project.full_path} started. Waiting duration: #{import_state.mirror_waiting_duration}")
metric_mirror_waiting_duration_seconds.observe({}, import_state.mirror_waiting_duration)
true
else
Rails.logger.info("Project #{project.full_path} was in inconsistent state: #{import_state.status}")
Gitlab::AppLogger.info("Project #{project.full_path} was in inconsistent state: #{import_state.status}")
false
end
end
# rubocop:enable Gitlab/RailsLogger
def fail_mirror(project, message)
project.import_state.mark_as_failed(message)
Rails.logger.error("Mirror update for #{project.full_path} failed with the following message: #{message}") # rubocop:disable Gitlab/RailsLogger
Gitlab::AppLogger.error("Mirror update for #{project.full_path} failed with the following message: #{message}")
end
def finish_mirror(project)
import_state = project.import_state
import_state.finish
Rails.logger.info("Mirror update for #{project.full_path} successfully finished. Update duration: #{import_state.mirror_update_duration}}.") # rubocop:disable Gitlab/RailsLogger
Gitlab::AppLogger.info("Mirror update for #{project.full_path} successfully finished. Update duration: #{import_state.mirror_update_duration}}.")
metric_mirror_update_duration_seconds.observe({}, import_state.mirror_update_duration)
end
......
......@@ -43,12 +43,12 @@ module EE
keys = ldap_user.ssh_keys - user.keys.ldap.pluck(:key)
keys.each do |key|
::Rails.logger.info "#{self.class.name}: adding LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})"
::Gitlab::AppLogger.info "#{self.class.name}: adding LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})"
new_key = ::LDAPKey.new(title: "LDAP - #{ldap_config.sync_ssh_keys}", key: key)
new_key.user = user
unless new_key.save
::Rails.logger.error "#{self.class.name}: failed to add LDAP SSH key #{key.inspect} to #{user.name} (#{user.id})\n"\
::Gitlab::AppLogger.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
......@@ -61,10 +61,10 @@ module EE
keys = user.keys.ldap.where.not(key: ldap_user.ssh_keys)
keys.each do |deleted_key|
::Rails.logger.info "#{self.class.name}: removing LDAP SSH key #{deleted_key.key} from #{user.name} (#{user.id})"
::Gitlab::AppLogger.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})"
::Gitlab::AppLogger.error "#{self.class.name}: failed to remove LDAP SSH key #{key.inspect} from #{user.name} (#{user.id})"
end
end
end
......@@ -83,7 +83,7 @@ module EE
kerberos_identity ||= ::Identity.new(provider: :kerberos, user: user)
kerberos_identity.extern_uid = ldap_user.kerberos_principal
unless kerberos_identity.save
::Rails.logger.error "#{self.class.name}: failed to add Kerberos principal #{ldap_user.kerberos_principal} to #{user.name} (#{user.id})\n"\
::Gitlab::AppLogger.error "#{self.class.name}: failed to add Kerberos principal #{ldap_user.kerberos_principal} to #{user.name} (#{user.id})\n"\
"error messages: #{kerberos_identity.errors.messages}"
end
end
......@@ -109,7 +109,7 @@ module EE
return if ldap_user.dn.empty? || ldap_user.dn == ldap_identity.extern_uid
unless ldap_identity.update(extern_uid: ldap_user.dn)
::Rails.logger.error "Could not update DN for #{user.name} (#{user.id})\n"\
::Gitlab::AppLogger.error "Could not update DN for #{user.name} (#{user.id})\n"\
"error messages: #{user.ldap_identity.errors.messages}"
end
end
......
......@@ -16,7 +16,7 @@ module EE
# rubocop: enable CodeReuse/ActiveRecord
def initialize(entry, adapter = nil)
Rails.logger.debug { "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}" } # rubocop:disable Gitlab/RailsLogger
::Gitlab::AppLogger.debug "Instantiating #{self.class.name} with LDIF:\n#{entry.to_ldif}"
@entry = entry
@adapter = adapter
end
......@@ -159,14 +159,14 @@ module EE
begin
base = ::Gitlab::Auth::Ldap::DN.new(adapter.config.base).to_a
rescue ::Gitlab::Auth::Ldap::DN::FormatError => e
Rails.logger.error "Configured LDAP `base` is invalid: '#{adapter.config.base}'. Error: \"#{e.message}\"" # rubocop:disable Gitlab/RailsLogger
::Gitlab::AppLogger.error "Configured LDAP `base` is invalid: '#{adapter.config.base}'. Error: \"#{e.message}\""
return []
end
members.select do |dn|
::Gitlab::Auth::Ldap::DN.new(dn).to_a.last(base.length) == base
rescue ::Gitlab::Auth::Ldap::DN::FormatError => e
Rails.logger.warn "Received invalid member DN from LDAP group '#{cn}': '#{dn}'. Error: \"#{e.message}\". Skipping" # rubocop:disable Gitlab/RailsLogger
::Gitlab::AppLogger.warn "Received invalid member DN from LDAP group '#{cn}': '#{dn}'. Error: \"#{e.message}\". Skipping"
end
end
......@@ -183,7 +183,7 @@ module EE
if dns
normalize_dns(dns)
else
Rails.logger.warn("Could not find member DNs for LDAP group #{entry.inspect}") # rubocop:disable Gitlab/RailsLogger
::Gitlab::AppLogger.warn("Could not find member DNs for LDAP group #{entry.inspect}")
[]
end
end
......
......@@ -136,7 +136,7 @@ RSpec.describe EE::Gitlab::Auth::Ldap::Group do
stub_ldap_adapter_nested_groups(group.dn, nested_groups, adapter)
stub_ldap_adapter_nested_groups(group2_entry.dn, [], adapter)
expect(Rails.logger)
expect(Gitlab::AppLogger)
.to receive(:error).with(/Configured LDAP `base` is invalid: 'invalid,dc=example,dc=com'/)
# Users in the top-level group always get added - they're not filtered
# through the nested groups shenanigans.
......@@ -161,9 +161,9 @@ RSpec.describe EE::Gitlab::Auth::Ldap::Group do
stub_ldap_adapter_nested_groups(group2_entry.dn, [], adapter)
stub_ldap_adapter_nested_groups(group3_entry.dn, [], adapter)
expect(Rails.logger)
expect(Gitlab::AppLogger)
.to receive(:info).with(/Returning original DN/)
expect(Rails.logger)
expect(Gitlab::AppLogger)
.to receive(:warn).with(/Received invalid member/)
expect(group.member_dns).not_to include('invalid,ou=user,ou=groups,dc=example,dc=com')
end
......
......@@ -45,7 +45,7 @@ module Gitlab
def self.normalize_dn(dn)
::Gitlab::Auth::Ldap::DN.new(dn).to_normalized_s
rescue ::Gitlab::Auth::Ldap::DN::FormatError => e
Rails.logger.info("Returning original DN \"#{dn}\" due to error during normalization attempt: #{e.message}") # rubocop:disable Gitlab/RailsLogger
Gitlab::AppLogger.info("Returning original DN \"#{dn}\" due to error during normalization attempt: #{e.message}") # rubocop:disable Gitlab/RailsLogger
dn
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