Skip to content

Commit

Permalink
fix: model aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
leoguillaumegouv committed Dec 20, 2024
1 parent 5bd3ff1 commit 741b0cd
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/clients/_authenticationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ def __init__(self, cache: Redis, table_id: str, *args, **kwargs) -> None:
self.table_id = table_id
self.redis = cache

# @TODO: check columns exists in Grist

async def check_api_key(self, key: str) -> Optional[User]:
"""
Get API key details from cache or Grist and return a User object.
Expand Down
2 changes: 2 additions & 0 deletions app/clients/search/_elasticsearchclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ def create_collection(
"""
See SearchClient.create_collection
"""

collection_model = self.models[collection_model].id # replace alias by model id
if self.models[collection_model].type != EMBEDDINGS_MODEL_TYPE:
raise WrongModelTypeException()

Expand Down
2 changes: 2 additions & 0 deletions app/clients/search/_qdrantsearchclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ def create_collection(
"""
See SearchClient.create_collection
"""

collection_model = self.models[collection_model].id # replace alias by model id
if self.models[collection_model].type != EMBEDDINGS_MODEL_TYPE:
raise WrongModelTypeException()

Expand Down
2 changes: 1 addition & 1 deletion app/schemas/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Models(ConfigBaseModel):
@field_validator("aliases", mode="before")
def validate_aliases(cls, aliases):
unique_aliases = list()
for key, values in aliases.items():
for _, values in aliases.items():
unique_aliases.extend(values)

assert len(unique_aliases) == len(set(unique_aliases)), "Duplicated aliases found."
Expand Down
2 changes: 1 addition & 1 deletion app/utils/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def check_rate_limit(request: Request) -> Optional[str]:
Returns:
Optional[str]: user_id if the access level is 0, None otherwise (no rate limit applied).
"""

# @TODO: add a middleware to check the key and forward user role to the request
authorization = request.headers.get("Authorization")
scheme, credentials = authorization.split(" ") if authorization else ("", "")
api_key = HTTPAuthorizationCredentials(scheme=scheme, credentials=credentials)
Expand Down
6 changes: 3 additions & 3 deletions docs/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ L'API implémente un système de rôle à 3 niveaux :

| Niveau du rôle | Description |
| --- | --- |
| 0 (user) | Accès limité à l'API (rate limiting) et aucun droits d'édition sur les collections publiques |
| 1 (client) | Accès illimité à l'API et aucun droits d'édition sur les collections publiques |
| 2 (admin) | Accès illimité à l'API et droits d'édition sur toutes les collections |
| 0 (user) | Aucun droits d'édition sur les collections publiques |
| 1 (client) | Aucun droits d'édition sur les collections publiques |
| 2 (admin) | Droits d'édition sur toutes les collections |

Par défaut, le rate limiting est de 100 requêtes par minute pour tous les niveaux. Il est de 10 requêtes par minute pour le niveau 0 (user) pour les endpoints tagués *Core*.

0 comments on commit 741b0cd

Please sign in to comment.