module RouterHelper
Public Instance Methods
formatted_exception_message(ex)
click to toggle source
# File lib/router_helper.rb, line 98 def formatted_exception_message ex return ex.backtrace.join("\n\t").sub("\n\t", ": #{ex}#{ex.class ? " (#{ex.class})" : ''}\n\t") end
generate_third_party_url()
click to toggle source
# File lib/router_helper.rb, line 93 def generate_third_party_url urls = send("services_#{Rails.env}_urls") urls.map {|key,values| values.map {|k,v| define_method("#{key}_host_service_#{k}") { v }}} end
kafka_log_end_points()
click to toggle source
# File lib/router_helper.rb, line 81 def kafka_log_end_points tool_urls[Rails.env.to_sym][:kafka] end
redis_log()
click to toggle source
# File lib/router_helper.rb, line 89 def redis_log $redis_log ||= Redis.new(redis_log_end_points) end
redis_log_end_points()
click to toggle source
# File lib/router_helper.rb, line 85 def redis_log_end_points tool_urls[Rails.env.to_sym][:redis] end
rest_client_url(url, _payload = {})
click to toggle source
# File lib/router_helper.rb, line 3 def rest_client_url(url, _payload = {}) payload = _payload[:params] || {} payload[:referer_service] = current_micro_service_name headers = {"#{jwt_header_name}" => jwt_header_token} headers = headers.merge(_payload[:headers]) if _payload[:headers] verb = _payload[:method] begin data = RestClient::Request.execute(method: verb, url: url, payload: payload, headers: headers) data = {code: data.code, data: JSON.parse(data.body), headers: data.headers, cookies: data.cookies} rescue RestClient::Unauthorized, RestClient::Forbidden => err data = JSON.parse(err.response) rescue RestClient::ResourceNotFound => ex data = {code: 404, error: "Url not found #{url}\n" + formatted_exception_message(ex)} rescue RestClient::InternalServerError => ex data = {code: 500, error: "Server side exception\n" + formatted_exception_message(ex) } rescue Exception => ex data = {code: 503, error: formatted_exception_message(ex) } end data end
services_development_urls()
click to toggle source
# File lib/router_helper.rb, line 24 def services_development_urls @_services_development_urls ||= { user: {url: "http://localhost", port: 3000}, horizontal: {url: "http://localhost", port: 3005}, content: {url: "http://localhost", port: 3004}, practice: {url: "http://localhost", port: 3001}, mocktest: {url: "http://localhost", port: 3002}, payment: {url: "http://localhost", port: 3003} } end
services_preprod_urls()
click to toggle source
# File lib/router_helper.rb, line 46 def services_preprod_urls @_services_preprod_urls ||= { user: {url: "http://user-microservice", port: 80}, horizontal: {url: "http://horizontal-microservice", port: 80}, content: {url: "http://content-microservice", port: 80}, mocktest: {url: "http://mocktest-microservice", port: 80}, practice: {url: "http://practice-microservice", port: 80}, payment: {url: "http://payment-microservice", port: 80} } end
services_production_urls()
click to toggle source
# File lib/router_helper.rb, line 61 def services_production_urls @_services_production_urls ||= { user: {url: "http://user-microservice", port: 80}, horizontal: {url: "http://horizontal-microservice", port: 80}, content: {url: "http://content-microservice", port: 80}, mocktest: {url: "http://mocktest-microservice", port: 80}, practice: {url: "http://practice-microservice", port: 80}, payment: {url: "http://payment-microservice", port: 80} } end
services_staging_urls()
click to toggle source
# File lib/router_helper.rb, line 35 def services_staging_urls @_services_staging_urls ||= { user: {url: "http://user-microservice", port: 80}, horizontal: {url: "http://horizontal-microservice", port: 80}, content: {url: "http://content-microservice", port: 80}, mocktest: {url: "http://mocktest-microservice", port: 80}, practice: {url: "http://practice-microservice", port: 80}, payment: {url: "http://payment-microservice", port: 80} } end
services_uri()
click to toggle source
# File lib/router_helper.rb, line 57 def services_uri @_services_uri ||= send("services_#{Rails.env}_urls") end
tool_urls()
click to toggle source
# File lib/router_helper.rb, line 72 def tool_urls stage = ['10.140.10.48:9092','10.140.10.103:9092','10.140.10.108:9092'] prod = ['10.140.10.178:9092', '10.140.10.159:9092', '10.140.10.236:9092'] {development: {kafka: stage, redis: {host: "10.140.10.195", port: 6379}}, staging: {kafka: stage, redis: {host: "10.140.10.195", port: 6379}}, preprod: {kafka: stage, redis: {host: "10.140.10.195", port: 6379}}, production: {kafka: prod, redis: {host: "10.140.10.42", port: 6379}}} end