Esempio n. 1
0
    def get_client(self):
        # Get the access keys configured from the config file
        if self.aws_access_key_id is None:
            self.aws_access_key_id = config.get('credentials', 'AWS_ACCESS_KEY_ID', fallback=None)
        if self.aws_secret_access_key is None:
            self.aws_secret_access_key = config.get('credentials', 'AWS_SECRET_ACCESS_KEY', fallback=None)

        # Get the access keys configured from the system
        if self.aws_access_key_id is None:
            self.aws_access_key_id = environ.get('AWS_ACCESS_KEY_ID', None)
        if self.aws_secret_access_key is None:
            self.aws_secret_access_key = environ.get('AWS_SECRET_ACCESS_KEY', None)

        if not self.aws_access_key_id or not self.aws_access_key_id:
            raise Exception('Missing AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY')

        # Get actual client
        self.api = boto3.client(
            self.api_name,
            # region_name= config.get(self.api_name, 'endpoint', fallback='eu-west-1'),
            # endpoint_url= config.get(self.api_name, 'endpoint', fallback='https://rekognition.eu-west-1.amazonaws.com'),
            # verify=self.verify,
            # aws_access_key_id=self.aws_access_key_id,
            # aws_secret_access_key=self.aws_secret_access_key
        )
        return self.api
Esempio n. 2
0
def setup_logging():
    '''
    Create logging based on settings in server.config. At least log to a
    logfile that has a maximum size.

    :return: None
    '''
    log_location = config.get('locations', 'log')
    if not os.path.exists(log_location):
        os.makedirs(log_location)

    # Determine logging level
    ll = config.get('server', 'logging_level')
    logging_level = logging.DEBUG
    if ll == 'debug':
        logging_level = logging.DEBUG
    elif ll == 'info':
        logging_level = logging.INFO

    # Create logger
    root = logging.getLogger()
    root.setLevel(logging_level)

    # Create logging file handler. Filesize limited, after that the start will
    # be overwritten
    log_formatter = logging.Formatter('%(asctime)s %(message)s',
                                      '%d-%m-%Y %H:%M:%S')

    # Add separate handler for errors
    my_handler_error = RotatingFileHandler(log_location + '/error.log',
                                           mode='a',
                                           maxBytes=config.getint(
                                               'server', 'max_logsize'),
                                           backupCount=2,
                                           encoding=None,
                                           delay=0)
    my_handler_error.setLevel(logging.ERROR)
    my_handler_error.setFormatter(log_formatter)
    root.addHandler(my_handler_error)

    my_handler = RotatingFileHandler(log_location + '/server.log',
                                     mode='a',
                                     maxBytes=config.getint(
                                         'server', 'max_logsize'),
                                     backupCount=2,
                                     encoding=None,
                                     delay=0)
    my_handler.setFormatter(log_formatter)
    root.addHandler(my_handler)

    # Create logging to stdout handler
    if config.getboolean('server', 'log_to_stdout'):
        ch = logging.StreamHandler(sys.stdout)
        root.addHandler(ch)
Esempio n. 3
0
def setup_logging():
    '''
    Create logging based on settings in server.config. At least log to a
    logfile that has a maximum size.

    :return: None
    '''
    log_location = config.get('locations', 'log')
    if not os.path.exists(log_location):
        os.makedirs(log_location)

    # Determine logging level
    ll = config.get('server', 'logging_level')
    logging_level = logging.DEBUG
    if ll == 'debug':
        logging_level = logging.DEBUG
    elif ll == 'info':
        logging_level = logging.INFO

    # Create logger
    root = logging.getLogger()
    root.setLevel(logging_level)

    # Create logging file handler. Filesize limited, after that the start will
    # be overwritten
    log_formatter = logging.Formatter('%(asctime)s %(message)s',
                                      '%d-%m-%Y %H:%M:%S')

    # Add separate handler for errors
    my_handler_error = RotatingFileHandler(
        log_location + '/error.log', mode='a',
        maxBytes=config.getint('server', 'max_logsize'), backupCount=2,
        encoding=None, delay=0)
    my_handler_error.setLevel(logging.ERROR)
    my_handler_error.setFormatter(log_formatter)
    root.addHandler(my_handler_error)

    my_handler = RotatingFileHandler(
        log_location + '/server.log', mode='a',
        maxBytes=config.getint('server', 'max_logsize'), backupCount=2,
        encoding=None, delay=0)
    my_handler.setFormatter(log_formatter)
    root.addHandler(my_handler)

    # Create logging to stdout handler
    if config.getboolean('server', 'log_to_stdout'):
        ch = logging.StreamHandler(sys.stdout)
        root.addHandler(ch)
Esempio n. 4
0
def setup_iot_client():
    '''
    Setup the client for the NMS
    '''
    backend_url = 'ws://%s:%s/API-ws/' % (config.get(
        'backend', 'host'), config.getint('backend', 'webport'))
    backend_client = IoTWebSocketClient()
    backend_client.connect(url=backend_url)
    return backend_client
Esempio n. 5
0
def setup_iot_client():
    '''
    Setup the client for the NMS
    '''
    backend_url = 'ws://%s:%s/API-ws/' % (config.get('backend',
                                                     'host'),
                                          config.getint('backend',
                                                        'webport'))
    backend_client = IoTWebSocketClient()
    backend_client.connect(url=backend_url)
    return backend_client
Esempio n. 6
0
    def run(self):
        '''
        Run the server.
        :return: None
        '''
        # Run setup
        setup_logging()
        setup_signal_handling()
        setup_database()
        http_server = setup_server()

        # Start servers

        # Prepare HTTP server
        ioloop = tornado.ioloop.IOLoop.instance()

        http_server.listen(config.get('server',  'webport'))
        logging.info("Launching Websocket listener")
        ioloop.start()
Esempio n. 7
0
    def run(self):
        '''
        Run the server.
        :return: None
        '''
        # Run setup
        setup_logging()
        setup_signal_handling()
        setup_database()
        http_server = setup_server()

        # Start servers

        # Prepare HTTP server
        ioloop = tornado.ioloop.IOLoop.instance()

        http_server.listen(config.get('server', 'webport'))
        logging.info("Launching Websocket listener")
        ioloop.start()