forked from QuivrHQ/quivr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(chat): add name update * chore(linting): add flake8 * feat: add chat name edit
- Loading branch information
1 parent
8ed8a2c
commit e1a7404
Showing
25 changed files
with
393 additions
and
154 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[flake8] | ||
; Minimal configuration for Flake8 to work with Black. | ||
max-line-length = 100 | ||
ignore = E101,E111,E112,E221,E222,E501,E711,E712,W503,W504,F401 |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
{ | ||
"[python]": { | ||
"editor.defaultFormatter": "ms-python.autopep8" | ||
}, | ||
"python.formatting.provider": "black", | ||
"editor.codeActionsOnSave": { | ||
"source.organizeImports": true | ||
"source.organizeImports": true, | ||
"source.fixAll":true | ||
}, | ||
"python.linting.enabled": true, | ||
"python.linting.flake8Enabled": true, | ||
"editor.formatOnSave": true, | ||
"[typescript]": { | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"editor.formatOnSave": true | ||
}, | ||
"python.linting.enabled": true | ||
"editor.formatOnSaveMode": "modifications" | ||
} |
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 |
---|---|---|
@@ -1,36 +1,61 @@ | ||
|
||
from datetime import datetime | ||
|
||
from fastapi import HTTPException | ||
from models.settings import CommonsDep | ||
from pydantic import DateError | ||
|
||
|
||
async def verify_api_key(api_key: str, commons: CommonsDep): | ||
async def verify_api_key(api_key: str, commons: CommonsDep): | ||
try: | ||
# Use UTC time to avoid timezone issues | ||
current_date = datetime.utcnow().date() | ||
result = commons['supabase'].table('api_keys').select('api_key', 'creation_time').filter('api_key', 'eq', api_key).filter('is_active', 'eq', True).execute() | ||
result = ( | ||
commons["supabase"] | ||
.table("api_keys") | ||
.select("api_key", "creation_time") | ||
.filter("api_key", "eq", api_key) | ||
.filter("is_active", "eq", True) | ||
.execute() | ||
) | ||
if result.data is not None and len(result.data) > 0: | ||
api_key_creation_date = datetime.strptime(result.data[0]['creation_time'], "%Y-%m-%dT%H:%M:%S").date() | ||
api_key_creation_date = datetime.strptime( | ||
result.data[0]["creation_time"], "%Y-%m-%dT%H:%M:%S" | ||
).date() | ||
|
||
# Check if the API key was created today: Todo remove this check and use deleted_time instead. | ||
if api_key_creation_date == current_date: | ||
return True | ||
return False | ||
except DateError: | ||
return False | ||
|
||
|
||
|
||
async def get_user_from_api_key(api_key: str, commons: CommonsDep): | ||
# Lookup the user_id from the api_keys table | ||
user_id_data = commons['supabase'].table('api_keys').select('user_id').filter('api_key', 'eq', api_key).execute() | ||
|
||
if not user_id_data.data: | ||
raise HTTPException(status_code=400, detail="Invalid API key.") | ||
|
||
user_id = user_id_data.data[0]['user_id'] | ||
user_id_data = ( | ||
commons["supabase"] | ||
.table("api_keys") | ||
.select("user_id") | ||
.filter("api_key", "eq", api_key) | ||
.execute() | ||
) | ||
|
||
if not user_id_data.data: | ||
raise HTTPException(status_code=400, detail="Invalid API key.") | ||
|
||
user_id = user_id_data.data[0]["user_id"] | ||
|
||
# Lookup the email from the users table. Todo: remove and use user_id for credentials | ||
user_email_data = commons['supabase'].table('users').select('email').filter('user_id', 'eq', user_id).execute() | ||
# Lookup the email from the users table. Todo: remove and use user_id for credentials | ||
user_email_data = ( | ||
commons["supabase"] | ||
.table("users") | ||
.select("email") | ||
.filter("user_id", "eq", user_id) | ||
.execute() | ||
) | ||
|
||
return {'email': user_email_data.data[0]['email']} if user_email_data.data else {'email': None} | ||
return ( | ||
{"email": user_email_data.data[0]["email"]} | ||
if user_email_data.data | ||
else {"email": None} | ||
) |
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 |
---|---|---|
|
@@ -14,7 +14,9 @@ def __init__(self, auto_error: bool = True): | |
super().__init__(auto_error=auto_error) | ||
|
||
async def __call__(self, request: Request, commons: CommonsDep): | ||
credentials: Optional[HTTPAuthorizationCredentials] = await super().__call__(request) | ||
credentials: Optional[HTTPAuthorizationCredentials] = await super().__call__( | ||
request | ||
) | ||
self.check_scheme(credentials) | ||
token = credentials.credentials | ||
return await self.authenticate(token, commons) | ||
|
@@ -33,10 +35,13 @@ async def authenticate(self, token: str, commons: CommonsDep): | |
elif await verify_api_key(token, commons): | ||
return await get_user_from_api_key(token, commons) | ||
else: | ||
raise HTTPException(status_code=402, detail="Invalid token or expired token.") | ||
raise HTTPException( | ||
status_code=402, detail="Invalid token or expired token." | ||
) | ||
|
||
def get_test_user(self): | ||
return {'email': '[email protected]'} # replace with test user information | ||
return {"email": "[email protected]"} # replace with test user information | ||
|
||
|
||
def get_current_user(credentials: dict = Depends(AuthBearer())) -> User: | ||
return User(email=credentials.get('email', 'none')) | ||
return User(email=credentials.get("email", "none")) |
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
from pydantic import BaseModel | ||
|
||
|
||
class User (BaseModel): | ||
class User(BaseModel): | ||
email: str |
Oops, something went wrong.