async def store( zone_id: int, form: DnsRecordForZoneCreateForm, dns_record_repo: DnsRecordRepo = Depends(DnsRecordRepo()), zone_repo: ZoneRepo = Depends(ZoneRepo()), token: TokenPayload = Depends(ScopedTo("dns-record:create")), ): zone_repo.exists(id=zone_id, or_fail=True) data = only(dict(form), ["record", "sort"]) data["zone_id"] = zone_id item = dns_record_repo.create(data).data() return DnsRecordResponse(dns_record=item)
async def update( zone_id: int, dns_record_id: int, form: DnsRecordForZoneCreateForm, dns_record_repo: DnsRecordRepo = Depends(DnsRecordRepo), zone_repo: ZoneRepo = Depends(ZoneRepo), token: TokenPayload = Depends(ScopedTo("dns-record:create")), ): zone_repo.exists(id=zone_id, or_fail=True) data = only(dict(form), ["record", "sort"]) # TODO: make sure sorts don't clash item = dns_record_repo.first_or_fail(id=dns_record_id).update(data).data() return DnsRecordResponse(dns_record=item)
async def index( zone_id: int, sort_qs: SortQS = Depends(SortQS), pagination: PaginationQS = Depends(PaginationQS), dns_record_repo: DnsRecordRepo = Depends(DnsRecordRepo()), zone_repo: ZoneRepo = Depends(ZoneRepo()), token: TokenPayload = Depends(ScopedTo("dns-record:list")), includes: List[str] = Query(None), ): zone_repo.exists(id=zone_id, or_fail=True) includes = only(includes, ["zone"], values=True) pg, items = (dns_record_repo.loads("zone").sort(sort_qs).filter_by( zone_id=zone_id).paginate(pagination).includes(includes).data()) return DnsRecordsResponse(pagination=pg, dns_records=items)
async def update( zone_id: int, dns_record_id: int, form: DnsRecordForZoneCreateForm, dns_record_repo: DnsRecordRepo = Depends(DnsRecordRepo()), zone_repo: ZoneRepo = Depends(ZoneRepo()), token: TokenPayload = Depends(ScopedTo("dns-record:create")), ): # TODO: use abort_for_input instead of or_fail zone_repo.exists(id=zone_id, or_fail=True) data = only(form, ["record", "sort"]) item = dns_record_repo.first_or_fail(id=dns_record_id).update(data).data() return DnsRecordResponse(dns_record=item)
async def show( zone_id: int, dns_record_id: int, dns_record_repo: DnsRecordRepo = Depends(DnsRecordRepo()), zone_repo: ZoneRepo = Depends(ZoneRepo()), token: TokenPayload = Depends(ScopedTo("dns-record:show")), includes: List[str] = Query(None), ): zone_repo.exists(id=zone_id, or_fail=True) includes = only(includes, ["zone"], values=True) item = (dns_record_repo.loads("zone").filter_by( zone_id=zone_id).first_or_fail( id=dns_record_id).includes(includes).data()) return DnsRecordResponse(dns_record=item)
async def destroy( zone_id: int, zone_repo: ZoneRepo = Depends(ZoneRepo()), token: TokenPayload = Depends(ScopedTo("zone:destroy")), ): messages = [{"text": "Deactivation Succesful", "type": "success"}] if not zone_repo.exists(zone_id): return BaseResponse(messages=messages) zone_repo.deactivate(zone_id) return BaseResponse(messages=messages)
async def store( form: ZoneCreateForm, zone_repo: ZoneRepo = Depends(ZoneRepo()), dns_server_repo: DnsServerRepo = Depends(DnsServerRepo()), token: TokenPayload = Depends(ScopedTo("zone:create")), ): data = only(dict(form), ["ip", "domain"]) data["domain"] = data["domain"].lower() # Make sure domain is unique if zone_repo.exists(domain=data["domain"]): abort_for_input("domain", "A Zone with that domain already exists") zone_repo.clear() if form.dns_server_id: if dns_server_repo.exists(id=form.dns_server_id): data["dns_server_id"] = dns_server_repo.results().id zone = zone_repo.create(data).data() return ZoneResponse(zone=zone)