8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/xlogin/delegator.rb', line 8
def build(uri, **params)
target_host = params.delete(:relay)
return super(uri, **params) unless target_host
target_info = Xlogin.factory.get_inventory(target_host)
target_temp = Xlogin.factory.get_template(target_info[:type])
target_uri = Addressable::URI.parse(target_info[:uri])
login = @methods.fetch(:login)
delegate = @methods.fetch(:delegate)
raise Xlogin::Error.new("'login' and 'delegate' methods must be defined in the #{target_info[:type]} template.") unless login && delegate
relay_uri = Addressable::URI.parse(uri.to_s)
userinfo_cache = relay_uri.userinfo.dup
relay_uri.userinfo = ''
session = target_temp.build(relay_uri, **params)
session.instance_exec(*userinfo_cache.split(':'), &login)
session.instance_exec(target_uri, **params, &delegate)
session
end
|