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

Update Dependencies - Feb 2024 #57

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,27 @@ description = "An automated Slack bot to syndicate local events into Slack chann
readme = "README.md"
requires-python = ">=3.11"
license = { text = "MIT" }
version="0.1.0"
authors = [
{ name = "Olivia Sculley", email = "[email protected]" },
]
keywords = [
"automation",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to reformat this entire file. I was fighting with my autolinter hard, and I think it won.

"black",
"bolt",
"bot",
"pylint",
"pytest",
"slack"
]
version = "0.1.0"
authors = [{ name = "Olivia Sculley", email = "[email protected]" }]
keywords = ["automation", "black", "bolt", "bot", "pylint", "pytest", "slack"]
dependencies = [
"aiohttp==3.9.1",
"fastapi==0.103.2",
"aiohttp==3.9.3",
"fastapi==0.109.2",
"python_dateutil==2.8.2",
"pytz==2023.3",
"slack_bolt==1.18.0",
"uvicorn==0.23.2"
"pytz==2024.1",
"slack_bolt==1.18.1",
"uvicorn==0.27.0.post1",
]

[project.optional-dependencies]
test = [
"black==23.9.1",
"httpx==0.25.0",
"isort==5.12.0",
"pylint==2.17.5",
"pytest==7.4.2",
"pytest-asyncio==0.21.1",
"ssort==0.11.6"
"black==24.1.1",
"httpx==0.26.0",
"isort==5.13.2",
"pylint==3.0.3",
"pytest==7.4.4",
"pytest-asyncio==0.23.4",
"ssort==0.11.6",
]

[project.urls]
Expand All @@ -43,13 +33,8 @@ Documentation = "https://github.com/hackgvl/slack-events-bot/blob/dev/README.md"
Repository = "https://github.com/hackgvl/slack-events-bot.git"

[tool.pytest.ini_options]
pythonpath = [
".",
"src"
]
norecursedirs = [
"tests/helpers"
]
pythonpath = [".", "src"]
norecursedirs = ["tests/helpers"]

[tool.isort]
profile = "black"
1 change: 1 addition & 0 deletions src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Logic for restricting the use of Slack commands to specific parties
and validating incoming requests.
"""

import hashlib
import hmac
import logging
Expand Down
1 change: 1 addition & 0 deletions src/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Contains all the functions that interact with the sqlite database"""

import datetime
import os
import sqlite3
Expand Down
31 changes: 2 additions & 29 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

Visit the /docs route for more information on the routes contained within.
"""

import asyncio
import datetime
import logging
Expand All @@ -16,7 +17,6 @@
import uvicorn
from fastapi import HTTPException, Request
from fastapi.responses import PlainTextResponse
from starlette.types import Message

import database
from auth import validate_slack_command_source
Expand Down Expand Up @@ -84,39 +84,12 @@ async def update_check_api_cooldown(team_domain: str | None) -> None:
await database.create_cooldown(team_domain, "check_api", 15)


async def set_body(req: Request, body: bytes):
"""
Overrides the Request class's __receive method as a workaround to an issue
where accessing a request body in middleware causes it to become blocking.

See https://github.com/tiangolo/fastapi/discussions/8187 for the discussion
and this post (https://github.com/tiangolo/fastapi/discussions/8187#discussioncomment-5148049)
for where this code originates. Thanks, https://github.com/liukelin!
"""

async def receive() -> Message:
return {"type": "http.request", "body": body}

# pylint: disable=protected-access
req._receive = receive


async def get_body(req: Request) -> bytes:
"""
Leans into the overriden Request.__receive method seen above in set_body
to workaround 'await req.body()' causing the application to hang.
"""
body = await req.body()
await set_body(req, body)
return body


@API.middleware("http")
async def rate_limit_check_api(
req: Request, call_next: Callable[[Request], Awaitable[None]]
):
"""Looks to see if /check_api has been run recently, and returns an error if so."""
req_body = await get_body(req)
req_body = await req.body()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish there was a chef's kiss emoji for this!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It felt so good to rip that out, oh my gosh!


if await check_api_being_requested(req.scope["path"], req_body):
team_domain = await identify_slack_team_domain(req_body)
Expand Down
Loading