Include origin in remote requests and display it
parent
ea6540358c
commit
64cb7dfb3c
|
@ -12,8 +12,10 @@ module RemoteCredentialDataService
|
||||||
rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, [])
|
rv = json_to_mdm_object(data, CREDENTIAL_MDM_CLASS, [])
|
||||||
parsed_body = JSON.parse(data.response.body)
|
parsed_body = JSON.parse(data.response.body)
|
||||||
parsed_body.each do |cred|
|
parsed_body.each do |cred|
|
||||||
private_object = to_ar(cred['private_class'].constantize, cred['private'])
|
private_object = to_ar(cred['private']['type'].constantize, cred['private'])
|
||||||
|
origin_object = to_ar(cred['origin']['type'].constantize, cred['origin'])
|
||||||
rv[parsed_body.index(cred)].private = private_object
|
rv[parsed_body.index(cred)].private = private_object
|
||||||
|
rv[parsed_body.index(cred)].origin = origin_object
|
||||||
end
|
end
|
||||||
rv
|
rv
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,21 @@ require 'digest'
|
||||||
#
|
#
|
||||||
module ResponseDataHelper
|
module ResponseDataHelper
|
||||||
|
|
||||||
|
|
||||||
|
def process_response(response_wrapper)
|
||||||
|
begin
|
||||||
|
if response_wrapper.expected
|
||||||
|
body = response_wrapper.response.body
|
||||||
|
unless body.nil? && body.empty?
|
||||||
|
return body
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
elog "Error processing response: #{e.message}"
|
||||||
|
e.backtrace.each { |line| elog line }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
#
|
#
|
||||||
# Converts an HTTP response to a Hash
|
# Converts an HTTP response to a Hash
|
||||||
#
|
#
|
||||||
|
@ -13,14 +28,10 @@ module ResponseDataHelper
|
||||||
#
|
#
|
||||||
def json_to_hash(response_wrapper)
|
def json_to_hash(response_wrapper)
|
||||||
begin
|
begin
|
||||||
if response_wrapper.expected
|
body = process_response(response_wrapper)
|
||||||
body = response_wrapper.response.body
|
return JSON.parse(body).symbolize_keys
|
||||||
unless body.nil? && body.empty?
|
|
||||||
return JSON.parse(body).symbolize_keys
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue => e
|
rescue => e
|
||||||
elog "Error parsing response: #{e.message}"
|
elog "Error parsing response as JSON: #{e.message}"
|
||||||
e.backtrace.each { |line| elog line }
|
e.backtrace.each { |line| elog line }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,15 +47,12 @@ module ResponseDataHelper
|
||||||
def json_to_mdm_object(response_wrapper, mdm_class, returns_on_error = nil)
|
def json_to_mdm_object(response_wrapper, mdm_class, returns_on_error = nil)
|
||||||
if response_wrapper.expected
|
if response_wrapper.expected
|
||||||
begin
|
begin
|
||||||
body = response_wrapper.response.body
|
parsed_body = Array.wrap(JSON.parse(process_response(response_wrapper)))
|
||||||
if !body.nil? && !body.empty?
|
rv = []
|
||||||
parsed_body = Array.wrap(JSON.parse(body))
|
parsed_body.each do |json_object|
|
||||||
rv = []
|
rv << to_ar(mdm_class.constantize, json_object)
|
||||||
parsed_body.each do |json_object|
|
|
||||||
rv << to_ar(mdm_class.constantize, json_object)
|
|
||||||
end
|
|
||||||
return rv
|
|
||||||
end
|
end
|
||||||
|
return rv
|
||||||
rescue => e
|
rescue => e
|
||||||
elog "Mdm Object conversion failed #{e.message}"
|
elog "Mdm Object conversion failed #{e.message}"
|
||||||
e.backtrace.each { |line| elog "#{line}\n" }
|
e.backtrace.each { |line| elog "#{line}\n" }
|
||||||
|
@ -102,6 +110,8 @@ module ResponseDataHelper
|
||||||
case association.macro
|
case association.macro
|
||||||
when :belongs_to
|
when :belongs_to
|
||||||
data.delete("#{k}_id")
|
data.delete("#{k}_id")
|
||||||
|
# Polymorphic associations do not auto-create the 'build_model' method
|
||||||
|
next if association.options[:polymorphic]
|
||||||
to_ar(association.klass, v, obj.send("build_#{k}"))
|
to_ar(association.klass, v, obj.send("build_#{k}"))
|
||||||
obj.class_eval do
|
obj.class_eval do
|
||||||
define_method("#{k}_id") { obj.send(k).id }
|
define_method("#{k}_id") { obj.send(k).id }
|
||||||
|
|
|
@ -71,11 +71,12 @@ module ServletHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def format_cred_json(data)
|
def format_cred_json(data)
|
||||||
includes = [:logins, :public, :private, :realm]
|
includes = [:logins, :public, :private, :realm, :origin]
|
||||||
|
|
||||||
response = []
|
response = []
|
||||||
Array.wrap(data).each do |cred|
|
Array.wrap(data).each do |cred|
|
||||||
json = cred.as_json(include: includes).merge('private_class' => cred.private.class.to_s)
|
json = cred.as_json(include: includes)
|
||||||
|
json['origin'] = json['origin'].merge('type' => cred.origin.class.to_s)
|
||||||
json['public'] = json['public'].merge('type' => cred.public.type)
|
json['public'] = json['public'].merge('type' => cred.public.type)
|
||||||
json['private'] = json['private'].merge('type' => cred.private.type)
|
json['private'] = json['private'].merge('type' => cred.private.type)
|
||||||
response << json
|
response << json
|
||||||
|
|
|
@ -429,7 +429,7 @@ class Creds
|
||||||
|
|
||||||
tbl << [
|
tbl << [
|
||||||
"", # host
|
"", # host
|
||||||
"", # cred
|
origin, # origin
|
||||||
"", # service
|
"", # service
|
||||||
public_val,
|
public_val,
|
||||||
private_val,
|
private_val,
|
||||||
|
|
Loading…
Reference in New Issue