soar_sc_routing 0.1.0 → 0.1.1
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 +4 -4
- data/.gitignore +1 -0
- data/README.md +104 -7
- data/lib/soar_sc_routing/router_meta.rb +1 -1
- data/lib/soar_sc_routing/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fea3c6587e087f991be068900975cf9cb55de40
|
4
|
+
data.tar.gz: 3de8a711bc33523266652720ac014c18e9946e71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 96c82424d98aeac09b2aa1d367d0a0d73be9b8fc4c99d5aa4dc5344213b72411defe5d81282b81541d02c4286d545aed43f20ab934f9352cc48a7c0c6021beab
|
7
|
+
data.tar.gz: 25dc7233e50a22e72da73375efb30aa07b741283180776039bfb0fb875a6f489211ecb8aa3588d19127f8f13df3d6801ce7dae34f0e48b31e956c4ecb548547c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,57 @@
|
|
1
1
|
# SoarScRouting
|
2
2
|
|
3
|
-
|
3
|
+
## Features
|
4
4
|
|
5
|
-
|
5
|
+
### RouterMeta
|
6
|
+
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.
|
7
|
+
|
8
|
+
When a route is registered, control is delegated as appropriate to the controller, renderer and access manager indicated in the meta.
|
9
|
+
|
10
|
+
An IoC function is provided that specialization classes can use to group registrations in during initialization of the router meta instance.
|
11
|
+
|
12
|
+
An IoC function is provided to delegate rendering of views to the specialized class.
|
13
|
+
|
14
|
+
### BaseRouter
|
15
|
+
|
16
|
+
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.
|
17
|
+
|
18
|
+
The block delegates to the controller specified in the meta, and then renders the ouput using the renderer (view) specified in the meta.
|
19
|
+
|
20
|
+
The base router also provides two IoC functions to cater for routes not found and exceptions while routing.
|
21
|
+
|
22
|
+
### Router meta
|
23
|
+
|
24
|
+
Router meta is validated during registration and takes the form:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
{ 'description' => 'description',
|
28
|
+
'service_name' => 'service_name',
|
29
|
+
'method' => 'GET/POST/...',
|
30
|
+
'path' => '/path',
|
31
|
+
'params' => { 'para' => 'm1'},
|
32
|
+
'nfrs' => { 'secured' => 'SIGNED/UNSIGNED',
|
33
|
+
'authorization' => 'AUTHORIZED/UNAUTHORIZED'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
```
|
37
|
+
|
38
|
+
If a route is marked as AUTHORIZED, the route and the access manager set are registered with SoarAuthorization::Authorize.
|
39
|
+
|
40
|
+
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.
|
41
|
+
|
42
|
+
###Validation errors:
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
ArgumentError "detail must not be nil" if the detail parameter is nil
|
46
|
+
ArgumentError "path must be provided" if detail['path'] is nil
|
47
|
+
ArgumentError "description must be provided" if detail['description']
|
48
|
+
ArgumentError "service_name must be provided" if detail['service_name']
|
49
|
+
ArgumentError "method must be provided" if detail['method'] is nil
|
50
|
+
ArgumentError "params must be provided" if detail['params']
|
51
|
+
ArgumentError "nfrs must be provided" if detail['nfrs']
|
52
|
+
ArgumentError "nfrs['authorization'] must be provided" if detail['nfrs']['authorization'] is nil
|
53
|
+
ArgumentError "nfrs['secured'] must be provided" if detail['nfrs']['secured'] is nil
|
54
|
+
```
|
6
55
|
|
7
56
|
## Installation
|
8
57
|
|
@@ -22,18 +71,66 @@ Or install it yourself as:
|
|
22
71
|
|
23
72
|
## Usage
|
24
73
|
|
25
|
-
|
74
|
+
### RouterMeta
|
26
75
|
|
27
|
-
|
76
|
+
```ruby
|
77
|
+
class AuthenticatedRouterMeta < SoarScRouting::RouterMeta
|
78
|
+
def policy_am
|
79
|
+
@policy_am ||= SoarPolicyAccessManager::PolicyAccessManager.new(SoarSc::service_registry)
|
80
|
+
@policy_am
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_routing_table
|
84
|
+
# register_route({
|
85
|
+
# 'description' => 'Given a pattern, finds services matching the pattern and reports where they can be accessed',
|
86
|
+
# 'service_name' => 'where-is-it',
|
87
|
+
# 'path' => '/where-is-it',
|
88
|
+
# 'method' => 'get',
|
89
|
+
# 'params' => {
|
90
|
+
# 'pattern' => {
|
91
|
+
# 'required' => 'true', 'type' => 'string'
|
92
|
+
# }
|
93
|
+
# },
|
94
|
+
# 'nfrs' => {
|
95
|
+
# 'authorization' => 'AUTHORIZED',
|
96
|
+
# 'secured' => 'UNSIGNED'
|
97
|
+
# },
|
98
|
+
# 'view' => {
|
99
|
+
# 'renderer' => 'json',
|
100
|
+
# 'name' => 'where_is_it'
|
101
|
+
# },
|
102
|
+
# 'controller' => 'WhereIsIt'
|
103
|
+
# }, SoarSc::startup_flow_id)
|
104
|
+
end
|
105
|
+
|
106
|
+
def render_view(detail, http_code, body)
|
107
|
+
renderer = SoarSc::Renderer.new
|
108
|
+
renderer.render_view(detail, http_code, body)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
```
|
28
112
|
|
29
|
-
|
113
|
+
### BaseRouter
|
30
114
|
|
31
|
-
|
115
|
+
```ruby
|
116
|
+
class SoarScRouter < SoarScRouting::BaseRouter
|
117
|
+
def not_found
|
118
|
+
SoarSc::Web::Views::Default.not_found
|
119
|
+
end
|
120
|
+
|
121
|
+
def excepted(ex)
|
122
|
+
SoarSc::Web::Views::Default.error(ex)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
```
|
32
126
|
|
33
127
|
## Contributing
|
34
128
|
|
35
|
-
|
129
|
+
Please send feedback and comments to the author at:
|
130
|
+
|
131
|
+
Ernst van Graan <ernst.van.graan@hetzner.co.za>
|
36
132
|
|
133
|
+
This gem is sponsored by Hetzner (Pty) Ltd - http://hetzner.co.za
|
37
134
|
|
38
135
|
## License
|
39
136
|
|