Beispiel #1
0
def serve(port):
    """Run a development api server. Don't use this in production."""
    try:
        port = schema.And(
            schema.Use(int),
            lambda n: MIN_PORT_NUMBER <= n <= MAX_PORT_NUMBER).validate(port)
    except schema.SchemaError:
        raise InvalidAPIArgumentsException(
            'Error: Invaid port. Must be in the range 1-65535.')
    except Exception as e:
        sys.exit('Unxpected Error!!! \n %s' % e)
    """Start the HIL API server"""
    config.setup()
    if cfg.has_option('devel', 'debug'):
        debug = cfg.getboolean('devel', 'debug')
    else:
        debug = False
    # We need to import api here so that the functions within it get registered
    # (via `rest_call`), though we don't use it directly:
    # pylint: disable=unused-variable
    from hil import api, rest
    server.init()
    migrations.check_db_schema()
    server.stop_orphan_consoles()
    rest.serve(port, debug=debug)
Beispiel #2
0
def should_save(switch_obj):
    """checks the config file to see if switch should save or not"""
    switch_ext = switch_obj.__class__.__module__
    if cfg.has_option(switch_ext, 'save'):
        if not cfg.getboolean(switch_ext, 'save'):
            return False
    return True
Beispiel #3
0
def should_save(switch_obj):
    """checks the config file to see if switch should save or not"""
    switch_ext = switch_obj.__class__.__module__
    if cfg.has_option(switch_ext, 'save'):
        if not cfg.getboolean(switch_ext, 'save'):
            return False
    return True
Beispiel #4
0
    def _should_save(self, switch_type):
        """checks the config file to see if switch should save or not"""

        switch_ext = 'hil.ext.switches.' + switch_type
        if cfg.has_option(switch_ext, 'save'):
            if not cfg.getboolean(switch_ext, 'save'):
                return False
        return True
Beispiel #5
0
    def _should_save(self, switch_type):
        """checks the config file to see if switch should save or not"""

        switch_ext = 'hil.ext.switches.' + switch_type
        if cfg.has_option(switch_ext, 'save'):
            if not cfg.getboolean(switch_ext, 'save'):
                return False
        return True
Beispiel #6
0
def init_auth():
    ok = auth.get_auth_backend().authenticate()
    if cfg.has_option('auth', 'require_authentication'):
        require_auth = cfg.getboolean('auth', 'require_authentication')
    else:
        require_auth = True
    if not ok and require_auth:
        raise AuthorizationError("Authentication failed. Authentication "
                                 "is required to use this service.")
Beispiel #7
0
def init_auth():
    """Process authentication.

    This invokes the auth backend. If HIL is configured to *require*
    authentication, and authentication fails, it raises an
    AuthorizationError.
    """
    ok = auth.get_auth_backend().authenticate()
    if cfg.has_option('auth', 'require_authentication'):
        require_auth = cfg.getboolean('auth', 'require_authentication')
    else:
        require_auth = True
    if not ok and require_auth:
        raise AuthorizationError("Authentication failed. Authentication "
                                 "is required to use this service.")
Beispiel #8
0
def init_auth():
    """Process authentication.

    This invokes the auth backend. If HIL is configured to *require*
    authentication, and authentication fails, it raises an
    AuthorizationError.
    """
    ok = auth.get_auth_backend().authenticate()
    if cfg.has_option('auth', 'require_authentication'):
        require_auth = cfg.getboolean('auth', 'require_authentication')
    else:
        require_auth = True
    if not ok and require_auth:
        raise AuthorizationError("Authentication failed. Authentication "
                                 "is required to use this service.")