Skip to content

Commit

Permalink
removed constant DAILY_UPLOAD_LIMIT_BYTES from operation_validator an…
Browse files Browse the repository at this point in the history
…d instead retrieving value from get_settings()
  • Loading branch information
fullerzz committed Sep 4, 2024
1 parent 006deec commit 28338d6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/smolvault/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Settings(BaseSettings):
auth_secret_key: str
user_whitelist: str
users_limit: int
daily_upload_limit_bytes: int

model_config = SettingsConfigDict(env_file=".env")

Expand Down
4 changes: 2 additions & 2 deletions src/smolvault/validators/operation_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
from smolvault.clients.database import DatabaseClient
from smolvault.config import get_settings

DAILY_UPLOAD_LIMIT_BYTES = 1_000_000_000
logger = logging.getLogger(__name__)


class UploadValidator:
def __init__(self) -> None:
self.settings = get_settings()
self.daily_upload_limit_bytes = self.settings.daily_upload_limit_bytes
self.whitelist = self.settings.user_whitelist.split(",")

def upload_allowed(self, user_id: int, db_client: DatabaseClient) -> bool:
Expand All @@ -24,7 +24,7 @@ def _uploads_under_limit_prev_24h(self, user_id: int, db_client: DatabaseClient)
metadata = db_client.get_all_metadata(user_id, start_time=start_time)
bytes_uploaded = sum([record.size for record in metadata])
logger.info("User %s has uploaded %d bytes in the last 24 hours", user_id, bytes_uploaded)
return bytes_uploaded < DAILY_UPLOAD_LIMIT_BYTES
return bytes_uploaded < self.daily_upload_limit_bytes

def _user_on_whitelist(self, user_id: int) -> bool:
logger.info("Checking whitelist for user %s", user_id)
Expand Down
1 change: 1 addition & 0 deletions tests/testing.env
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ SMOLVAULT_DB="test.db"
SMOLVAULT_CACHE="./uploads/"
USER_WHITELIST="1,2"
USERS_LIMIT="3"
DAILY_UPLOAD_LIMIT_BYTES="1000000000"

0 comments on commit 28338d6

Please sign in to comment.