Socket
Book a DemoInstallSign in
Socket

soar_sc_routing

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

soar_sc_routing

0.3.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

SoarScRouting

Features

RouterMeta

This library facilitates the registration of routes and their meta for use by a router. The SOAR reference implementation uses this library to register routes and meta for soar_sc routers.

When a route is registered, control is delegated as appropriate to the controller, renderer and access manager indicated in the meta.

An IoC function is provided that specialization classes can use to group registrations in during initialization of the router meta instance.

An IoC function is provided to delegate rendering of views to the specialized class.

BaseRouter

This library also provides a base router to build routers from. The router will search all paths registered with it and call the block registered for the first matched path.

The block delegates to the controller specified in the meta, and then renders the ouput using the renderer (view) specified in the meta.

The base router also provides two IoC functions to cater for routes not found and exceptions while routing.

Router meta

Router meta is validated during registration and takes the form:

{ 'description' => 'description',
  'service_name' => 'service_name',
  'method' => 'GET/POST/...',
  'path' => '/path',
  'params' => { 'para' => 'm1'},
  'nfrs' => { 'secured' => 'SIGNED/UNSIGNED',
              'authorization' => 'AUTHORIZED/UNAUTHORIZED'
            }
}

If a route is marked as AUTHORIZED, the route and the access manager set are registered with SoarAuthorization::Authorize.

The interpretation of a route marked as SIGNED is left up to the router implementation. In soar_sc SIGNED activates and requires SMAAK for requests traversing the route.

###Validation errors:

ArgumentError "detail must not be nil" if the detail parameter is nil
ArgumentError "path must be provided" if detail['path'] is nil
ArgumentError "description must be provided" if detail['description']
ArgumentError "service_name must be provided" if detail['service_name']
ArgumentError "method must be provided" if detail['method'] is nil
ArgumentError "nfrs must be provided" if detail['nfrs']
ArgumentError "nfrs['authorization'] must be provided" if detail['nfrs']['authorization'] is nil
ArgumentError "nfrs['secured'] must be provided" if detail['nfrs']['secured'] is nil

Installation

Add this line to your application's Gemfile:

gem 'soar_sc_routing'

And then execute:

$ bundle

Or install it yourself as:

$ gem install soar_sc_routing

Usage

RouterMeta

class AuthenticatedRouterMeta < SoarScRouting::RouterMeta
  def access_manager
    provider = Soar::Authorization::AccessManager::Provider::ServiceRegistry.new(SoarSc::service_registry)
    @policy_am ||= Soar::Authorization::AccessManager.new(provider)
    @policy_am
  end

  def setup_routing_table
    # register_route({
    #   'description' => 'Given a pattern, finds services matching the pattern and reports where they can be accessed',
    #   'service_name' => 'where-is-it',
    #   'path' => '/where-is-it',
    #   'method' => 'get',
    #   'params' => {
    #     'pattern' => {
    #       'required' => 'true', 'type' => 'string'
    #     }
    #   },
    #   'nfrs' => {
    #     'authorization' => 'AUTHORIZED',
    #     'secured' => 'UNSIGNED'
    #   },
    #   'view' => {
    #     'renderer' => 'json',
    #     'name' => 'where_is_it'
    #   },
    #   'controller' => 'WhereIsIt'
    # }, SoarSc::startup_flow_id)
  end

  def render_view(detail, http_code, body)
    renderer = SoarSc::Renderer.new
    renderer.render_view(detail, http_code, body)
  end
end

BaseRouter

class SoarScRouter < SoarScRouting::BaseRouter
  def not_found
    SoarSc::Web::Views::Default.not_found
  end

  def excepted(ex)
   SoarSc::Web::Views::Default.error(ex)      
  end
end

Testing

Testing can be performed:

$ bundle exec rspec -cfd spec/*

Contributing

Please send feedback and comments to the author at:

Ernst van Graan ernst.van.graan@hetzner.co.za

This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za

License

The gem is available as open source under the terms of the MIT License.

FAQs

Package last updated on 12 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.