(request)
| 360 | @api_view(["GET"]) |
| 361 | @permission_classes([Authenticated]) |
| 362 | def environment(request): |
| 363 | public_ip = None |
| 364 | local_ip = None |
| 365 | country_code = None |
| 366 | country_name = None |
| 367 | city = None |
| 368 | ip_lookup_pending = False |
| 369 | |
| 370 | ip_lookup_env_disabled = not getattr(django_settings, "ENABLE_IP_LOOKUP", True) |
| 371 | ip_lookup_db_enabled = CoreSettings.get_system_settings().get("enable_ip_lookup", True) |
| 372 | ip_lookup_enabled = not ip_lookup_env_disabled and ip_lookup_db_enabled |
| 373 | |
| 374 | if ip_lookup_enabled: |
| 375 | cached = cache.get(_IP_CACHE_KEY) |
| 376 | if cached is not None: |
| 377 | public_ip = cached.get("public_ip") |
| 378 | local_ip = cached.get("local_ip") |
| 379 | country_code = cached.get("country_code") |
| 380 | country_name = cached.get("country_name") |
| 381 | city = cached.get("city") |
| 382 | else: |
| 383 | if cache.add(_IP_LOCK_KEY, True, 30): |
| 384 | threading.Thread(target=_perform_ip_lookup, daemon=True).start() |
| 385 | ip_lookup_pending = True |
| 386 | |
| 387 | # Get environment mode and TLS status from settings |
| 388 | postgres_ssl = getattr(django_settings, "POSTGRES_SSL", False) |
| 389 | |
| 390 | return Response( |
| 391 | { |
| 392 | "authenticated": True, |
| 393 | "public_ip": public_ip, |
| 394 | "local_ip": local_ip, |
| 395 | "country_code": country_code, |
| 396 | "country_name": country_name, |
| 397 | "city": city, |
| 398 | "ip_lookup_enabled": ip_lookup_enabled, |
| 399 | "ip_lookup_env_disabled": ip_lookup_env_disabled, |
| 400 | "ip_lookup_pending": ip_lookup_pending, |
| 401 | "env_mode": os.getenv("DISPATCHARR_ENV", "aio"), |
| 402 | "redis_tls": { |
| 403 | "enabled": getattr(django_settings, "REDIS_SSL", False), |
| 404 | "verify": getattr(django_settings, "REDIS_SSL_VERIFY", True), |
| 405 | "mtls": bool(getattr(django_settings, "REDIS_SSL_CERT", "") and getattr(django_settings, "REDIS_SSL_KEY", "")), |
| 406 | }, |
| 407 | "postgres_tls": { |
| 408 | "enabled": postgres_ssl, |
| 409 | "ssl_mode": getattr(django_settings, "POSTGRES_SSL_MODE", "verify-full") if postgres_ssl else None, |
| 410 | "mtls": bool(getattr(django_settings, "POSTGRES_SSL_CERT", "") and getattr(django_settings, "POSTGRES_SSL_KEY", "")), |
| 411 | }, |
| 412 | } |
| 413 | ) |
| 414 | |
| 415 | |
| 416 | @extend_schema( |
nothing calls this directly
no test coverage detected