Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

role.py 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. ###############################################################################
  2. #
  3. # The MIT License (MIT)
  4. #
  5. # Copyright (c) typedef int GmbH
  6. #
  7. # Permission is hereby granted, free of charge, to any person obtaining a copy
  8. # of this software and associated documentation files (the "Software"), to deal
  9. # in the Software without restriction, including without limitation the rights
  10. # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. # copies of the Software, and to permit persons to whom the Software is
  12. # furnished to do so, subject to the following conditions:
  13. #
  14. # The above copyright notice and this permission notice shall be included in
  15. # all copies or substantial portions of the Software.
  16. #
  17. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. # THE SOFTWARE.
  24. #
  25. ###############################################################################
  26. import json
  27. from autobahn import util
  28. from autobahn.wamp.exception import ProtocolError
  29. __all__ = (
  30. 'RoleFeatures',
  31. 'RoleBrokerFeatures',
  32. 'RoleSubscriberFeatures',
  33. 'RolePublisherFeatures',
  34. 'RoleDealerFeatures',
  35. 'RoleCallerFeatures',
  36. 'RoleCalleeFeatures',
  37. 'ROLE_NAME_TO_CLASS',
  38. 'DEFAULT_CLIENT_ROLES',
  39. )
  40. class RoleFeatures(util.EqualityMixin):
  41. """
  42. Base class for WAMP role features.
  43. """
  44. ROLE = None
  45. def __str__(self):
  46. return json.dumps(self.__dict__)
  47. def __repr__(self):
  48. configured_options = {}
  49. for k, v in self.__dict__.items():
  50. if v is not None:
  51. configured_options[k] = v
  52. return "{0}({1})".format(self.ROLE, ", ".join([k + '=' + str(v)
  53. for k, v in configured_options.items()]))
  54. def _check_all_bool(self):
  55. # check feature attributes
  56. for k in self.__dict__:
  57. if not k.startswith('_') and k != 'ROLE':
  58. if getattr(self, k) is not None and type(getattr(self, k)) != bool:
  59. raise ProtocolError("invalid type {0} for feature '{1}' for role '{2}'".format(getattr(self, k), k, self.ROLE))
  60. class RoleBrokerFeatures(RoleFeatures):
  61. """
  62. WAMP broker role features.
  63. """
  64. ROLE = 'broker'
  65. def __init__(self,
  66. publisher_identification=None,
  67. publication_trustlevels=None,
  68. pattern_based_subscription=None,
  69. session_meta_api=None,
  70. subscription_meta_api=None,
  71. subscriber_blackwhite_listing=None,
  72. publisher_exclusion=None,
  73. subscription_revocation=None,
  74. event_history=None,
  75. payload_transparency=None,
  76. x_acknowledged_event_delivery=None,
  77. payload_encryption_cryptobox=None,
  78. event_retention=None,
  79. **kwargs):
  80. self.publisher_identification = publisher_identification
  81. self.publication_trustlevels = publication_trustlevels
  82. self.pattern_based_subscription = pattern_based_subscription
  83. self.session_meta_api = session_meta_api
  84. self.subscription_meta_api = subscription_meta_api
  85. self.subscriber_blackwhite_listing = subscriber_blackwhite_listing
  86. self.publisher_exclusion = publisher_exclusion
  87. self.subscription_revocation = subscription_revocation
  88. self.event_history = event_history
  89. self.payload_transparency = payload_transparency
  90. self.x_acknowledged_event_delivery = x_acknowledged_event_delivery
  91. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  92. self.event_retention = event_retention
  93. self._check_all_bool()
  94. class RoleSubscriberFeatures(RoleFeatures):
  95. """
  96. WAMP subscriber role features.
  97. """
  98. ROLE = 'subscriber'
  99. def __init__(self,
  100. publisher_identification=None,
  101. publication_trustlevels=None,
  102. pattern_based_subscription=None,
  103. subscription_revocation=None,
  104. event_history=None,
  105. payload_transparency=None,
  106. payload_encryption_cryptobox=None,
  107. **kwargs):
  108. self.publisher_identification = publisher_identification
  109. self.publication_trustlevels = publication_trustlevels
  110. self.pattern_based_subscription = pattern_based_subscription
  111. self.subscription_revocation = subscription_revocation
  112. self.event_history = event_history
  113. self.payload_transparency = payload_transparency
  114. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  115. self._check_all_bool()
  116. class RolePublisherFeatures(RoleFeatures):
  117. """
  118. WAMP publisher role features.
  119. """
  120. ROLE = 'publisher'
  121. def __init__(self,
  122. publisher_identification=None,
  123. subscriber_blackwhite_listing=None,
  124. publisher_exclusion=None,
  125. payload_transparency=None,
  126. x_acknowledged_event_delivery=None,
  127. payload_encryption_cryptobox=None,
  128. **kwargs):
  129. self.publisher_identification = publisher_identification
  130. self.subscriber_blackwhite_listing = subscriber_blackwhite_listing
  131. self.publisher_exclusion = publisher_exclusion
  132. self.payload_transparency = payload_transparency
  133. self.x_acknowledged_event_delivery = x_acknowledged_event_delivery
  134. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  135. self._check_all_bool()
  136. class RoleDealerFeatures(RoleFeatures):
  137. """
  138. WAMP dealer role features.
  139. """
  140. ROLE = 'dealer'
  141. def __init__(self,
  142. caller_identification=None,
  143. call_trustlevels=None,
  144. pattern_based_registration=None,
  145. session_meta_api=None,
  146. registration_meta_api=None,
  147. shared_registration=None,
  148. call_timeout=None,
  149. call_canceling=None,
  150. progressive_call_results=None,
  151. registration_revocation=None,
  152. payload_transparency=None,
  153. testament_meta_api=None,
  154. payload_encryption_cryptobox=None,
  155. **kwargs):
  156. self.caller_identification = caller_identification
  157. self.call_trustlevels = call_trustlevels
  158. self.pattern_based_registration = pattern_based_registration
  159. self.session_meta_api = session_meta_api
  160. self.registration_meta_api = registration_meta_api
  161. self.shared_registration = shared_registration
  162. self.call_timeout = call_timeout
  163. self.call_canceling = call_canceling
  164. self.progressive_call_results = progressive_call_results
  165. self.registration_revocation = registration_revocation
  166. self.payload_transparency = payload_transparency
  167. self.testament_meta_api = testament_meta_api
  168. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  169. self._check_all_bool()
  170. class RoleCallerFeatures(RoleFeatures):
  171. """
  172. WAMP caller role features.
  173. """
  174. ROLE = 'caller'
  175. def __init__(self,
  176. caller_identification=None,
  177. call_timeout=None,
  178. call_canceling=None,
  179. progressive_call_results=None,
  180. payload_transparency=None,
  181. payload_encryption_cryptobox=None,
  182. **kwargs):
  183. self.caller_identification = caller_identification
  184. self.call_timeout = call_timeout
  185. self.call_canceling = call_canceling
  186. self.progressive_call_results = progressive_call_results
  187. self.payload_transparency = payload_transparency
  188. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  189. self._check_all_bool()
  190. class RoleCalleeFeatures(RoleFeatures):
  191. """
  192. WAMP callee role features.
  193. """
  194. ROLE = 'callee'
  195. def __init__(self,
  196. caller_identification=None,
  197. call_trustlevels=None,
  198. pattern_based_registration=None,
  199. shared_registration=None,
  200. call_timeout=None,
  201. call_canceling=None,
  202. progressive_call_results=None,
  203. registration_revocation=None,
  204. payload_transparency=None,
  205. payload_encryption_cryptobox=None,
  206. **kwargs):
  207. self.caller_identification = caller_identification
  208. self.call_trustlevels = call_trustlevels
  209. self.pattern_based_registration = pattern_based_registration
  210. self.shared_registration = shared_registration
  211. self.call_timeout = call_timeout
  212. self.call_canceling = call_canceling
  213. self.progressive_call_results = progressive_call_results
  214. self.registration_revocation = registration_revocation
  215. self.payload_transparency = payload_transparency
  216. self.payload_encryption_cryptobox = payload_encryption_cryptobox
  217. self._check_all_bool()
  218. # map of role names to role class
  219. ROLE_NAME_TO_CLASS = {
  220. 'broker': RoleBrokerFeatures,
  221. 'subscriber': RoleSubscriberFeatures,
  222. 'publisher': RolePublisherFeatures,
  223. 'dealer': RoleDealerFeatures,
  224. 'caller': RoleCallerFeatures,
  225. 'callee': RoleCalleeFeatures,
  226. }
  227. # default role features for client roles supported
  228. DEFAULT_CLIENT_ROLES = {
  229. 'subscriber': RoleSubscriberFeatures(
  230. publisher_identification=True,
  231. pattern_based_subscription=True,
  232. subscription_revocation=True,
  233. payload_transparency=True,
  234. payload_encryption_cryptobox=True,
  235. ),
  236. 'publisher': RolePublisherFeatures(
  237. publisher_identification=True,
  238. subscriber_blackwhite_listing=True,
  239. publisher_exclusion=True,
  240. payload_transparency=True,
  241. x_acknowledged_event_delivery=True,
  242. payload_encryption_cryptobox=True,
  243. ),
  244. 'caller': RoleCallerFeatures(
  245. caller_identification=True,
  246. progressive_call_results=True,
  247. payload_transparency=True,
  248. payload_encryption_cryptobox=True,
  249. call_canceling=True,
  250. ),
  251. 'callee': RoleCalleeFeatures(
  252. caller_identification=True,
  253. pattern_based_registration=True,
  254. shared_registration=True,
  255. progressive_call_results=True,
  256. registration_revocation=True,
  257. payload_transparency=True,
  258. payload_encryption_cryptobox=True,
  259. call_canceling=True,
  260. ),
  261. }