Skip to content

Commit b47e85d

Browse files
Improve new cookie handling
1 parent 2d80f50 commit b47e85d

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

utils/msl/memberships.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from utils import GLOBAL_SSL_CONTEXT
1414

1515
if TYPE_CHECKING:
16-
from collections.abc import Mapping, Sequence
16+
from collections.abc import Mapping, MutableMapping, Sequence
1717
from http.cookies import Morsel
1818
from logging import Logger
1919
from typing import Final
@@ -29,15 +29,16 @@
2929

3030
logger: "Final[Logger]" = logging.getLogger("TeX-Bot")
3131

32+
SU_PLATFORM_ACCESS_COOKIE: "Final[str]" = settings["SU_PLATFORM_ACCESS_COOKIE"]
3233

3334
BASE_SU_PLATFORM_WEB_HEADERS: "Final[Mapping[str, str]]" = {
3435
"Cache-Control": "no-cache",
3536
"Pragma": "no-cache",
3637
"Expires": "0",
3738
}
3839

39-
BASE_SU_PLATFORM_WEB_COOKIES: "Final[Mapping[str, str]]" = {
40-
".AspNet.SharedCookie": settings["SU_PLATFORM_ACCESS_COOKIE"],
40+
BASE_SU_PLATFORM_WEB_COOKIES: "Final[MutableMapping[str, str]]" = {
41+
".AspNet.SharedCookie": SU_PLATFORM_ACCESS_COOKIE,
4142
}
4243

4344
MEMBERS_LIST_URL: "Final[str]" = f"https://guildofstudents.com/organisation/memberlist/{settings['ORGANISATION_ID']}/?sort=groups"
@@ -56,11 +57,11 @@ async def fetch_url_content_with_session(url: str) -> str:
5657
returned_asp_cookie: Morsel | None = http_response.cookies.get(".AspNet.SharedCookie") # type: ignore[type-arg]
5758
if (
5859
returned_asp_cookie
59-
and returned_asp_cookie.value != settings["SU_PLATFORM_ACCESS_COOKIE"]
60+
and returned_asp_cookie.value
61+
!= BASE_SU_PLATFORM_WEB_COOKIES[".AspNet.SharedCookie"]
6062
):
61-
logger.warning("MSL sent a new cookie...")
62-
logger.debug("Old cookie: %s", settings["SU_PLATFORM_ACCESS_COOKIE"])
63-
logger.debug("New cookie: %s", returned_asp_cookie)
63+
logger.info("SU platform access cookie was updated by the server; updating local.")
64+
BASE_SU_PLATFORM_WEB_COOKIES[".AspNet.SharedCookie"] = returned_asp_cookie.value
6465
return await http_response.text()
6566

6667

0 commit comments

Comments
 (0)