###############################################################################
#
# The MIT License (MIT)
#
# Copyright (c) typedef int GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
###############################################################################
import json
from autobahn import util
from autobahn.wamp.exception import ProtocolError
__all__ = (
"DEFAULT_CLIENT_ROLES",
"ROLE_NAME_TO_CLASS",
"RoleBrokerFeatures",
"RoleCalleeFeatures",
"RoleCallerFeatures",
"RoleDealerFeatures",
"RoleFeatures",
"RolePublisherFeatures",
"RoleSubscriberFeatures",
)
[docs]
class RoleFeatures(util.EqualityMixin):
"""
Base class for WAMP role features.
"""
[docs]
def __str__(self):
return json.dumps(self.__dict__)
[docs]
def __repr__(self):
configured_options = {}
for k, v in self.__dict__.items():
if v is not None:
configured_options[k] = v
return "{0}({1})".format(
self.ROLE,
", ".join([k + "=" + str(v) for k, v in configured_options.items()]),
)
[docs]
def _check_all_bool(self):
# check feature attributes
for k in self.__dict__:
if not k.startswith("_") and k != "ROLE":
if getattr(self, k) is not None and type(getattr(self, k)) != bool:
raise ProtocolError(
"invalid type {0} for feature '{1}' for role '{2}'".format(
getattr(self, k), k, self.ROLE
)
)
[docs]
class RoleBrokerFeatures(RoleFeatures):
"""
WAMP broker role features.
"""
def __init__(
self,
publisher_identification=None,
publication_trustlevels=None,
pattern_based_subscription=None,
session_meta_api=None,
subscription_meta_api=None,
subscriber_blackwhite_listing=None,
publisher_exclusion=None,
subscription_revocation=None,
event_history=None,
payload_transparency=None,
x_acknowledged_event_delivery=None,
payload_encryption_cryptobox=None,
event_retention=None,
**kwargs,
):
[docs]
self.publisher_identification = publisher_identification
[docs]
self.publication_trustlevels = publication_trustlevels
[docs]
self.pattern_based_subscription = pattern_based_subscription
[docs]
self.subscriber_blackwhite_listing = subscriber_blackwhite_listing
[docs]
self.publisher_exclusion = publisher_exclusion
[docs]
self.subscription_revocation = subscription_revocation
[docs]
self.event_history = event_history
[docs]
self.payload_transparency = payload_transparency
[docs]
self.x_acknowledged_event_delivery = x_acknowledged_event_delivery
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
[docs]
self.event_retention = event_retention
self._check_all_bool()
[docs]
class RoleSubscriberFeatures(RoleFeatures):
"""
WAMP subscriber role features.
"""
def __init__(
self,
publisher_identification=None,
publication_trustlevels=None,
pattern_based_subscription=None,
subscription_revocation=None,
event_history=None,
payload_transparency=None,
payload_encryption_cryptobox=None,
**kwargs,
):
[docs]
self.publisher_identification = publisher_identification
[docs]
self.publication_trustlevels = publication_trustlevels
[docs]
self.pattern_based_subscription = pattern_based_subscription
[docs]
self.subscription_revocation = subscription_revocation
[docs]
self.event_history = event_history
[docs]
self.payload_transparency = payload_transparency
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
self._check_all_bool()
[docs]
class RolePublisherFeatures(RoleFeatures):
"""
WAMP publisher role features.
"""
def __init__(
self,
publisher_identification=None,
subscriber_blackwhite_listing=None,
publisher_exclusion=None,
payload_transparency=None,
x_acknowledged_event_delivery=None,
payload_encryption_cryptobox=None,
**kwargs,
):
[docs]
self.publisher_identification = publisher_identification
[docs]
self.subscriber_blackwhite_listing = subscriber_blackwhite_listing
[docs]
self.publisher_exclusion = publisher_exclusion
[docs]
self.payload_transparency = payload_transparency
[docs]
self.x_acknowledged_event_delivery = x_acknowledged_event_delivery
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
self._check_all_bool()
[docs]
class RoleDealerFeatures(RoleFeatures):
"""
WAMP dealer role features.
"""
def __init__(
self,
caller_identification=None,
call_trustlevels=None,
pattern_based_registration=None,
session_meta_api=None,
registration_meta_api=None,
shared_registration=None,
call_timeout=None,
call_canceling=None,
progressive_call_results=None,
registration_revocation=None,
payload_transparency=None,
testament_meta_api=None,
payload_encryption_cryptobox=None,
**kwargs,
):
[docs]
self.caller_identification = caller_identification
[docs]
self.call_trustlevels = call_trustlevels
[docs]
self.pattern_based_registration = pattern_based_registration
[docs]
self.shared_registration = shared_registration
[docs]
self.call_timeout = call_timeout
[docs]
self.call_canceling = call_canceling
[docs]
self.progressive_call_results = progressive_call_results
[docs]
self.registration_revocation = registration_revocation
[docs]
self.payload_transparency = payload_transparency
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
self._check_all_bool()
[docs]
class RoleCallerFeatures(RoleFeatures):
"""
WAMP caller role features.
"""
def __init__(
self,
caller_identification=None,
call_timeout=None,
call_canceling=None,
progressive_call_results=None,
payload_transparency=None,
payload_encryption_cryptobox=None,
**kwargs,
):
[docs]
self.caller_identification = caller_identification
[docs]
self.call_timeout = call_timeout
[docs]
self.call_canceling = call_canceling
[docs]
self.progressive_call_results = progressive_call_results
[docs]
self.payload_transparency = payload_transparency
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
self._check_all_bool()
[docs]
class RoleCalleeFeatures(RoleFeatures):
"""
WAMP callee role features.
"""
def __init__(
self,
caller_identification=None,
call_trustlevels=None,
pattern_based_registration=None,
shared_registration=None,
call_timeout=None,
call_canceling=None,
progressive_call_results=None,
registration_revocation=None,
payload_transparency=None,
payload_encryption_cryptobox=None,
**kwargs,
):
[docs]
self.caller_identification = caller_identification
[docs]
self.call_trustlevels = call_trustlevels
[docs]
self.pattern_based_registration = pattern_based_registration
[docs]
self.shared_registration = shared_registration
[docs]
self.call_timeout = call_timeout
[docs]
self.call_canceling = call_canceling
[docs]
self.progressive_call_results = progressive_call_results
[docs]
self.registration_revocation = registration_revocation
[docs]
self.payload_transparency = payload_transparency
[docs]
self.payload_encryption_cryptobox = payload_encryption_cryptobox
self._check_all_bool()
# map of role names to role class
[docs]
ROLE_NAME_TO_CLASS = {
"broker": RoleBrokerFeatures,
"subscriber": RoleSubscriberFeatures,
"publisher": RolePublisherFeatures,
"dealer": RoleDealerFeatures,
"caller": RoleCallerFeatures,
"callee": RoleCalleeFeatures,
}
# default role features for client roles supported
[docs]
DEFAULT_CLIENT_ROLES = {
"subscriber": RoleSubscriberFeatures(
publisher_identification=True,
pattern_based_subscription=True,
subscription_revocation=True,
payload_transparency=True,
payload_encryption_cryptobox=True,
),
"publisher": RolePublisherFeatures(
publisher_identification=True,
subscriber_blackwhite_listing=True,
publisher_exclusion=True,
payload_transparency=True,
x_acknowledged_event_delivery=True,
payload_encryption_cryptobox=True,
),
"caller": RoleCallerFeatures(
caller_identification=True,
progressive_call_results=True,
payload_transparency=True,
payload_encryption_cryptobox=True,
call_canceling=True,
),
"callee": RoleCalleeFeatures(
caller_identification=True,
pattern_based_registration=True,
shared_registration=True,
progressive_call_results=True,
registration_revocation=True,
payload_transparency=True,
payload_encryption_cryptobox=True,
call_canceling=True,
),
}