Files
anti f2b3393669 chore: relicense to AGPL-3.0-or-later and add SPDX headers
Replaces LICENSE (GPLv3 -> AGPLv3) and prepends
`SPDX-License-Identifier: AGPL-3.0-or-later` to every source file
across decnet/, decnet_web/, tests/, scripts/, and tools/.

Rationale: closes the GPLv3 ASP loophole so any party operating a
modified DECNET as a network service must offer their modified
source. Personal copyright (Samuel Paschuan) + inbound=outbound
contributions make a future unilateral relicense infeasible.

- LICENSE: full AGPL-3.0 text (gnu.org/licenses/agpl-3.0.txt)
- COPYRIGHT: project copyright notice
- tools/add_spdx_headers.py: idempotent header injector
  (shebang- and PEP 263-aware)

Touches 1565 source files (.py, .ts, .tsx, .js, .jsx, .css, .sh).
No behavior change; comments only.
2026-05-22 21:04:16 -04:00

74 lines
2.5 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Tarpit rule CRUD."""
from __future__ import annotations
import json
import uuid
from datetime import datetime, timezone
from typing import Any, Optional
from sqlalchemy import select
from decnet.web.db.models import TarpitRule
from decnet.web.db.sqlmodel_repo._helpers import _MixinBase
class TarpitMixin(_MixinBase):
"""Mixin: composed onto ``SQLModelRepository``."""
async def set_tarpit_rule(self, data: dict[str, Any]) -> None:
"""Upsert a tarpit rule keyed on ``decky_name`` (one rule per decky)."""
async with self._session() as session:
result = await session.execute(
select(TarpitRule).where(TarpitRule.decky_name == data["decky_name"])
)
existing = result.scalar_one_or_none()
if existing:
for k, v in data.items():
setattr(existing, k, v)
session.add(existing)
else:
payload = {
"id": str(uuid.uuid4()),
"created_at": datetime.now(timezone.utc),
**data,
}
session.add(TarpitRule(**payload))
await session.commit()
async def get_tarpit_rule(self, decky_name: str) -> Optional[dict[str, Any]]:
async with self._session() as session:
result = await session.execute(
select(TarpitRule).where(TarpitRule.decky_name == decky_name)
)
row = result.scalar_one_or_none()
if row is None:
return None
d = row.model_dump(mode="json")
d["ports"] = json.loads(d["ports"])
return d
async def delete_tarpit_rule(self, decky_name: str) -> bool:
async with self._session() as session:
result = await session.execute(
select(TarpitRule).where(TarpitRule.decky_name == decky_name)
)
row = result.scalar_one_or_none()
if row is None:
return False
await session.delete(row)
await session.commit()
return True
async def list_tarpit_rules(self) -> list[dict[str, Any]]:
async with self._session() as session:
result = await session.execute(select(TarpitRule))
rows = result.scalars().all()
out = []
for row in rows:
d = row.model_dump(mode="json")
d["ports"] = json.loads(d["ports"])
out.append(d)
return out