Beispiel #1
0
async def store(
        form: DnsRequestCreateForm,
        dns_request_repo: DnsRequestRepo = Depends(DnsRequestRepo()),
        zone_repo: ZoneRepo = Depends(ZoneRepo()),
        dns_server_repo: DnsServerRepo = Depends(DnsServerRepo()),
        token: str = Depends(ScopedTo("dns-request:create")),
):

    dns_server_id = (dns_server_repo.first_or_fail(
        name=form.dns_server_name.lower()).results().id)

    zone = (zone_repo.filter(
        literal(form.name.lower()).contains(
            zone_repo.label("domain"))).first().results())

    zone_id = zone.id if zone else None

    data = only(dict(form),
                ["name", "source_address", "source_port", "type", "protocol"])

    data["name"] = data["name"].lower()
    data["type"] = data["type"].upper()

    data["dns_server_id"] = dns_server_id
    data["zone_id"] = zone_id

    dns_request = dns_request_repo.create(data).data()
    return DnsRequestResponse(dns_request=dns_request)
Beispiel #2
0
async def index(
        sort_qs: SortQS = Depends(SortQS),
        pagination: PaginationQS = Depends(PaginationQS),
        dns_request_repo: DnsRequestRepo = Depends(DnsRequestRepo()),
        token: TokenPayload = Depends(ScopedTo("dns-request:list")),
):
    pg, items = (dns_request_repo.loads("dns_server").sort(sort_qs).paginate(
        pagination).includes("dns_server").data())
    return DnsRequestsResponse(pagination=pg, dns_requests=items)
Beispiel #3
0
async def show(
        dns_request_id: int,
        dns_request_repo: DnsRequestRepo = Depends(DnsRequestRepo()),
        token: TokenPayload = Depends(ScopedTo("dns-request:show")),
        includes: List[str] = Query(None),
):
    # probably a bunch of access bypasses with scopes via includes
    # need easy way to scope for includes
    includes = only(includes, ["dns_server", "zone"], values=True)

    dns_request = (dns_request_repo.loads(includes).get_or_fail(
        dns_request_id).includes(includes).data())
    return DnsRequestResponse(dns_request=dns_request)