Example #1
0
def ports_add(user):
    """
    POST /ports
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data.update({'user_id': user.user_id})
    params = PortAddValidator.parse(data)
    try:
        port = add_user_port(**params)
    except (RenkiHTTPError, Invalid, DoesNotExist):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occured')

    try:
        PortDatabase.validate_add(user, user.user_id)
    except SoftLimitReached as e:
        port.waiting = True
        pass
    except HardLimitReached as e:
        logger.exception(e)
        raise PermissionDenied('Not allowed to create more ports')
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occured')
    
    dbconn.session.safe_commit()
    return ok(port.as_dict())
Example #2
0
def domains_get_domain_admin(user, user_id, domain_id):
    """
    GET /domains/domain_id route
    """
    data = {'user_id' : user_id, 'domain_id': domain_id}
    data = DomainIDValidator.parse(data)
    domain = get_domain_by_id(int(domain_id), user_id=int(user_id))
    return ok(domain.as_dict())
Example #3
0
def dns_zone_delete_route(user_id, domain_id):
    data = dict(request.params.items())
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    params = DNSQueryValidator.parse(data)
    sandbox(delete_dns_zone, **params)
    dbconn.session.safe_commit()
    return ok({})
Example #4
0
def dns_zone_get_records(user_id, domain_id):
    """
    GET /domains/<domain_id>/dns/records
    """
    data = dict(request.params.items())
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    params = DNSGetValidator.parse(data)
    records = sandbox(get_dns_records, **params)
    return ok({'records': [x.as_dict() for x in records]})
Example #5
0
def domains_delete_domain_admin(user, user_id, domain_id):
    """
    DELETE /domains/domain_id route
    """
    data = {'user_id' : user_id, 'domain_id': domain_id}
    data = DomainIDValidator.parse(data)
    domain = get_domain_by_id(int(domain_id), user_id=int(user.id))
    domain.delete()
    dbconn.session.safe_commit()
    return ok({})
Example #6
0
def dummies_delete(user, dummy_id):
    data = dict(request.params.items())
    data.update({'user_id' : user.id, 'dummy_id': dummy_id})
    params = DummyDeleteValidator.parse(data)
    try:
        port = get_dummy_by_id(**params)
    except DoesNotExist:
        raise
    dummy.delete()
    dbconn.session.safe_commit()
    return ok()
Example #7
0
def get_dns_route(user_id, domain_id):
    """
    GET /domains/<domain_id>/dns route
    """
    data = dict(request.params.items())
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    params = DNSGetValidator.parse(data)
    zone = sandbox(get_dns_zone, **params)
    dbconn.session.safe_commit()
    return ok(zone.as_dict())
Example #8
0
def dns_zone_get_record(user_id, domain_id, dns_record_id):
    """
    GET /domains/<domain_id>/dns/records/<dns_record_id>
    """
    data = dict(request.params.items())
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    data['dns_record_id'] = dns_record_id
    params = DNSRecordQueryValidator.parse(data)
    record = sandbox(get_dns_record, user_id=params['user_id'],
                          dns_record_id=params['dns_record_id'])
    return ok(record.as_dict())
Example #9
0
def dns_zone_delete_record(user_id, domain_id, dns_record_id):
    """
    DELETE /domains/<domain_id>/dns/records/<dns_record_id>
    """
    data = dict(request.params.items())
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    data['dns_record_id'] = dns_record_id
    params = DNSRecordQueryValidator.parse(data)
    sandbox(delete_dns_record, user_id=params['user_id'],
            dns_record_id=params['dns_record_id'])
    dbconn.session.safe_commit()
    return ok({})
Example #10
0
def dummies_index(user):
    data = dict(request.params.items())
    data.update({'user_id': user.user_id})
    params = DummyGetValidator.parse(data)
    try:
        dummies = get_user_dummies(**params)
    except (RenkiHTTPError, Invalid):
        raise
    except Exception as e:
        print(e)
        logger.info(e)
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    return ok({'dummies': [x.as_dict() for x in dummies]})
Example #11
0
def dns_zone_add_route(user_id, domain_id):
    """
    PUT /domains/<domain_id>/dns
    """
    data = dict(request.json)
    qdata = {}
    qdata['user_id'] = user_id
    qdata['domain_id'] = domain_id
    params = DNSZoneValidator.parse(data)
    qparams = DNSQueryValidator.parse(qdata)
    params.update(qparams)
    zone = sandbox(add_user_dns_zone, **params)
    dbconn.session.safe_commit()
    return ok(zone.as_dict())
Example #12
0
def dns_zone_add_records(user_id, domain_id):
    """
    Add new DNS record to DNS zone
    """
    data = dict(request.params.items())
    qdata = {}
    qdata['user_id'] = user_id
    qdata['domain_id'] = domain_id
    qparams = DNSQueryValidator.parse(qdata)
    params = DNSRecordParser.parse(data)
    params.update(qparams)
    record = sandbox(add_dns_record, **params)
    dbconn.session.safe_commit()
    return ok(record.as_dict())
Example #13
0
def domains_modify_domain_admin(user, user_id, domain_id):
    """
    POST /domains/domain_id route
    """
    data = request_data()
    data['user_id'] = user_id
    data['domain_id'] = domain_id
    data = DomainEditValidator.parse(data)
    domain = get_domain_by_id(int(domain_id), user_id=int(user.id))
    if 'comment' in data and data['comment'] is not None:
        domain.comment = data['comment']
    domain.save()
    dbconn.session.safe_commit()
    return ok({})
Example #14
0
def admin_ports_index(user, user_id):
    """
    GET /<id>/ports
    """
    data = dict(request.params.items())
    data.update({'user_id': user_id})
    params = PortGetValidator.parse(data)
    try:
        ports = get_user_ports(**params)
    except (RenkiHTTPError, Invalid, DoesNotExist):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    return ok({'ports': [x.as_dict() for x in ports]})
Example #15
0
def dns_zone_modify_record(user_id, domain_id, dns_record_id):
    """
    PUT/POST /domains/<domain_id>/dns/records/<dns_record_id>
    """

    qdata = {}
    qdata['user_id'] = user_id
    qdata['domain_id'] = domain_id
    qdata['dns_record_id'] = dns_record_id
    qparams = DNSRecordQueryValidator.parse(qdata)
    params = DNSRecordParser.parse(data)
    params.update(qparams)
    record = sandbox(modify_dns_record, **params)
    dbconn.session.safe_commit()
    return ok(record.as_dict())
Example #16
0
def repositories_get_repository(user, type, repo_id):
    """
    GET /repositories/<type>/<id>
    """
    data = dict(request.params.items())
    data.update({'user_id': user.user_id, 'type': type, 'repo_id': repo_id})
    params = RepositoryIDValidator.parse(data)
    try:
        repo = get_repository_by_id(**params)
    except DoesNotExist:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')

    return ok(repo.as_dict())
Example #17
0
def repositories_index(user):
    """
    GET /repositories
    """
    repos = {}
    data = dict(request.params.items())
    data['user_id'] = user.user_id
    params = RepositoryGetValidator.parse(data)
    try:
        repos = get_user_repositories(**params)
    except (RenkiHTTPError, Invalid):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    return ok({'svn': [x.as_dict() for x in repos if x.type == 'svn'], 'git': [x.as_dict() for x in repos if x.type == 'git']})
Example #18
0
def repositories_get_repository(user, type, repo_id):
    """
    GET /repositories/<type>/<id>
    """
    data = dict(request.params.items())
    data.update({'user_id': user.user_id, 'type': type, 'repo_id': repo_id})
    params = RepositoryIDValidator.parse(data)
    try:
        repo = get_repository_by_id(**params)
    except DoesNotExist:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')

    return ok(repo.as_dict())
Example #19
0
def ports_history_admin(user, user_id):
    """
    GET /ports/history
    """
    data = dict(request.params.items())
    data.update({'user_id': user_id})
    params = PortGetValidator.parse(data)
    try:
        ports = get_user_port_history(**params)
    except (RenkiHTTPError, Invalid):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')

    return ok({'ports': [x.to_dict() for x in ports]})
Example #20
0
def admin_ports_delete(user, user_id, port_id):
    """
    DELETE /ports/port_id route
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data.update({'user_id' : user_id, 'port_id': port_id})
    params = PortIDValidator.parse(data)
    try:
        port = get_port_by_id(**params)
    except DoesNotExist:
        raise
    port.delete()
    dbconn.session.safe_commit()
    return ok()
Example #21
0
def ports_history(user):
    """
    GET /ports/history
    """
    data = dict(request.params.items())
    data.update({'user_id': user.user_id})
    params = PortGetValidator.parse(data)
    try:
        ports = get_user_port_history(**params)
    except (RenkiHTTPError, Invalid):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
        
    return ok({'ports': [x.to_dict() for x in ports]})
    #return ok({'ports': [str(x) + str(vars(ports)[x]) for x in vars(ports)]})#[x.as_dict() for x in ports]})
Example #22
0
def get_domains_route(user):
    """
    GET /domains
    """
    domains = []

    data = dict(request.params.items())
    data['user_id'] = user.user_id
    params = DomainGetValidator.parse(data)
    try:
        domains = get_user_domains(**params)
    except RenkiHTTPError:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    return ok({'domains': [x.as_dict() for x in domains]})
Example #23
0
def admin_ports_add(user, user_id):
    """
    POST /<user_id>/ports
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data.update({'user_id': user_id})
    params = PortAddValidator.parse(data)
    try:
        port = add_user_port(**params)
    except (Invalid, DatabaseError, RenkiHTTPError, DoesNotExist):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occured')
    dbconn.session.safe_commit()
    return ok(port.as_dict())
Example #24
0
def repositories_add_repository(user, type):
    """
    POST /repositories/<type>
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data['user_id'] = user.user_id
    data['type'] = type
    params = RepositoryAddValidator.parse(data)
    try:
        repo = add_user_repository(**params)
    except (DoesNotExist, AlreadyExist):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    dbconn.session.safe_commit()
    return ok(repo.as_dict())
Example #25
0
def repositories_delete_repository(user, type, repo_id):
    """
    DELETE /repositories/<type>/<id>
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data.update({'user_id': user.user_id, 'type': type, 'repo_id': repo_id})
    params = RepositoryIDValidator.parse(data)
    try:
        repo = get_repository_by_id(**params)
    except DoesNotExist:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    repo.delete()
    dbconn.session.safe_commit()
    return ok()
Example #26
0
def repositories_index(user):
    """
    GET /repositories
    """
    repos = {}
    data = dict(request.params.items())
    data['user_id'] = user.user_id
    params = RepositoryGetValidator.parse(data)
    try:
        repos = get_user_repositories(**params)
    except (RenkiHTTPError, Invalid):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    return ok({
        'svn': [x.as_dict() for x in repos if x.type == 'svn'],
        'git': [x.as_dict() for x in repos if x.type == 'git']
    })
Example #27
0
def repositories_add_repository(user, type):
    """
    POST /repositories/<type>
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data['user_id'] = user.user_id
    data['type'] = type
    params = RepositoryAddValidator.parse(data)
    try:
        repo = add_user_repository(**params)
    except (DoesNotExist, AlreadyExist):
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    dbconn.session.safe_commit()
    return ok(repo.as_dict())
Example #28
0
def repositories_delete_repository(user, type, repo_id):
    """
    DELETE /repositories/<type>/<id>
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data.update({'user_id': user.user_id, 'type': type, 'repo_id': repo_id})
    params = RepositoryIDValidator.parse(data)
    try:
        repo = get_repository_by_id(**params)
    except DoesNotExist:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    repo.delete()
    dbconn.session.safe_commit()
    return ok()
Example #29
0
def domains_add_route(user):
    """
    Add domain route
    """
    data = request.json
    if not data:
        data = dict(request.params.items())
    data['user_id'] = user.user_id
    params = UserDomainPutValidator.parse(data)
    try:
        domain = add_user_domain(**params)
    except (AlreadyExist, DatabaseError) as e:
        return error(str(e))
    except RenkiHTTPError:
        raise
    except Exception as e:
        logger.exception(e)
        raise RenkiHTTPError('Unknown error occurred')
    dbconn.session.safe_commit()
    return ok(domain.as_dict())