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
46
47
48
49
50
51
52
|
# File 'lib/envoi/mam/agent/config_service_client.rb', line 13
def self.config_get(args = { })
app_id = args[:app_id]
token = args[:token]
api_url = args[:api_url] || DEFAULT_API_URL
request_url = "#{api_url}getuserrecord?token=#{token}&application_id=#{app_id}"
uri = URI(request_url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Get.new(uri.request_uri)
response = http.request(req)
code = response.code
body_raw = response.body
unless code == '200'
puts uri.to_s
puts uri.request_uri
puts code
puts body_raw
return false
end
body_parsed = JSON.parse(body_raw)
result = body_parsed['result']
raise "Invalid response from configuration service. No result found. '#{body_raw}'" unless result
app_data = result.first
raise "Invalid response from configuration service. No app data found. '#{body_raw}'" unless app_data
agent_data_raw = app_data['agentdata']
raise "Invalid response from configuration service. No agentdata found. '#{body_raw}'" unless agent_data_raw
begin
agent_data = JSON.parse(agent_data_raw)
rescue => e
raise "Error parsing agentdata. #{e.message} '#{body_raw}'"
end
agent_data
end
|