コード例 #1
0
def create_resource_record(req_record_data):
    """
    create a new resource object based on the request parameters
    :param req_record_data:
    :return:
    """
    validation, error = new_record_validator(req_record_data)
    if error:
        return jsonify({'error': error})
    record_type = req_record_data.get('type')
    validation, error = DNS_TYPES[record_type](req_record_data)
    if error:
        return jsonify({"error": error})
    record_id = req_record_data.get('zone_id')
    resource_record = Domain.query.filter_by(id=record_id).first()
    new_record = Record()
    new_record.domain_id = record_id
    if req_record_data.get('name'):
        new_record.name = req_record_data.get(
            "name") + '.' + resource_record.name
    else:
        new_record.name = resource_record.name
    new_record.type = record_type
    new_record.content = req_record_data.get("content")
    new_record.ttl = req_record_data.get("ttl") or 3600
    new_record.prio = req_record_data.get("priority") or None
    db.session.add(new_record)
    db.session.commit()
    return jsonify({"status": "ok"})
コード例 #2
0
def build_zone_ns(zone_data, zone_id):
    """
    function to handle the nameserver insertions coming in through the zone creation endpoint
    :param zone_data: dictionary containing the zone creation data
    :param zone_id: zone id value that the ns record maps to
    :return: list of nameserver records
    """
    ns_value = zone_data['nameserver']
    ns_record = Record()
    ns_record.domain_id = zone_id
    ns_record.name = zone_data['name'].rstrip(".")
    ns_record.type = "NS"
    ns_record.content = ns_value
    ns_record.ttl = 3600
    return ns_record
コード例 #3
0
def build_zone_soa(zone_data, zone_id):
    """
    build the SOA record for the zone from the zone creation data
    :param zone_id: id of the zone record to map the resource record to
    :param zone_data:incoming zone data dictionary
    :return: record object for the SOA record
    """
    nameserver = zone_data['nameserver']
    soa_record = Record()
    soa_record.domain_id = zone_id
    soa_record.name = zone_data['name'].rstrip(".")
    rname = parse_soa_email(email=zone_data['rname'], encode=True)
    soa_record.type = "SOA"
    soa_record.content = f"{nameserver} {rname} 1 86400 7200 3600000 3600"
    soa_record.ttl = 3600
    return soa_record