예제 #1
0
def resync(environ, start_response):
    """
    Handle Re-sync requests
    """
    try:
        # Validate caller address
        if environ['REMOTE_ADDR'] not in settings['SYNC_POOL']:
            logger.error('Operation not permitted from IP %(REMOTE_ADDR)s',
                         environ)
            raise YKSyncError(
                'OPERATION_NOT_ALLOWED',
                'Remote IP %(REMOTE_ADDR)s it not in sync pool' % environ)
        # Parse query and check values
        resync_params = parse_querystring(environ['QUERY_STRING'])
        synclib = Sync()
        output = synclib.resync_local(resync_params)
        status_code = 200
        logger.info('Re-sync request by %s for keys: %s',
                    environ['REMOTE_ADDR'], resync_params['yk'])
    except YKSyncError as err:
        output = str(err)
        status_code = 401
    except Exception as err:
        logger.exception('ERROR: %s', err)
        output = ''
        status_code = 500
    finally:
        start_response(HTTP_STATUS_CODES[status_code],
                       [('Content-Type', 'text/plain')])
        return [output.encode()]
예제 #2
0
파일: wsgi.py 프로젝트: oriordan/yubistack
def resync(environ, start_response):
    """
    Handle Re-sync requests
    """
    try:
        # Validate caller address
        if environ['REMOTE_ADDR'] not in settings['SYNC_POOL']:
            logger.error('Operation not permitted from IP %(REMOTE_ADDR)s', environ)
            raise YKSyncError('OPERATION_NOT_ALLOWED',
                              'Remote IP %(REMOTE_ADDR)s it not in sync pool' % environ)
        # Parse query and check values
        resync_params = parse_querystring(environ['QUERY_STRING'])
        synclib = Sync()
        output = synclib.resync_local(resync_params)
        status_code = 200
        logger.info('Re-sync request by %s for keys: %s',
                    environ['REMOTE_ADDR'], resync_params['yk'])
    except YKSyncError as err:
        output = str(err)
        status_code = 401
    except Exception as err:
        logger.exception('ERROR: %s', err)
        output = ''
        status_code = 500
    finally:
        start_response(HTTP_STATUS_CODES[status_code], [('Content-Type', 'text/plain')])
        return [output.encode()]
예제 #3
0
파일: wsgi.py 프로젝트: oriordan/yubistack
def sync(environ, start_response):
    """
    Handle Sync requests
    """
    local_params = None
    try:
        # Validate caller address
        if environ['REMOTE_ADDR'] not in settings['SYNC_POOL']:
            logger.error('Operation not permitted from IP %(REMOTE_ADDR)s', environ)
            raise YKSyncError('OPERATION_NOT_ALLOWED',
                              'Remote IP %(REMOTE_ADDR)s it not in sync pool' % environ)
        sync_params = parse_querystring(environ['QUERY_STRING'])
        logger.info('[%s] Received sync request from %s (counter: %s, use: %s, nonce: %s)',
                    sync_params.get('yk_publicname'), environ['REMOTE_ADDR'],
                    sync_params.get('yk_counter'), sync_params.get('yk_use'),
                    sync_params.get('nonce'))
        synclib = Sync()
        local_params = synclib.sync_local(sync_params)
        output = 'OK'
        status_code = 200
    except YKSyncError as err:
        output = str(err)
        status_code = 401
    except Exception as err:
        logger.exception('ERROR: %s', err)
        output = 'BACKEND_ERROR'
        status_code = 500
    finally:
        return wsgi_response(output, start_response, apikey=''.encode(),
                             extra=local_params, status=status_code)
예제 #4
0
def sync(environ, start_response):
    """
    Handle Sync requests
    """
    local_params = None
    try:
        # Validate caller address
        if environ['REMOTE_ADDR'] not in settings['SYNC_POOL']:
            logger.error('Operation not permitted from IP %(REMOTE_ADDR)s',
                         environ)
            raise YKSyncError(
                'OPERATION_NOT_ALLOWED',
                'Remote IP %(REMOTE_ADDR)s it not in sync pool' % environ)
        sync_params = parse_querystring(environ['QUERY_STRING'])
        logger.info(
            '[%s] Received sync request from %s (counter: %s, use: %s, nonce: %s)',
            sync_params.get('yk_publicname'), environ['REMOTE_ADDR'],
            sync_params.get('yk_counter'), sync_params.get('yk_use'),
            sync_params.get('nonce'))
        synclib = Sync()
        local_params = synclib.sync_local(sync_params)
        output = 'OK'
        status_code = 200
    except YKSyncError as err:
        output = str(err)
        status_code = 401
    except Exception as err:
        logger.exception('ERROR: %s', err)
        output = 'BACKEND_ERROR'
        status_code = 500
    finally:
        return wsgi_response(output,
                             start_response,
                             apikey=''.encode(),
                             extra=local_params,
                             status=status_code)