Introduced Sequencer Unit base class Sequencer::Unit::Common::FallbackProvider to handle simple setting fallback values of state attributes if not already present.
This commit is contained in:
parent
598d7b2060
commit
e73f75c458
6 changed files with 65 additions and 34 deletions
|
@ -9,6 +9,7 @@ class Sequencer
|
||||||
'Import::Ldap::Users::StaticAttributes',
|
'Import::Ldap::Users::StaticAttributes',
|
||||||
'Import::Ldap::Users::DryRun::Flag',
|
'Import::Ldap::Users::DryRun::Flag',
|
||||||
'Import::Ldap::Users::DryRun::Payload',
|
'Import::Ldap::Users::DryRun::Payload',
|
||||||
|
'Ldap::Config',
|
||||||
'Ldap::Connection',
|
'Ldap::Connection',
|
||||||
'Import::Ldap::Users::UserRoles',
|
'Import::Ldap::Users::UserRoles',
|
||||||
'Import::Ldap::Users::Sum',
|
'Import::Ldap::Users::Sum',
|
||||||
|
|
29
lib/sequencer/unit/common/fallback_provider.rb
Normal file
29
lib/sequencer/unit/common/fallback_provider.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
class Sequencer
|
||||||
|
class Unit
|
||||||
|
module Common
|
||||||
|
class FallbackProvider < Sequencer::Unit::Base
|
||||||
|
|
||||||
|
def process
|
||||||
|
provides = self.class.provides
|
||||||
|
raise 'Only one provide attribute possible' if provides.size != 1
|
||||||
|
|
||||||
|
attribute = provides.shift
|
||||||
|
return if state.provided?(attribute)
|
||||||
|
|
||||||
|
result = fallback
|
||||||
|
|
||||||
|
# don't store nil values which are default anyway
|
||||||
|
return if result.nil?
|
||||||
|
|
||||||
|
state.provide(attribute, result)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def fallback
|
||||||
|
raise 'Missing implementation of fallback method'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,27 +1,22 @@
|
||||||
class Sequencer
|
class Sequencer
|
||||||
class Unit
|
class Unit
|
||||||
module Exchange
|
module Exchange
|
||||||
class Connection < Sequencer::Unit::Base
|
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||||
|
|
||||||
uses :ews_config
|
uses :ews_config
|
||||||
provides :ews_connection
|
provides :ews_connection
|
||||||
|
|
||||||
def process
|
|
||||||
# check if EWS connection is already given (sub sequence)
|
|
||||||
return if state.provided?(:ews_connection)
|
|
||||||
|
|
||||||
state.provide(:ews_connection) do
|
|
||||||
Viewpoint::EWSClient.new(
|
|
||||||
config[:endpoint],
|
|
||||||
config[:user],
|
|
||||||
config[:password],
|
|
||||||
additional_opts
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def fallback
|
||||||
|
Viewpoint::EWSClient.new(
|
||||||
|
config[:endpoint],
|
||||||
|
config[:user],
|
||||||
|
config[:password],
|
||||||
|
additional_opts
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def config
|
def config
|
||||||
@config ||= begin
|
@config ||= begin
|
||||||
ews_config || ::Import::Exchange.config
|
ews_config || ::Import::Exchange.config
|
||||||
|
|
|
@ -3,19 +3,14 @@ class Sequencer
|
||||||
module Import
|
module Import
|
||||||
module Exchange
|
module Exchange
|
||||||
module FolderContacts
|
module FolderContacts
|
||||||
class FolderIds < Sequencer::Unit::Base
|
class FolderIds < Sequencer::Unit::Common::FallbackProvider
|
||||||
include ::Sequencer::Unit::Exchange::Folders::Mixin::Folder
|
|
||||||
|
|
||||||
provides :ews_folder_ids
|
provides :ews_folder_ids
|
||||||
|
|
||||||
def process
|
private
|
||||||
# check if ids are already processed
|
|
||||||
return if state.provided?(:ews_folder_ids)
|
|
||||||
|
|
||||||
state.provide(:ews_folder_ids) do
|
def fallback
|
||||||
config = ::Import::Exchange.config
|
::Import::Exchange.config[:folders]
|
||||||
config[:folders]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
17
lib/sequencer/unit/ldap/config.rb
Normal file
17
lib/sequencer/unit/ldap/config.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
require 'import/ldap'
|
||||||
|
|
||||||
|
class Sequencer
|
||||||
|
class Unit
|
||||||
|
module Ldap
|
||||||
|
class Config < Sequencer::Unit::Common::FallbackProvider
|
||||||
|
provides :ldap_config
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def fallback
|
||||||
|
::Import::Ldap.config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,22 +1,16 @@
|
||||||
require 'ldap'
|
require 'ldap'
|
||||||
require 'import/ldap'
|
|
||||||
|
|
||||||
class Sequencer
|
class Sequencer
|
||||||
class Unit
|
class Unit
|
||||||
module Ldap
|
module Ldap
|
||||||
class Connection < Sequencer::Unit::Base
|
class Connection < Sequencer::Unit::Common::FallbackProvider
|
||||||
uses :ldap_config
|
uses :ldap_config
|
||||||
provides :ldap_connection
|
provides :ldap_connection
|
||||||
|
|
||||||
def process
|
private
|
||||||
return if state.provided?(:ldap_connection)
|
|
||||||
|
|
||||||
state.provide(:ldap_connection) do
|
def fallback
|
||||||
config = ldap_config
|
::Ldap.new(ldap_config)
|
||||||
config ||= ::Import::Ldap.config
|
|
||||||
|
|
||||||
::Ldap.new(config)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue