---
apiVersion: v1
kind: ConfigMap
metadata:
  name: app
  namespace: issues
data:
  app.py: |
    import ssl
    from django.conf import settings
    from faststream import FastStream
    from faststream.kafka import KafkaBroker
    from faststream.security import BaseSecurity


    def get_broker() -> KafkaBroker:
        ssl_context = ssl.create_default_context(
            cafile=settings.KAFKA_SSL_CAFILE,
        )

        # Сертификат передаем, но hostname не проверяем
        ssl_context.check_hostname = False

        # Для самоподписанного сертификата
        ssl_context.verify_mode = ssl.CERT_NONE

        security = BaseSecurity(
            ssl_context=ssl_context,
            use_ssl=True,
        )

        broker = KafkaBroker(
            bootstrap_servers=[settings.KAFKA_HOST],
            security=security,
        )

        return broker


    def get_consumer_broker() -> KafkaBroker:
        broker = get_broker()

        from kafka_app.consumers import eav_router

        broker.include_router(eav_router)

        return broker


    def configure_app() -> FastStream:
        broker = get_consumer_broker()

        app = FastStream(broker)

        return app
