soar_sc_routing 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 891ece3dcea44d840af6368216d9e21ddbdecf74
4
- data.tar.gz: 6592a06ade0f0db34f191cd3be9e9cf20373fb87
3
+ metadata.gz: e7711ac0ca595ce5f6836934567ae557f6705257
4
+ data.tar.gz: 1871d2e6936b468d491b9a8183a836cfedc52288
5
5
  SHA512:
6
- metadata.gz: 02f58e8fe7f9d8b773d800f80e7b4dec71436d33623df0dbe77f257eb1ea50bb8143a163ba91812987cb515e6fb1cf903047ff24fae88883ed0bc822300ec106
7
- data.tar.gz: 2dd5b2a535ec82ddcafc97825ebe6f72ab63ae16410b276ab673d11644952d4d52e8525f626719ac7e29757be1a47faca0f31f64306f4c4d2ed2afbdf30831a4
6
+ metadata.gz: 7d724e3768b15066d6653eeae580a33cef91913171a3c61b2e51cfd369a9c3755d88ea886d3969d6c175b4921c0143533b4927bb0a215d3e6df3548ecb8c01ff
7
+ data.tar.gz: 3fde980c6b3fb7981a0eec248ae69bc0f253d016814156473dfd5c0c7acf394e55086104924f0cd70a8a5fbb153e53b660ee0f218fb0bc10aa81b661b55283d7
data/README.md CHANGED
@@ -74,7 +74,7 @@ Or install it yourself as:
74
74
 
75
75
  ```ruby
76
76
  class AuthenticatedRouterMeta < SoarScRouting::RouterMeta
77
- def policy_am
77
+ def access_manager
78
78
  @policy_am ||= SoarPolicyAccessManager::PolicyAccessManager.new(SoarSc::service_registry)
79
79
  @policy_am
80
80
  end
@@ -41,25 +41,30 @@ module SoarScRouting
41
41
  end
42
42
 
43
43
  def route_matched_path(request, path)
44
- debug("matched #{path}",request.params['flow_identifier'])
44
+ debug("#{@route_meta.name} matched #{path}",request.params['flow_identifier'])
45
45
  http_code, content_type, body = @route_meta.routing[path].call(request)
46
46
  debug("controller returned #{http_code}, #{content_type}", request.params['flow_identifier'])
47
47
  return [http_code, content_type, body]
48
48
  end
49
49
 
50
50
  def route_path(request)
51
- # Only allow POST requests
52
- #if not request.post?
53
- # return SoarSc::Web::Views::Default.render(405, "")
54
- #end
51
+ debug("#{@route_meta.name} attempting to match #{request.path}",request.params['flow_identifier'])
55
52
  @route_meta.routing.each do |path, block|
56
- if matches = Regexp.new(path).match(request.path)
53
+ matches = Regexp.new(path).match(request.path)
54
+ if matches && request_verb_matches_route_verb?(request,@route_meta.lexicon)
57
55
  request.define_singleton_method(:regex_matches) { return matches.to_a }
58
56
  return route_matched_path(request, path)
59
57
  end
60
58
  end
61
- debug("no match to #{request.path}",request.params['flow_identifier'])
59
+ debug("no match to #{request.path} on router #{@route_meta.name}",request.params['flow_identifier'])
62
60
  not_found
63
61
  end
62
+
63
+ private
64
+
65
+ def request_verb_matches_route_verb?(request,path_lexicon)
66
+ return false if path_lexicon.nil? or path_lexicon[request.path].nil?
67
+ path_lexicon[request.path]['method'].include?(request.env['REQUEST_METHOD'])
68
+ end
64
69
  end
65
70
  end
@@ -19,13 +19,15 @@ module SoarScRouting
19
19
  attr_accessor :service_names
20
20
  attr_accessor :policy_am
21
21
  attr_accessor :autenticate
22
+ attr_reader :name
22
23
 
23
- def initialize(configuration)
24
+ def initialize(configuration,name = 'router')
24
25
  @configuration = configuration
25
26
  @lexicon = {}
26
27
  @routing = {}
27
28
  @signed_routes = {}
28
29
  @service_names = {}
30
+ @name = name
29
31
  setup_routing_table
30
32
  end
31
33
 
@@ -35,8 +37,8 @@ module SoarScRouting
35
37
 
36
38
  def register_route(detail, startup_flow_id = nil)
37
39
  validate_detail(detail)
38
- info("Registering service: #{detail}", startup_flow_id)
39
- resource = SoarScRouting::Resource.new(detail['description'], "#{detail['service_name']}", detail['method'].upcase, detail['params'])
40
+ info("Registering service: #{detail} on router #{@name}", startup_flow_id)
41
+ resource = SoarScRouting::Resource.new(detail['description'], "#{detail['service_name']}", upcase(detail['method']), detail['params'])
40
42
  add_resource_route(detail['path'], resource, interpret_secured(detail), interpret_authorized(detail)) do |request|
41
43
  if detail['controller']
42
44
  delegate_to_controller_and_renderer(detail, startup_flow_id, request)
@@ -101,7 +103,7 @@ module SoarScRouting
101
103
  controller = Object::const_get(detail['controller']).new(@configuration)
102
104
  end
103
105
  http_code, body = controller.serve(request)
104
- render_view(detail, http_code, body)
106
+ render_view(detail, http_code, body)
105
107
  end
106
108
 
107
109
  def info(message, startup_flow_id)
@@ -150,6 +152,11 @@ module SoarScRouting
150
152
  authorized = 'AUTHORIZED' if not ['AUTHORIZED', 'UNAUTHORIZED'].include?(detail['nfrs']['authorization'])
151
153
  end
152
154
  authorized == 'AUTHORIZED'
153
- end
155
+ end
156
+
157
+ def upcase(methods)
158
+ return methods.map(&:upcase) if methods.is_a?(Array)
159
+ methods.upcase if methods.is_a?(String)
160
+ end
154
161
  end
155
162
  end
@@ -1,3 +1,3 @@
1
1
  module SoarScRouting
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_sc_routing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ernst Van Graan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-19 00:00:00.000000000 Z
11
+ date: 2016-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsender