Class: SoarSmaak::Router
- Inherits:
-
Object
- Object
- SoarSmaak::Router
- Defined in:
- lib/soar_smaak/router.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Router
constructor
A new instance of Router.
- #smaak(request) ⇒ Object
Constructor Details
#initialize(app) ⇒ Router
Returns a new instance of Router.
5 6 7 |
# File 'lib/soar_smaak/router.rb', line 5 def initialize(app) @app = app end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/soar_smaak/router.rb', line 3 def configuration @configuration end |
Instance Method Details
#call(env) ⇒ Object
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/soar_smaak/router.rb', line 16 def call(env) @configuration = env['configuration'] @auditing = env['auditing'] @signed_routes = env['signed_routes'] SoarSmaak::SecureService::auditing = @auditing secure_service = SoarSmaak::SecureService.get_instance(@configuration) @server = secure_service.smaak_server @auditing.debug("Smaak: signed routes are: #{@signed_routes}") request = Rack::Request.new(env) if SoarSmaak::Interpreter::smaak_request?(request) or @signed_routes[request.path] @auditing.debug("Smaak: routing smaak request") begin , body = smaak(request) rescue => ex return [500, {"Content-Type" => "text/html"}, ['Unable to route request on SMAAK route. Was your request a SMAAK request?']] end return [403, {}, [" 403 - Not authorized"]] if not or not .identifier @auditing.debug("Smaak: request authorized for #{.identifier}") session = update_session_with_smaak(request, ) env["rack.input"] = body else @auditing.debug("routing non-smaak request") end http_code, content_type, body = @app.call(env) if SoarSmaak::Interpreter::smaak_request?(request) or @signed_routes[request.path] @auditing.debug("Smaak: request authorized for #{.identifier}") return [http_code, content_type, [@server.compile_response(, body[0])]] if .encrypt return [http_code, content_type, @server.compile_response(, body)] else return http_code, content_type, body end # rescue => ex # puts ex # [500, {"Content-Type" => "text/html"}, ['Unable to route request on SMAAK route. Was your request a SMAAK request?']] end |
#smaak(request) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/soar_smaak/router.rb', line 9 def smaak(request) @auditing.debug("Smaak: verifying request") , body = @server.verify_signed_request(request) @auditing.debug("Smaak: auth_message: #{}") return , body end |