appfuel-service 0.3.4 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4fb6da63bfcf8f11729fc8d3d1162f2e20b02ca
4
- data.tar.gz: 552e1e5d59591828710d22828a7f5b280c0587a9
3
+ metadata.gz: 754067554ec7f6f0f75a223c0e07c2896c425223
4
+ data.tar.gz: 6e9575e427b7db96f1d3d4e6d99759d85e63564f
5
5
  SHA512:
6
- metadata.gz: 62eacc1270c059feb97429e1729c5c928d8a1d6b26ccd9c540a3ae5b25f8806625c1994b026702ad05cfff513d5755305603505c2edfa8a898b765227ef290d9
7
- data.tar.gz: 9d693988fc1459af6770bf5a32b24abe6121d61cb58d062f56f0bf5ad549f58865737239cd8e3fa95acf71068df44beadc1d845453fea0d6e492168386220780
6
+ metadata.gz: 942044d4e57fe313e3ccae40cd640a8c32d01d30b25d2ca34ec5f2bfe6624f1b7d76cf2467bd82da5bb9752804a15b48de058536381f987562f591425b5e6230
7
+ data.tar.gz: 995f0f97d82549e7225faf7938656a3791ea761d5a454fb675111fe3dc9dcd0bf1ef4317ae353a17b5a5215cf2ebbf4322bfb51cf6a10fb23e62993332f1a2e1
data/CHANGELOG.md CHANGED
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. (Pending ap
5
5
 
6
6
 
7
7
  # Releases
8
+ ## [[0.4.0]](https://github.com/rsb/appfuel/releases/tag/0.4.0) 2017-09-27
9
+ ### Added
10
+ - allow work to restrict action routes with `register`
11
+
8
12
  ## [[0.3.4]](https://github.com/rsb/appfuel/releases/tag/0.3.4) 2017-09-19
9
13
  ### Fixed
10
14
  - standard config settings to logfile instead of log
@@ -1,5 +1,5 @@
1
1
  module Appfuel
2
2
  module Service
3
- VERSION = "0.3.4"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -16,6 +16,8 @@ module Appfuel
16
16
  key = klass.container_class_path
17
17
  container.register(key, klass)
18
18
  container[consumer_key] << key
19
+
20
+ @allow_all_actions = true
19
21
  end
20
22
 
21
23
  def top_container_key
@@ -25,6 +27,31 @@ module Appfuel
25
27
  def container_class_type
26
28
  'consumers'
27
29
  end
30
+
31
+ def allow_all_action?
32
+ @allow_all_actions
33
+ end
34
+
35
+ def register(routes)
36
+ @allow_all_actions = false
37
+
38
+ routes = [routes] if routes.is_a?(String)
39
+
40
+ unless routes.is_a?(Array)
41
+ fail "register accepts only String or Array"
42
+ end
43
+ @registered_actions = routes
44
+ end
45
+
46
+ def registered_actions
47
+ @registered_actions ||= []
48
+ end
49
+
50
+ def registered?(route)
51
+ return true if allowed_all_actions? == true
52
+
53
+ registered_actions.include?(route)
54
+ end
28
55
  end
29
56
 
30
57
  # Sneakers worker hook to handle messages from RabbitMQ
@@ -43,6 +70,11 @@ module Appfuel
43
70
  return ack!
44
71
  end
45
72
 
73
+ handle_invalid_routes(request.action_route) do |exception|
74
+ handle_exception("dispatch not allowed", exception, request)
75
+ return ack!
76
+ end
77
+
46
78
  begin
47
79
  response = dispatch(request, app_container)
48
80
  rescue => e
@@ -61,7 +93,6 @@ module Appfuel
61
93
  ack!
62
94
  end
63
95
 
64
-
65
96
  def rpc?(properties)
66
97
  properties.correlation_id && properties.reply_to
67
98
  end
@@ -87,6 +118,21 @@ module Appfuel
87
118
 
88
119
  private
89
120
 
121
+ def handle_invalid_routes(route)
122
+ if self.class.registered_actions.empty? ||
123
+ self.class.registered?(request.action_route)
124
+ return false
125
+ end
126
+
127
+ msg = "route #{request.action_route} not allowed for queue #{queue}"
128
+ e = RuntimeError.new(msg)
129
+ if block_given?
130
+ yield e
131
+ else
132
+ return e
133
+ end
134
+ end
135
+
90
136
  def handle_exception(label, e, request)
91
137
  err_msg = "[queue #{queue}] #{label}: #{e.message}"
92
138
  logger.error err_msg
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appfuel-service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Scott-Buccleuch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-19 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: appfuel