2018-04-26 08:55:53 +00:00
|
|
|
require_dependency 'sequencer/unit/import/common/model/statistics/mixin/empty_diff'
|
2017-11-29 16:54:52 +00:00
|
|
|
|
|
|
|
class Sequencer
|
|
|
|
class Unit
|
|
|
|
module Import
|
|
|
|
module Ldap
|
|
|
|
module Users
|
2018-01-08 15:30:09 +00:00
|
|
|
class Total < Sequencer::Unit::Base
|
2017-11-29 16:54:52 +00:00
|
|
|
include ::Sequencer::Unit::Import::Common::Model::Statistics::Mixin::EmptyDiff
|
|
|
|
|
|
|
|
uses :ldap_config, :ldap_connection, :dry_run
|
|
|
|
|
|
|
|
def process
|
|
|
|
state.provide(:statistics_diff) do
|
|
|
|
diff.merge(
|
2018-01-08 15:30:09 +00:00
|
|
|
total: total
|
2017-11-29 16:54:52 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-01-08 15:30:09 +00:00
|
|
|
def total
|
2017-11-29 16:54:52 +00:00
|
|
|
if !dry_run
|
|
|
|
result = Cache.get(cache_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
result ||= ldap_connection.count(ldap_config[:user_filter])
|
|
|
|
|
|
|
|
if !dry_run
|
|
|
|
Cache.write(cache_key, result, { expires_in: 1.hour })
|
|
|
|
end
|
|
|
|
|
|
|
|
result
|
|
|
|
end
|
|
|
|
|
|
|
|
def cache_key
|
|
|
|
@cache_key ||= "#{ldap_connection.host}::#{ldap_connection.port}::#{ldap_connection.ssl}::#{ldap_connection.base_dn}::#{ldap_config[:user_filter]}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|