Archived
Refactor UI assets and harden quality checks
This commit is contained in:
1 parent
23ab466c52
commit
4ecc8eb874
62 files changed
+3314
-3206
No files matched your search
+12
-11
@@ -8,7 +8,7 @@ from fastapi.responses import PlainTextResponse
|
||||
|
||||
from .dns import DnsProviderError
|
||||
from .security import credentials_from_basic_auth
|
||||
from .services.ddns import BadIpError, DdnsService
|
||||
from .services.ddns import BadIpError, DdnsService, UpdateIpParams
|
||||
from .settings import DdnsSettings
|
||||
from .store import DdnsStore
|
||||
|
||||
@@ -38,11 +38,8 @@ def authenticate_admin(
|
||||
if not settings.admin_password:
|
||||
raise HTTPException(status_code=500, detail="DDNS_ADMIN_PASSWORD is required")
|
||||
|
||||
supplied = None
|
||||
if authorization and authorization.lower().startswith("basic "):
|
||||
_, supplied = credentials_from_basic_auth(authorization)
|
||||
|
||||
if not supplied or not secrets.compare_digest(supplied, settings.admin_password):
|
||||
supplied = _basic_auth_password(authorization)
|
||||
if supplied is None or not secrets.compare_digest(supplied, settings.admin_password):
|
||||
raise HTTPException(
|
||||
status_code=401,
|
||||
detail="admin authentication required",
|
||||
@@ -50,17 +47,21 @@ def authenticate_admin(
|
||||
)
|
||||
|
||||
|
||||
def _basic_auth_password(authorization: str | None) -> str | None:
|
||||
if authorization is None or not authorization.lower().startswith("basic "):
|
||||
return None
|
||||
_, password = credentials_from_basic_auth(authorization)
|
||||
return password
|
||||
|
||||
|
||||
def apply_update_response(
|
||||
service: DdnsService,
|
||||
request: Request,
|
||||
hostname: str,
|
||||
myip: str | None,
|
||||
ipaddr: str | None,
|
||||
myipv6: str | None,
|
||||
ip6addr: str | None,
|
||||
ip_params: UpdateIpParams,
|
||||
) -> str | PlainTextResponse:
|
||||
try:
|
||||
return service.apply_update(request, hostname, myip, ipaddr, myipv6, ip6addr).result.dyndns_response
|
||||
return service.apply_update(request, hostname, ip_params).result.dyndns_response
|
||||
except BadIpError:
|
||||
return PlainTextResponse("badip", status_code=400)
|
||||
except DnsProviderError:
|
||||
|
||||
Reference in new issue
Block a user