Class: LdapChangelogConnector

Inherits:
RubySync::Connectors::LdapConnector show all
Defined in:
lib/ruby_sync/connectors/ldap_changelog_connector.rb

Overview

$VERBOSE = true

Instance Attribute Summary

Attributes inherited from RubySync::Connectors::BaseConnector

#is_vault, #name, #once_only, #pipeline

Instance Method Summary collapse

Methods inherited from RubySync::Connectors::LdapConnector

#[], #add, #delete, #each_entry, fields, #modify, sample_config, #started, #target_transform

Methods inherited from RubySync::Connectors::BaseConnector

#add, #association_context, #association_for, #can_act_as_vault?, #clean, #create_operations_for, #each_entry, #entry_for_own_association_key, event_method, fields, #find_associated, #has_entry_for_key?, #is_delete_echo?, #is_echo?, #is_vault?, #own_association_key_for, #path_for_own_association_key, sample_config, #start, #started, #stop, #stopped, #sync_started, #sync_stopped, target_transform, #test_delete, #test_modify, track_associations_with, track_changes_with

Methods included from RubySync::Connectors::ConnectorEventProcessing

#associated_path, #clean, #delete_from_mirror, #perform_add, #perform_delete, #perform_modify, #process, #update_mirror

Methods included from RubySync::Utilities

#as_array, #call_if_exists, #class_called, #class_for_name, #class_name_for, #connector_called, #dump_after, #dump_before, #effective_operations, #ensure_dir_exists, #get_preference, #get_preference_file_path, #include_in_search_path, #log_progress, #perform_operations, #perform_transform, #pipeline_called, #set_preference, #something_called, #with_rescue

Constructor Details

#initialize(options = {}) ⇒ LdapChangelogConnector

Returns a new instance of LdapChangelogConnector.



32
33
34
35
36
37
# File 'lib/ruby_sync/connectors/ldap_changelog_connector.rb', line 32

def initialize options={}
  super options 
  @last_change_number = 1
  # TODO: Persist the current CSN, for now we'll just skip to the end of the changelog
  skip_existing_changelog_entries
end

Instance Method Details

#each_changeObject

Look for changelog entries. This is not supported by all LDAP servers Changelog entries have these attributes targetdn changenumber objectclass changes changetime changetype dn

TODO: Detect presence/location of changelog from root DSE



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ruby_sync/connectors/ldap_changelog_connector.rb', line 49

def each_change
  with_ldap do |ldap|
    log.debug "@last_change_number = #{@last_change_number}"
    filter = "(changenumber>=#{@last_change_number})"
    first = true
    @full_refresh_required = false
    ldap.search :base => changelog_dn, :filter =>filter do |change|
	change_number = change.changenumber[0].to_i
	if first
 first = false
 # TODO: Persist the change_number so that we don't do a full resync everytime rubysync starts
 if change_number != @last_change_number
   log.warn "Earliest change number (#{change_number}) differs from that recorded (#{@last_change_number})."
   log.warn "A full refresh is required."
   @full_refresh_required = true
   break
 end
	else
 @last_change_number = change_number if change_number > @last_change_number
 # TODO: A proper DN object would be nice instead of string manipulation
 target_dn = change.targetdn[0].gsub(/\s*,\s*/,',')
 if target_dn =~ /#{search_base}$/oi
   change_type = change.changetype[0]
   event = event_for_changelog_entry(change)
   yield event
 end
	end
    end
  end
  each_entry if @full_refresh_required
end

#skip_existing_changelog_entriesObject



82
83
84
85
86
87
88
89
90
91
# File 'lib/ruby_sync/connectors/ldap_changelog_connector.rb', line 82

def skip_existing_changelog_entries
  with_ldap do |ldap|
    filter = "(changenumber>=#{@last_change_number})"
    @full_refresh_required = false
    ldap.search :base => changelog_dn, :filter =>filter do |change|
	change_number = change.changenumber[0].to_i
	@last_change_number = change_number if change_number > @last_change_number
    end
  end
end

#test_add(id, details) ⇒ Object

Called by unit tests to inject data



95
96
97
98
# File 'lib/ruby_sync/connectors/ldap_changelog_connector.rb', line 95

def test_add id, details
  details << RubySync::Operation.new(:add, "objectclass", ['inetOrgPerson', 'organizationalPerson', 'person', 'top', 'RubySyncSynchable'])
  add id, details
end