Ejemplo n.º 1
0
def update(context, request):

    params = dict()
    source = request.matchdict['source']
    Redirect.get(request.db_session, source)

    specs = (
       ('new_source', check_domain_not_used, [request]),
       ('destination', Instance.get_by_domain, [request.db_session]),
       ('http_code', None, None),
       ('target_path', None, None)
    )
    try:
        for attr, validate_fun, fun_args in specs:
            if attr in request.params:
                if validate_fun:
                    fun_args.append(request.params[attr])
                    params[attr] = validate_fun(*fun_args)
                else:
                    params[attr] = request.params[attr]

    except NoResultFound:
        raise ParamsError("No instance for domain {}"\
                          .format(request.params['destination']))

    if not params:
        raise ParamsError("Missing update fields")

    params['source'] = source
    if "destination" in params:
        params['instance_id'] = params['destination'].id
        del params['destination']

    if "new_source" in params:
        params['new_source'] = validate_hostname(params['new_source'])

    return request.submit_task('redirect.update', **params)
Ejemplo n.º 2
0
def update(session, task, source, instance_id=None, http_code=None,
           target_path=None, new_source=None):
    try:
        redirect = Redirect.get(session, source)
        if instance_id:
            redirect.instance = Instance.get(session, instance_id)
        if http_code:
            redirect.http_code = http_code
        if target_path:
            redirect.target_path = target_path
        if new_source:
            redirect.source = new_source

    except:
        log.exception('redirect.update')
Ejemplo n.º 3
0
def delete(session, task, source):
    redirect = Redirect.get(session, source)
    redirect.delete()
Ejemplo n.º 4
0
def delete(context, request):
    source = request.matchdict['source']
    Redirect.get(request.db_session, source)
    return request.submit_task('redirect.delete', source=source)
Ejemplo n.º 5
0
def info(context, request):
    return Redirect.get(request.db_session,
                        request.matchdict['source']).to_dict()
Ejemplo n.º 6
0
def list(context, request):
    return {r.source: r.to_dict() for r in Redirect.all(request.db_session)}