Example #1
0
def submit():
    def _get(k):
        if k in request.POST:
            return request.POST[k]
        else:
            raise HTTPError(500, "Missing key: %s" % k)
    # get all values, yeah
    package = _get('package')
    version = _get('version')
    variant = _get('variant')
    ext = _get('ext')
    archive = _get('archive').file # TODO?
    user = _get('user')
    api_token = _get('token')
    if ('/' in package or '..' in package):
        raise HTTPError(500, "Invalid package: %s" % package)
    if ('/' in version or '..' in version):
        raise HTTPError(500, "Invalid version: %s" % version)
    if ('/' in variant or '..' in variant):
        raise HTTPError(500, "Invalid variant: %s" % version)
    # Ask nirvana if I'm allowed to do that.
    try:
        if not SHOP.is_authorized(user, api_token, package, version, variant):
            raise HTTPError(500, "User is not allowed to upload this variant.")
    except Exception, e:
        raise HTTPError(500, "Unhandled error: %r" % e)
Example #2
0
        else:
            raise HTTPError(500, "Missing key: %s" % k)
    # get all values, yeah
    package = _get('package')
    version = _get('version')
    variant = _get('variant')
    ext = _get('ext')
    archive = _get('archive').file # TODO?
    user = _get('user')
    api_token = _get('token')
    if ('/' in package or '..' in package):
        raise HTTPError(500, "Invalid package: %s" % package)
    if ('/' in version or '..' in version):
        raise HTTPError(500, "Invalid version: %s" % version)
    if ('/' in variant or '..' in variant):
        raise HTTPError(500, "Invalid variant: %s" % version)
    # Ask nirvana if I'm allowed to do that.
    try:
        if not SHOP.is_authorized(user, api_token, package, version, variant):
            raise HTTPError(500, "User is not allowed to upload this variant.")
    except Exception, e:
        raise HTTPError(500, "Unhandled error: %r" % e)
    # Yeah, do it!
    try:
        filename = SHOP.add(package, version, variant, ext, archive)
    except InvalidExtension:
        raise HTTPError(500, "Invalid extension!")
    # Trigger everything!
    SHOP.trigger_submirrors()
    return 'Done.'