Skip to content

Commit

Permalink
ttl on api key instead
Browse files Browse the repository at this point in the history
  • Loading branch information
codekansas committed Jul 27, 2024
1 parent f68de6d commit c5aa541
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions store/app/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand All @@ -72,6 +70,7 @@ class APIKey(RobolistBaseModel):
user_id: str
source: APIKeySource
permissions: set[APIKeyPermission] | None = None
ttl: int | None = None

@classmethod
def create(
Expand All @@ -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
)


Expand Down

0 comments on commit c5aa541

Please sign in to comment.