Turns out, getting this thing out into the wild isn't as simple as I thought :D Co-authored-by: Tomek Wójcik <labs@tomekwojcik.pl> Co-committed-by: Tomek Wójcik <labs@tomekwojcik.pl>
44 lines
1.0 KiB
Python
44 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import annotations
|
|
|
|
import urllib.parse
|
|
import uuid
|
|
|
|
import pydantic
|
|
|
|
from hotpocket_common.constants import AccessTokenOriginApp
|
|
|
|
from .base import ModelOut, Query
|
|
|
|
|
|
class AccessTokenOut(ModelOut):
|
|
key: str
|
|
origin: str
|
|
meta: dict
|
|
|
|
def get_parsed_origin(self) -> urllib.parse.SplitResult:
|
|
return urllib.parse.urlsplit(self.origin)
|
|
|
|
def get_origin_app(self) -> AccessTokenOriginApp | None:
|
|
parsed_origin = self.get_parsed_origin()
|
|
|
|
match parsed_origin.scheme:
|
|
case 'safari-web-extension':
|
|
return AccessTokenOriginApp.SAFARI_WEB_EXTENSION
|
|
|
|
case _:
|
|
return None
|
|
|
|
def get_origin_app_id(self) -> str:
|
|
return self.get_parsed_origin().netloc
|
|
|
|
|
|
class AccessTokensQuery(Query):
|
|
account_uuid: uuid.UUID
|
|
before: uuid.UUID | None = pydantic.Field(default=None)
|
|
|
|
|
|
class AccessTokenMetaUpdateIn(pydantic.BaseModel):
|
|
version: str | None = None
|
|
platform: str | None = None
|