示例#1
0
def _delete_recordset_if_empty(context, domain_id, recordset_id):
    recordset = get_central_api().find_recordset(context, {
        'id': recordset_id
    })
    # Make sure it's the right recordset
    if len(recordset.records) == 0:
        get_central_api().delete_recordset(context, domain_id, recordset_id)
示例#2
0
def update_domain(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    domain = get_central_api().get_domain(context, domain_id)
    domain = domain_schema.filter(domain)
    domain.update(values)

    domain_schema.validate(domain)
    domain = get_central_api().update_domain(context, domain_id, values)

    return flask.jsonify(domain_schema.filter(domain))
示例#3
0
def update_server(server_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    server = get_central_api().get_server(context, server_id)
    server = server_schema.filter(server)
    server.update(values)

    server_schema.validate(server)
    server = get_central_api().update_server(context, server_id, values=values)

    return flask.jsonify(server_schema.filter(server))
示例#4
0
def update_server(server_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    server = get_central_api().get_server(context, server_id)
    server = server_schema.filter(server)
    server.update(values)

    server_schema.validate(server)
    server = get_central_api().update_server(context, server_id, values=values)

    return flask.jsonify(server_schema.filter(server))
示例#5
0
def update_domain(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    domain = get_central_api().get_domain(context, domain_id)
    domain = domain_schema.filter(domain)
    domain.update(values)

    domain_schema.validate(domain)
    domain = get_central_api().update_domain(context, domain_id, values)

    return flask.jsonify(domain_schema.filter(domain))
示例#6
0
def update_tsigkey(tsigkey_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    tsigkey = get_central_api().get_tsigkey(context, tsigkey_id)
    tsigkey = tsigkey_schema.filter(tsigkey)
    tsigkey.update(values)

    tsigkey_schema.validate(tsigkey)
    tsigkey = get_central_api().update_tsigkey(context, tsigkey_id,
                                               values=values)

    return flask.jsonify(tsigkey_schema.filter(tsigkey))
示例#7
0
def delete_record(domain_id, record_id):
    context = flask.request.environ.get("context")

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return a record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {"domain_id": domain_id, "id": record_id}
    record = get_central_api().find_record(context, criterion)

    get_central_api().delete_record(context, domain_id, record["recordset_id"], record_id)

    return flask.Response(status=200)
示例#8
0
def update_tsigkey(tsigkey_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    tsigkey = get_central_api().get_tsigkey(context, tsigkey_id)
    tsigkey = tsigkey_schema.filter(tsigkey)
    tsigkey.update(values)

    tsigkey_schema.validate(tsigkey)
    tsigkey = get_central_api().update_tsigkey(context,
                                               tsigkey_id,
                                               values=values)

    return flask.jsonify(tsigkey_schema.filter(tsigkey))
示例#9
0
def delete_record(domain_id, record_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return a record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    get_central_api().delete_record(context, domain_id, record['recordset_id'],
                                    record_id)

    return flask.Response(status=200)
示例#10
0
def get_record(domain_id, record_id):
    context = flask.request.environ.get("context")

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    criterion = {"domain_id": domain_id, "id": record_id}
    record = get_central_api().find_record(context, criterion)

    recordset = get_central_api().get_recordset(context, domain_id, record["recordset_id"])

    record = _format_record_v1(record, recordset)

    return flask.jsonify(record_schema.filter(record))
示例#11
0
def create_record(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    record_schema.validate(values)

    if values['type'] == 'SOA':
        raise exceptions.BadRequest('SOA records cannot be manually created.')

    recordset = _find_or_create_recordset(context,
                                          domain_id,
                                          values['name'],
                                          values['type'],
                                          values.get('ttl', None))

    record = objects.Record(**_extract_record_values(values))

    record = get_central_api().create_record(context, domain_id,
                                             recordset['id'],
                                             record)

    record = _format_record_v1(record, recordset)

    response = flask.jsonify(record_schema.filter(record))
    response.status_int = 201
    response.location = flask.url_for('.get_record', domain_id=domain_id,
                                      record_id=record['id'])

    return response
示例#12
0
def get_record(domain_id, record_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    recordset = get_central_api().get_recordset(context, domain_id,
                                                record['recordset_id'])

    record = _format_record_v1(record, recordset)

    return flask.jsonify(record_schema.filter(record))
示例#13
0
def _find_or_create_recordset(context, domain_id, name, type, ttl):
    try:
        recordset = _find_recordset(context, domain_id, name, type)
    except exceptions.RecordSetNotFound:
        values = {"name": name, "type": type, "ttl": ttl}
        recordset = get_central_api().create_recordset(context, domain_id, objects.RecordSet(**values))

    return recordset
示例#14
0
def get_records(domain_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an empty records array instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    records = get_central_api().find_records(context, {'domain_id': domain_id})

    recordsets = _fetch_domain_recordsets(context, domain_id)

    def _inner(record):
        recordset = recordsets[record['recordset_id']]
        return _format_record_v1(record, recordset)

    records = [_inner(r) for r in records]

    return flask.jsonify(records_schema.filter({'records': records}))
示例#15
0
def get_records(domain_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an empty records array instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    records = get_central_api().find_records(context, {'domain_id': domain_id})

    recordsets = _fetch_domain_recordsets(context, domain_id)

    def _inner(record):
        recordset = recordsets[record['recordset_id']]
        return _format_record_v1(record, recordset)

    records = [_inner(r) for r in records]

    return flask.jsonify(records_schema.filter({'records': records}))
示例#16
0
def update_tsigkey(tsigkey_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    # Fetch the existing resource
    tsigkey = get_central_api().get_tsigkey(context, tsigkey_id)

    # Prepare a dict of fields for validation
    tsigkey_data = tsigkey_schema.filter(tsigkey)
    tsigkey_data.update(values)

    # Validate the new set of data
    tsigkey_schema.validate(tsigkey_data)

    # Update and persist the resource
    tsigkey.update(values)
    tsigkey = get_central_api().update_tsigkey(context, tsigkey)

    return flask.jsonify(tsigkey_schema.filter(tsigkey))
示例#17
0
def update_server(server_id):
    context = flask.request.environ.get("context")
    values = flask.request.json

    # Fetch the existing resource
    server = get_central_api().get_server(context, server_id)

    # Prepare a dict of fields for validation
    server_data = server_schema.filter(server)
    server_data.update(values)

    # Validate the new set of data
    server_schema.validate(server_data)

    # Update and persist the resource
    server.update(values)
    server = get_central_api().update_server(context, server)

    return flask.jsonify(server_schema.filter(server))
示例#18
0
def update_domain(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    # Fetch the existing resource
    domain = get_central_api().get_domain(context, domain_id)

    # Prepare a dict of fields for validation
    domain_data = domain_schema.filter(domain)
    domain_data.update(values)

    # Validate the new set of data
    domain_schema.validate(domain_data)

    # Update and persist the resource
    domain.update(values)
    domain = get_central_api().update_domain(context, domain)

    return flask.jsonify(domain_schema.filter(domain))
示例#19
0
def delete_record(domain_id, record_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return a record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    # Cannot delete a managed record via the API.
    if record['managed'] is True:
        raise exceptions.BadRequest('Managed records may not be deleted')

    get_central_api().delete_record(
        context, domain_id, record['recordset_id'], record_id)

    _delete_recordset_if_empty(context, domain_id, record['recordset_id'])
    return flask.Response(status=200)
示例#20
0
def _find_or_create_recordset(context, domain_id, name, type, ttl):
    try:
        recordset = _find_recordset(context, domain_id, name, type)
    except exceptions.RecordSetNotFound:
        recordset = get_central_api().create_recordset(context, domain_id, {
            'name': name,
            'type': type,
            'ttl': ttl,
        })

    return recordset
示例#21
0
def create_server():
    context = flask.request.environ.get("context")
    values = flask.request.json

    server_schema.validate(values)
    server = get_central_api().create_server(context, server=Server(**values))

    response = flask.jsonify(server_schema.filter(server))
    response.status_int = 201
    response.location = flask.url_for(".get_server", server_id=server["id"])

    return response
示例#22
0
def create_server():
    context = flask.request.environ.get('context')
    values = flask.request.json

    server_schema.validate(values)
    server = get_central_api().create_server(context, server=Server(**values))

    response = flask.jsonify(server_schema.filter(server))
    response.status_int = 201
    response.location = flask.url_for('.get_server', server_id=server['id'])

    return response
示例#23
0
def create_domain():
    context = flask.request.environ.get('context')
    values = flask.request.json

    domain_schema.validate(values)
    domain = get_central_api().create_domain(context, Domain(**values))

    response = flask.jsonify(domain_schema.filter(domain))
    response.status_int = 201
    response.location = flask.url_for('.get_domain', domain_id=domain['id'])

    return response
示例#24
0
def create_domain():
    context = flask.request.environ.get('context')
    values = flask.request.json

    domain_schema.validate(values)
    domain = get_central_api().create_domain(context, Domain(**values))

    response = flask.jsonify(domain_schema.filter(domain))
    response.status_int = 201
    response.location = flask.url_for('.get_domain', domain_id=domain['id'])

    return response
示例#25
0
def create_server():
    context = flask.request.environ.get('context')
    values = flask.request.json

    server_schema.validate(values)
    server = get_central_api().create_server(context,
                                             values=flask.request.json)

    response = flask.jsonify(server_schema.filter(server))
    response.status_int = 201
    response.location = flask.url_for('.get_server', server_id=server['id'])

    return response
示例#26
0
def create_tsigkey():
    context = flask.request.environ.get('context')
    values = flask.request.json

    tsigkey_schema.validate(values)
    tsigkey = get_central_api().create_tsigkey(
        context, tsigkey=TsigKey(**values))

    response = flask.jsonify(tsigkey_schema.filter(tsigkey))
    response.status_int = 201
    response.location = flask.url_for('.get_tsigkey', tsigkey_id=tsigkey['id'])

    return response
示例#27
0
def get_limits():
    context = flask.request.environ.get('context')

    absolute_limits = get_central_api().get_absolute_limits(context)

    return flask.jsonify(limits_schema.filter({
        "limits": {
            "absolute": {
                "maxDomains": absolute_limits['domains'],
                "maxDomainRecords": absolute_limits['domain_records']
            }
        }
    }))
示例#28
0
def create_tsigkey():
    context = flask.request.environ.get('context')
    values = flask.request.json

    tsigkey_schema.validate(values)
    tsigkey = get_central_api().create_tsigkey(context,
                                               tsigkey=TsigKey(**values))

    response = flask.jsonify(tsigkey_schema.filter(tsigkey))
    response.status_int = 201
    response.location = flask.url_for('.get_tsigkey', tsigkey_id=tsigkey['id'])

    return response
示例#29
0
def _find_or_create_recordset(context, domain_id, name, type, ttl):
    try:
        recordset = _find_recordset(context, domain_id, name, type)
    except exceptions.RecordSetNotFound:
        # Create an empty recordset
        values = {
            'name': name,
            'type': type,
            'ttl': ttl,
        }
        recordset = get_central_api().create_recordset(
            context, domain_id, objects.RecordSet(**values))

    return recordset
示例#30
0
def update_record(domain_id, record_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    # Find the associated recordset
    recordset = get_central_api().get_recordset(
        context, domain_id, record['recordset_id'])

    # Filter out any extra fields from the fetched record
    record = record_schema.filter(record)

    # Ensure all the API V1 fields are in place
    record = _format_record_v1(record, recordset)

    # Name and Type can't be updated on existing records
    if 'name' in values and record['name'] != values['name']:
        raise exceptions.InvalidOperation('The name field is immutable')

    if 'type' in values and record['type'] != values['type']:
        raise exceptions.InvalidOperation('The type field is immutable')

    # TTL Updates should be applied to the RecordSet
    update_recordset = False

    if 'ttl' in values and record['ttl'] != values['ttl']:
        update_recordset = True

    # Apply the updated fields to the record
    record.update(values)

    # Validate the record
    record_schema.validate(record)

    # Update the record
    record = get_central_api().update_record(
        context, domain_id, recordset['id'], record_id,
        _extract_record_values(values))

    # Update the recordset (if necessary)
    if update_recordset:
        recordset = get_central_api().update_recordset(
            context, domain_id, recordset['id'],
            _extract_recordset_values(values))

    # Format and return the response
    record = _format_record_v1(record, recordset)

    return flask.jsonify(record_schema.filter(record))
示例#31
0
def create_domain():
    valid_attributes = ['name', 'email', 'ttl', 'description']
    context = flask.request.environ.get('context')

    values = load_values(flask.request, valid_attributes)

    domain_schema.validate(values)

    domain = get_central_api().create_domain(context, Domain(**values))

    response = flask.jsonify(domain_schema.filter(domain))
    response.status_int = 201
    response.location = flask.url_for('.get_domain', domain_id=domain['id'])

    return response
示例#32
0
def update_record(domain_id, record_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return an record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    # Find the associated recordset
    recordset = get_central_api().get_recordset(context, domain_id,
                                                record['recordset_id'])

    # Filter out any extra fields from the fetched record
    record = record_schema.filter(record)

    # Ensure all the API V1 fields are in place
    record = _format_record_v1(record, recordset)

    # Name and Type can't be updated on existing records
    if 'name' in values and record['name'] != values['name']:
        raise exceptions.InvalidOperation('The name field is immutable')

    if 'type' in values and record['type'] != values['type']:
        raise exceptions.InvalidOperation('The type field is immutable')

    # TTL Updates should be applied to the RecordSet
    update_recordset = False

    if 'ttl' in values and record['ttl'] != values['ttl']:
        update_recordset = True

    # Apply the updated fields to the record
    record.update(values)

    # Validate the record
    record_schema.validate(record)

    # Update the record
    record = get_central_api().update_record(context, domain_id,
                                             recordset['id'], record_id,
                                             _extract_record_values(values))

    # Update the recordset (if necessary)
    if update_recordset:
        recordset = get_central_api().update_recordset(
            context, domain_id, recordset['id'],
            _extract_recordset_values(values))

    # Format and return the response
    record = _format_record_v1(record, recordset)

    return flask.jsonify(record_schema.filter(record))
示例#33
0
def create_record(domain_id):
    context = flask.request.environ.get("context")
    values = flask.request.json

    record_schema.validate(values)

    recordset = _find_or_create_recordset(context, domain_id, values["name"], values["type"], values.get("ttl", None))

    record = objects.Record(**_extract_record_values(values))

    record = get_central_api().create_record(context, domain_id, recordset["id"], record)

    record = _format_record_v1(record, recordset)

    response = flask.jsonify(record_schema.filter(record))
    response.status_int = 201
    response.location = flask.url_for(".get_record", domain_id=domain_id, record_id=record["id"])

    return response
示例#34
0
def create_record(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    record_schema.validate(values)

    recordset = _find_or_create_recordset(context, domain_id, values['name'],
                                          values['type'],
                                          values.get('ttl', None))

    record = get_central_api().create_record(context, domain_id,
                                             recordset['id'],
                                             _extract_record_values(values))

    record = _format_record_v1(record, recordset)

    response = flask.jsonify(record_schema.filter(record))
    response.status_int = 201
    response.location = flask.url_for('.get_record',
                                      domain_id=domain_id,
                                      record_id=record['id'])

    return response
示例#35
0
def create_record(domain_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    record_schema.validate(values)

    recordset = _find_or_create_recordset(context,
                                          domain_id,
                                          values['name'],
                                          values['type'],
                                          values.get('ttl', None))

    record = get_central_api().create_record(context, domain_id,
                                             recordset['id'],
                                             _extract_record_values(values))

    record = _format_record_v1(record, recordset)

    response = flask.jsonify(record_schema.filter(record))
    response.status_int = 201
    response.location = flask.url_for('.get_record', domain_id=domain_id,
                                      record_id=record['id'])

    return response
示例#36
0
def update_record(domain_id, record_id):
    context = flask.request.environ.get('context')
    values = flask.request.json

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return a record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Fetch the existing resource
    # NOTE(kiall): We use "find_record" rather than "get_record" as we do not
    #              have the recordset_id.
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    # Find the associated recordset
    recordset = get_central_api().get_recordset(
        context, domain_id, record.recordset_id)

    # Cannot manually update a SOA record
    if recordset['type'] == 'SOA':
        raise exceptions.BadRequest('SOA records cannot be manually updated.')

    # Prepare a dict of fields for validation
    record_data = record_schema.filter(_format_record_v1(record, recordset))
    record_data.update(values)

    # Validate the new set of data
    record_schema.validate(record_data)

    # Update and persist the resource
    record.update(_extract_record_values(values))
    record = get_central_api().update_record(context, record)

    # Update the recordset resource (if necessary)
    recordset.update(_extract_recordset_values(values))
    if len(recordset.obj_what_changed()) > 0:
        recordset = get_central_api().update_recordset(context, recordset)

    # Format and return the response
    record = _format_record_v1(record, recordset)

    return flask.jsonify(record_schema.filter(record))
示例#37
0
def delete_record(domain_id, record_id):
    context = flask.request.environ.get('context')

    # NOTE: We need to ensure the domain actually exists, otherwise we may
    #       return a record not found instead of a domain not found
    get_central_api().get_domain(context, domain_id)

    # Find the record
    criterion = {'domain_id': domain_id, 'id': record_id}
    record = get_central_api().find_record(context, criterion)

    # SOA records cannot be deleted
    recordset = get_central_api().get_recordset(context, domain_id,
                                                record['recordset_id'])
    if recordset['type'] == 'SOA':
        raise exceptions.BadRequest('SOA records cannot be manually deleted.')

    get_central_api().delete_record(
        context, domain_id, record['recordset_id'], record_id)

    _delete_recordset_if_empty(context, domain_id, record['recordset_id'])
    return flask.Response(status=200)
示例#38
0
def delete_tsigkey(tsigkey_id):
    context = flask.request.environ.get('context')

    get_central_api().delete_tsigkey(context, tsigkey_id)

    return flask.Response(status=200)
示例#39
0
 def central_api(self):
     return api.get_central_api()
示例#40
0
def get_domain(domain_id):
    context = flask.request.environ.get('context')

    domain = get_central_api().get_domain(context, domain_id)

    return flask.jsonify(domain_schema.filter(domain))
示例#41
0
def get_domains():
    context = flask.request.environ.get('context')

    domains = get_central_api().find_domains(context)

    return flask.jsonify(domains_schema.filter({'domains': domains}))
示例#42
0
def get_servers():
    context = flask.request.environ.get('context')

    servers = get_central_api().find_servers(context)

    return flask.jsonify(servers_schema.filter({'servers': servers}))
示例#43
0
def delete_domain(domain_id):
    context = flask.request.environ.get('context')

    get_central_api().delete_domain(context, domain_id)

    return flask.Response(status=200)
示例#44
0
def _fetch_domain_recordsets(context, domain_id):
    criterion = {'domain_id': domain_id}

    recordsets = get_central_api().find_recordsets(context, criterion)

    return dict((r['id'], r) for r in recordsets)
示例#45
0
def _fetch_domain_recordsets(context, domain_id):
    criterion = {'domain_id': domain_id}

    recordsets = get_central_api().find_recordsets(context, criterion)

    return dict((r['id'], r) for r in recordsets)
示例#46
0
def _find_recordset(context, domain_id, name, type):
    return get_central_api().find_recordset(context, {
        'domain_id': domain_id,
        'name': name,
        'type': type,
    })
示例#47
0
def get_domains():
    context = flask.request.environ.get('context')

    domains = get_central_api().find_domains(context)

    return flask.jsonify(domains_schema.filter({'domains': domains}))
示例#48
0
def get_tsigkeys():
    context = flask.request.environ.get('context')

    tsigkeys = get_central_api().find_tsigkeys(context)

    return flask.jsonify(tsigkeys_schema.filter({'tsigkeys': tsigkeys}))
示例#49
0
def get_tsigkey(tsigkey_id):
    context = flask.request.environ.get('context')

    tsigkey = get_central_api().get_tsigkey(context, tsigkey_id)

    return flask.jsonify(tsigkey_schema.filter(tsigkey))
示例#50
0
def delete_server(server_id):
    context = flask.request.environ.get('context')

    get_central_api().delete_server(context, server_id)

    return flask.Response(status=200)
示例#51
0
def _find_recordset(context, domain_id, name, type):
    return get_central_api().find_recordset(context, {
        'domain_id': domain_id,
        'name': name,
        'type': type,
    })
示例#52
0
def get_server(server_id):
    context = flask.request.environ.get('context')

    server = get_central_api().get_server(context, server_id)

    return flask.jsonify(server_schema.filter(server))
示例#53
0
def get_domain(domain_id):
    context = flask.request.environ.get('context')

    domain = get_central_api().get_domain(context, domain_id)

    return flask.jsonify(domain_schema.filter(domain))
示例#54
0
def get_domain_servers(domain_id):
    context = flask.request.environ.get('context')

    servers = get_central_api().get_domain_servers(context, domain_id)

    return flask.jsonify(servers_schema.filter({'servers': servers}))