Restrict Hackbot triggers to authorized user with editbugs permissions - #6444
Open
ayoubdiourin7 wants to merge 5 commits into
Open
Restrict Hackbot triggers to authorized user with editbugs permissions#6444ayoubdiourin7 wants to merge 5 commits into
ayoubdiourin7 wants to merge 5 commits into
Conversation
suhaibmujahid
requested changes
Jul 31, 2026
ayoubdiourin7
force-pushed
the
feat/hackbot-editbugs-auth-clean
branch
from
August 1, 2026 12:14
28a08b1 to
1f5820a
Compare
Comment on lines
+28
to
+37
| EDITBUGS_GROUP_PHID = "PHID-PROJ-njo5uuqyyq3oijbkhy55" | ||
| _MEMBERSHIP_CACHE_TTL_SECONDS = 60 | ||
| _MISSING_MEMBER_REFRESH_COOLDOWN_SECONDS = 30 | ||
|
|
||
| _editbugs_members_cache: TTLCache[str, frozenset[str]] = TTLCache( | ||
| maxsize=1, | ||
| ttl=_MEMBERSHIP_CACHE_TTL_SECONDS, | ||
| ) | ||
| _editbugs_members_lock = asyncio.Lock() | ||
| _last_editbugs_members_refresh = 0.0 |
Member
There was a problem hiding this comment.
This can grow to be a bit ugly. I would encapsulate this in a class that exposes a simple method to check if the user is authorized or not.
| missing_member_refresh_cooldown_seconds | ||
| ) | ||
|
|
||
| async def is_authorized(self, client: PhabricatorClient, author_phid: str) -> bool: |
Member
There was a problem hiding this comment.
I would pass the client to the constructor instead of here.
|
|
||
| def __init__( | ||
| self, | ||
| group_phid: str, |
Member
There was a problem hiding this comment.
Suggested change
| group_phid: str, | |
| authorized_group_phid: str, |
|
|
||
| # Members of this project are authorized to trigger Hackbot. | ||
| AUTHORIZED_GROUP_PHID = "PHID-PROJ-njo5uuqyyq3oijbkhy55" # bmo-editbugs-team | ||
| phabricator_authorizer = PhabricatorAuthorizer(AUTHORIZED_GROUP_PHID) |
Member
There was a problem hiding this comment.
Instead of using it as a singleton here, I would pass it as a dependency to the FastAPI route. The dependency injection with FastAPI makes it easier to avoid singletons.
|
|
||
| @dataclass(frozen=True) | ||
| class HackbotMention: | ||
| raw: str |
Member
There was a problem hiding this comment.
The name raw is not clear, I would use something like comment, text, or content.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
@hackbotcomment.Resolves #6423