-
Notifications
You must be signed in to change notification settings - Fork 17
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
Include more headers with logins #79
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from __future__ import annotations | ||
|
||
from asyncpg import Record | ||
from attr import dataclass | ||
|
||
from mautrix.types import UserID | ||
|
||
from .model_base import Model | ||
|
||
|
||
@dataclass | ||
class HttpHeader(Model): | ||
mxid: UserID | ||
name: str | ||
value: str | ||
|
||
_table_name = "http_header" | ||
_field_list = [ | ||
"mxid", | ||
"name", | ||
"value", | ||
] | ||
|
||
@classmethod | ||
def _from_row(cls, row: Record | None) -> HttpHeader | None: | ||
if row is None: | ||
return None | ||
return cls(**row) | ||
|
||
@classmethod | ||
async def get_for_mxid(cls, mxid: id.UserID) -> list[HttpHeader]: | ||
query = HttpHeader.select_constructor("mxid=$1") | ||
rows = await cls.db.fetch(query, mxid) | ||
return [cls._from_row(row) for row in rows if row] | ||
|
||
@classmethod | ||
async def delete_all_for_mxid(cls, mxid: id.UserID): | ||
await cls.db.execute("DELETE FROM http_header WHERE mxid=$1", mxid) | ||
|
||
@classmethod | ||
async def bulk_upsert(cls, mxid: id.UserID, http_headers: dict[str, str]): | ||
for name, value in http_headers.items(): | ||
http_header = cls(mxid, name, value) | ||
await http_header.upsert() | ||
|
||
async def upsert(self): | ||
query = """ | ||
INSERT INTO http_header (mxid, name, value) | ||
VALUES ($1, $2, $3) | ||
ON CONFLICT (mxid, name) | ||
DO UPDATE | ||
SET value=excluded.value | ||
""" | ||
await self.db.execute(query, self.mxid, self.name, self.value) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from mautrix.util.async_db import Connection | ||
|
||
from . import upgrade_table | ||
|
||
|
||
@upgrade_table.register(description="Add a header table for storing all of the headers") | ||
async def upgrade_v10(conn: Connection): | ||
await conn.execute( | ||
""" | ||
CREATE TABLE http_header ( | ||
mxid TEXT, | ||
name TEXT, | ||
value TEXT, | ||
|
||
PRIMARY KEY (mxid, name) | ||
) | ||
""" | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably it's worth having a foreign key for mxid to the users table, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I copied what I saw in the cookies table, should I add one there as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is probably fine. We can have the constraint later.