13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/cloudrail_si/servicecode/commands/AwaitCodeRedirect.rb', line 13
def execute(environment, parameters)
Helper.assert(parameters.length >= 2 && Helper.is_var_address(parameters[0]) &&
(Helper.is_string(parameters[1]) || Helper.is_var_address(parameters[1])))
res_var = parameters[0]
url_str = Helper.resolve(environment, parameters[1])
legacy = parameters.length == 2
keys = []
(2..parameters.length - 1).each do |i|
keys.push(Helper.resolve(environment, parameters[i]))
end
keys.push('code') if (legacy)
redirect_receiver = environment.instance_dependency_storage[:redirect_receiver] if (!redirect_receiver || !redirect_receiver.respond_to?(:call))
raise Errors::UserError.new("This service needs the RedirectReceiver to be implemented as a function. Have a look at our examples and documentation if you are unsure how to do that.")
end
redirect_url = redirect_receiver.call(url_str, environment.save_state_to_string())
parts = redirect_url.split('?')
param_str = (parts.length >= 2) ? parts[1] : parts[0]
query_map = CGI::parse(param_str)
res_map = {}
keys.each do |key|
if query_map[key].nil? || query_map[key].empty?
raise Errors::UserError.new("The URL the RedirectReceiver returns does not contain all necessary keys in the query, it's missing at least #{key}")
else
res_map[key] = query_map[key][0] end
end
environment.set_variable(res_var, legacy ? res_map["code"] : res_map)
end
|