How to use the crossbar.common.checkconfig.InvalidConfigException function in crossbar

To help you get started, we’ve selected a few crossbar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
check_listening_transport_web(transport)

    elif ttype == 'mqtt':
        check_listening_transport_mqtt(transport)

    elif ttype == 'flashpolicy':
        check_listening_transport_flashpolicy(transport)

    elif ttype == 'websocket.testee':
        check_listening_transport_websocket_testee(transport)

    elif ttype == 'stream.testee':
        check_listening_transport_stream_testee(transport)

    else:
        raise InvalidConfigException('logic error')
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
if not isinstance(options, Mapping):
        raise InvalidConfigException(
            "Realm 'options' must be a dict"
        )
    for arg, val in options.items():
        if arg not in ['event_dispatching_chunk_size', 'uri_check', 'enable_meta_api', 'bridge_meta_api']:
            raise InvalidConfigException(
                "Unknown realm option '{}'".format(arg)
            )
    if 'event_dispatching_chunk_size' in options:
        try:
            edcs = int(options['event_dispatching_chunk_size'])
            if edcs <= 0:
                raise ValueError("too small")
        except ValueError:
            raise InvalidConfigException(
                "Realm option 'event_dispatching_chunk_size' must be a positive int"
            )

    if 'enable_meta_api' in options:
        if type(options['enable_meta_api']) != bool:
            raise InvalidConfigException("Invalid type {} for enable_meta_api in realm options".format(type(options['enable_meta_api'])))

    if 'bridge_meta_api' in options:
        if type(options['bridge_meta_api']) != bool:
            raise InvalidConfigException("Invalid type {} for bridge_meta_api in realm options".format(type(options['bridge_meta_api'])))
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
check_listening_endpoint(manhole['endpoint'])

    if 'users' not in manhole:
        raise InvalidConfigException("missing mandatory attribute 'users' in Manhole item\n\n{}".format(pformat(manhole)))

    users = manhole['users']
    if not isinstance(users, Sequence):
        raise InvalidConfigException("'manhole.users' items must be lists ({} encountered)\n\n{}".format(type(users), pformat(users)))

    for user in users:
        if not isinstance(user, Mapping):
            raise InvalidConfigException("'manhole.users.user' items must be dictionaries ({} encountered)\n\n{}".format(type(user), pformat(user)))

        for k in user:
            if k not in ['user', 'password']:
                raise InvalidConfigException("encountered unknown attribute '{}' in manhole.users.user".format(k))

        if 'user' not in user:
            raise InvalidConfigException("missing mandatory attribute 'user' in Manhole user item\n\n{}".format(pformat(user)))

        if 'password' not in user:
            raise InvalidConfigException("missing mandatory attribute 'password' in Manhole user item\n\n{}".format(pformat(user)))
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_connecting_transport_rawsocket(personality, transport):
    """
    Check a connecting RawSocket-WAMP transport configuration.

    https://github.com/crossbario/crossbar/blob/master/docs/pages/administration/router/transport/RawSocket-Transport.md

    :param transport: The configuration item to check.
    :type transport: dict
    """
    for k in transport:
        if k not in ['id', 'type', 'endpoint', 'serializer', 'url', 'debug']:
            raise InvalidConfigException("encountered unknown attribute '{}' in RawSocket transport configuration".format(k))

    if 'id' in transport:
        check_id(transport['id'])

    if 'endpoint' not in transport:
        raise InvalidConfigException("missing mandatory attribute 'endpoint' in RawSocket transport item\n\n{}".format(pformat(transport)))

    personality.check_connecting_endpoint(personality, transport['endpoint'])

    if 'serializer' not in transport:
        raise InvalidConfigException("missing mandatory attribute 'serializer' in RawSocket transport item\n\n{}".format(pformat(transport)))

    serializer = transport['serializer']
    if not isinstance(serializer, str):
        raise InvalidConfigException("'serializer' in RawSocket transport configuration must be a string ({} encountered)".format(type(serializer)))
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_connections(connections):
    """
    Connections can be present in controller, router and container processes.
    """
    if not isinstance(connections, Sequence):
        raise InvalidConfigException("'connections' items must be lists ({} encountered)".format(type(connections)))

    for i, connection in enumerate(connections):
        log.debug("Checking connection item {item} ..", item=i)
        check_connection(connection)
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_router_component(component):
    """
    Check a component configuration for a component running side-by-side with
    a router.

    https://github.com/crossbario/crossbar/blob/master/docs/pages/administration/worker/Router-Configuration.md

    :param component: The component configuration.
    :type component: dict
    """
    if not isinstance(component, Mapping):
        raise InvalidConfigException("components must be dictionaries ({} encountered)".format(type(component)))

    if 'type' not in component:
        raise InvalidConfigException("missing mandatory attribute 'type' in component")

    ctype = component['type']
    if ctype not in ['wamplet', 'class', 'function']:
        raise InvalidConfigException("invalid value '{}' for component type".format(ctype))

    if ctype == 'wamplet':
        check_dict_args({
            'id': (False, [six.text_type]),
            'type': (True, [six.text_type]),
            'realm': (True, [six.text_type]),
            'role': (False, [six.text_type]),
            'references': (False, [Sequence]),

            'package': (True, [six.text_type]),
            'entrypoint': (True, [six.text_type]),
            'extra': (False, None),
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_endpoint_timeout(timeout):
    """
    Check a connecting endpoint timeout parameter.

    :param timeout: The timeout (seconds) to check.
    :type timeout: int
    """
    if type(timeout) not in six.integer_types:
        raise InvalidConfigException("'timeout' attribute in endpoint must be integer ({} encountered)".format(type(timeout)))
    if timeout < 0 or timeout > 600:
        raise InvalidConfigException("invalid value {} for 'timeout' attribute in endpoint".format(timeout))
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_realm_name(name):
    """
    Check a realm name.
    """
    if not isinstance(name, six.text_type):
        raise InvalidConfigException(u'invalid realm name "{}" - type must be string, was {}'.format(name, type(name)))
    if not _REALM_NAME_PAT.match(name):
        raise InvalidConfigException(u'invalid realm name "{}" - must match regular expression {}'.format(name, _REALM_NAME_PAT_STR))
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_or_raise_uri(value, message):
    if not isinstance(value, six.text_type):
        raise InvalidConfigException("{}: invalid type {} for URI".format(message, type(value)))
    if not _URI_PAT_STRICT_NON_EMPTY.match(value):
        raise InvalidConfigException("{}: invalid value '{}' for URI".format(message, value))
    return value
github crossbario / crossbar / crossbar / common / checkconfig.py View on Github external
def check_dict_args(spec, config, msg):
    """
    Check the arguments of C{config} according to C{spec}.

    C{spec} is a dict, with the key mapping to the config and the value being a
    2-tuple, for which the first item being whether or not it is mandatory, and
    the second being a list of types of which the config item can be.
    """
    if not isinstance(config, Mapping):
        raise InvalidConfigException("{} - invalid type for configuration item - expected dict, got {}".format(msg, type(config).__name__))

    for k in config:
        if k not in spec:
            raise InvalidConfigException("{} - encountered unknown attribute '{}'".format(msg, k))
        if spec[k][1]:
            valid_type = False
            for t in spec[k][1]:
                if isinstance(config[k], t):
                    # We're special-casing Sequence here, because in
                    # general if we say a Sequence is okay, we do NOT
                    # want strings to be allowed but Python says that
                    # "isinstance('foo', Sequence) == True"
                    if t is Sequence:
                        if not isinstance(config[k], (str, str)):
                            valid_type = True
                            break
                    else:
                        valid_type = True
                        break
            if not valid_type: