58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
import json
|
|
import os
|
|
from pathlib import Path
|
|
|
|
from django.http import JsonResponse
|
|
from spid_cie_oidc.entity.models import FederationEntityConfiguration, TrustChain, FetchedEntityStatement
|
|
|
|
|
|
def build_probe_view(service: str):
|
|
info_path = Path("/app/__buildinfo__.json")
|
|
fingerprint_path = Path("/app/__buildfingerprint__")
|
|
info = {}
|
|
if info_path.exists():
|
|
try:
|
|
info = json.loads(info_path.read_text())
|
|
except Exception:
|
|
info = {}
|
|
fingerprint = ""
|
|
if fingerprint_path.exists():
|
|
try:
|
|
fingerprint = fingerprint_path.read_text().strip()
|
|
except Exception:
|
|
fingerprint = ""
|
|
|
|
return JsonResponse(
|
|
{
|
|
"ok": True,
|
|
"service": service,
|
|
"build_id": info.get("build_id", ""),
|
|
"built_at_utc": info.get("built_at_utc", ""),
|
|
"image_marker": info.get("image_marker", ""),
|
|
"fingerprint": fingerprint,
|
|
"hostname": os.getenv("HOSTNAME", ""),
|
|
}
|
|
)
|
|
|
|
|
|
def diag_view(service: str):
|
|
configs = FederationEntityConfiguration.objects.all()
|
|
active = FederationEntityConfiguration.objects.filter(is_active=True)
|
|
first = configs.order_by("id").first()
|
|
first_active = active.order_by("id").first()
|
|
|
|
return JsonResponse(
|
|
{
|
|
"ok": True,
|
|
"service": service,
|
|
"config_count": configs.count(),
|
|
"active_config_count": active.count(),
|
|
"first_sub": getattr(first, "sub", None),
|
|
"first_entity_type": getattr(first, "entity_type", None),
|
|
"first_active_sub": getattr(first_active, "sub", None),
|
|
"first_active_entity_type": getattr(first_active, "entity_type", None),
|
|
"trust_chain_count": TrustChain.objects.count(),
|
|
"fetched_statement_count": FetchedEntityStatement.objects.count(),
|
|
}
|
|
)
|