Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SSLContext arg to aiohttp adapter #483

Merged
merged 8 commits into from
Feb 7, 2025
8 changes: 7 additions & 1 deletion twitchio/web/aio_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import asyncio
import datetime
import ssl
EvieePy marked this conversation as resolved.
Show resolved Hide resolved
import logging
from collections import deque
from typing import TYPE_CHECKING, Any, cast
Expand Down Expand Up @@ -101,6 +102,8 @@ class AiohttpAdapter(BaseAdapter, web.Application):
An optional :class:`str` passed to use as the EventSub secret. It is recommended you pass this parameter when using
an adapter for EventSub, as it will reset upon restarting otherwise. You can generate token safe secrets with the
:mod:`secrets` module.
ssl_context: ssl.SSLContext | None
An optional :class:`ssl.SSLContext` passed to the adapter. If SSL is setup via a front-facing web server such as NGINX, you should leave this as None.

Examples
--------
Expand Down Expand Up @@ -139,6 +142,7 @@ def __init__(
domain: str | None = None,
eventsub_path: str | None = None,
eventsub_secret: str | None = None,
ssl_context: ssl.SSLContext | None = None,
) -> None:
super().__init__()
self._runner: web.AppRunner | None = None
Expand All @@ -160,6 +164,8 @@ def __init__(
path: str = eventsub_path.removeprefix("/").removesuffix("/") if eventsub_path else "callback"
self._eventsub_path: str = f"/{path}"

self._ssl_context: ssl.SSLContext = ssl_context
EvieePy marked this conversation as resolved.
Show resolved Hide resolved

self._runner_task: asyncio.Task[None] | None = None
self.startup = self.event_startup
self.shutdown = self.event_shutdown
Expand Down Expand Up @@ -210,7 +216,7 @@ async def run(self, host: str | None = None, port: int | None = None) -> None:
self._runner = web.AppRunner(self, access_log=None, handle_signals=True)
await self._runner.setup()

site: web.TCPSite = web.TCPSite(self._runner, host or self._host, port or self._port)
site: web.TCPSite = web.TCPSite(self._runner, host or self._host, port or self._port, ssl_context=self._ssl_context)
self._runner_task = asyncio.create_task(site.start(), name=f"twitchio-web-adapter:{self.__class__.__qualname__}")

async def eventsub_callback(self, request: web.Request) -> web.Response:
Expand Down