Пример #1
0
def save_patch():
    """ Function to cache a patch in funsize """
    required_params = ('sha_from', 'sha_to')
    if not all(p in flask.request.form.keys() for p in required_params):
        log.info('Parameters could not be validated')
        flask.abort(400)

    files = flask.request.files
    if 'patch_file' not in files.keys():
        log.debug('Parameters passed could not be found on disk')
        flask.abort(400)
    storage = files.get('patch_file')

    form = flask.request.form
    sha_from, sha_to = form['sha_from'], form['sha_to']
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Saving patch file to cache with key %s', identifier)
    cache.save(storage.stream, 'patch', identifier)

    url = flask.url_for('get_patch', sha_from=sha_from, sha_to=sha_to)
    return flask.Response(
        json.dumps({"result": url}),
        status=200,
        mimetype='application/json')
Пример #2
0
def get_patch(sha_from, sha_to):
    """ Function to return a patch from cache """
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Looking up record with identifier %s', identifier)
    if not cache.exists('patch', identifier):
        log.info('Invalid partial request')
        resp = flask.Response(
            json.dumps(
                {"result": "Patch with identifier %s not found" % identifier}),
            status=404,
        )
        return resp

    log.info('Patch found, retrieving ...')
    return cache.retrieve_or_redirect('patch', identifier)
Пример #3
0
def get_patch(sha_from, sha_to):
    """ Function to return a patch from cache """
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Looking up record with identifier %s', identifier)
    if not cache.exists('patch', identifier):
        log.info('Invalid partial request')
        resp = flask.Response(
            json.dumps({
                "result": "Patch with identifier %s not found" % identifier
            }),
            status=404,
        )
        return resp

    log.info('Patch found, retrieving ...')
    return cache.retrieve_or_redirect('patch', identifier)
Пример #4
0
def trigger_partial():
    """ Function to trigger a  partial generation """
    required_params = (
        'mar_from', 'sha_from',
        'mar_to', 'sha_to',
        'channel_id', 'product_version')
    form = flask.request.form
    if not all(p in form.keys() for p in required_params):
        log.info('Missing parameters from POST form call')
        flask.abort(400)

    mar_from = form['mar_from']
    sha_from = form['sha_from']
    mar_to = form['mar_to']
    sha_to = form['sha_to']
    channel_id = form['channel_id']
    product_version = form['product_version']

    identifier = _get_identifier(sha_from, sha_to)
    url = flask.url_for('get_partial', identifier=identifier)

    if cache.exists('partial', identifier):
        log.info('Partial has already been triggered/generated')
        return flask.Response(json.dumps({"result": url}), status=201,
                              mimetype='application/json')
    try:
        cache.save_blank_file('partial', identifier)
    except:
        log.error('Error processing trigger request for URL: %s\n', url)
        return flask.Response(
            json.dumps({"result": "Error while processing request %s" % url}),
            status=500,
            mimetypge='application/json'
        )

    tasks.build_partial_mar.delay(mar_to, sha_to, mar_from, sha_from,
                                  identifier, channel_id, product_version)
    log.debug("Task submitted")
    return flask.Response(
        json.dumps({"result": url}),
        status=202,
        mimetype='application/json'
    )
Пример #5
0
def trigger_partial():
    """ Function to trigger a  partial generation """
    required_params = ('mar_from', 'sha_from', 'mar_to', 'sha_to',
                       'channel_id', 'product_version')
    form = flask.request.form
    if not all(p in form.keys() for p in required_params):
        log.info('Missing parameters from POST form call')
        flask.abort(400)

    mar_from = form['mar_from']
    sha_from = form['sha_from']
    mar_to = form['mar_to']
    sha_to = form['sha_to']
    channel_id = form['channel_id']
    product_version = form['product_version']

    identifier = _get_identifier(sha_from, sha_to)
    url = flask.url_for('get_partial', identifier=identifier)

    if cache.exists('partial', identifier):
        log.info('Partial has already been triggered/generated')
        return flask.Response(json.dumps({"result": url}),
                              status=201,
                              mimetype='application/json')
    try:
        cache.save_blank_file('partial', identifier)
    except:
        log.error('Error processing trigger request for URL: %s\n', url)
        return flask.Response(json.dumps(
            {"result": "Error while processing request %s" % url}),
                              status=500,
                              mimetypge='application/json')

    tasks.build_partial_mar.delay(mar_to, sha_to, mar_from, sha_from,
                                  identifier, channel_id, product_version)
    log.debug("Task submitted")
    return flask.Response(json.dumps({"result": url}),
                          status=202,
                          mimetype='application/json')
Пример #6
0
def save_patch():
    """ Function to cache a patch in funsize """
    required_params = ('sha_from', 'sha_to')
    if not all(p in flask.request.form.keys() for p in required_params):
        log.info('Parameters could not be validated')
        flask.abort(400)

    files = flask.request.files
    if 'patch_file' not in files.keys():
        log.debug('Parameters passed could not be found on disk')
        flask.abort(400)
    storage = files.get('patch_file')

    form = flask.request.form
    sha_from, sha_to = form['sha_from'], form['sha_to']
    identifier = _get_identifier(sha_from, sha_to)

    log.debug('Saving patch file to cache with key %s', identifier)
    cache.save(storage.stream, 'patch', identifier)

    url = flask.url_for('get_patch', sha_from=sha_from, sha_to=sha_to)
    return flask.Response(json.dumps({"result": url}),
                          status=200,
                          mimetype='application/json')