From c5aa5414adcaa40b5c954ade673e76a65d0c37ec Mon Sep 17 00:00:00 2001 From: Benjamin Bolte Date: Fri, 26 Jul 2024 20:26:36 -0700 Subject: [PATCH] ttl on api key instead --- store/app/model.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/store/app/model.py b/store/app/model.py index 6f674732..076d8d37 100644 --- a/store/app/model.py +++ b/store/app/model.py @@ -48,12 +48,10 @@ class OAuthKey(RobolistBaseModel): user_id: str user_token: str - ttl: int | None = None @classmethod def create(cls, user_token: str, user_id: str) -> Self: - ttl_timestamp = int((datetime.utcnow() + timedelta(days=90)).timestamp()) - return cls(id=str(new_uuid()), user_id=user_id, user_token=user_token, ttl=ttl_timestamp) + return cls(id=str(new_uuid()), user_id=user_id, user_token=user_token) APIKeySource = Literal["user", "oauth"] @@ -72,6 +70,7 @@ class APIKey(RobolistBaseModel): user_id: str source: APIKeySource permissions: set[APIKeyPermission] | None = None + ttl: int | None = None @classmethod def create( @@ -82,11 +81,13 @@ def create( ) -> Self: if permissions == "full": permissions = {"read", "write", "admin"} + ttl_timestamp = int((datetime.utcnow() + timedelta(days=90)).timestamp()) return cls( id=str(new_uuid()), user_id=user_id, source=source, permissions=permissions, + ttl=ttl_timestamp )