This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/authentik/events/geo.py
Jens Langhammer 14f2522c3e events: improve logging for geoip
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
2021-03-18 15:16:43 +01:00

26 lines
570 B
Python

"""events GeoIP Reader"""
from typing import Optional
from geoip2.database import Reader
from structlog.stdlib import get_logger
from authentik.lib.config import CONFIG
LOGGER = get_logger()
def get_geoip_reader() -> Optional[Reader]:
"""Get GeoIP Reader, if configured, otherwise none"""
path = CONFIG.y("authentik.geoip")
if path == "" or not path:
return None
try:
reader = Reader(path)
LOGGER.info("Enabled GeoIP support")
return reader
except OSError:
return None
GEOIP_READER = get_geoip_reader()