Coverage for src/kwai/modules/identity/tokens/access_token_repository.py: 100%
7 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Module that defines an interface for an access token repository."""
3from abc import abstractmethod
4from typing import Iterator
6from kwai.modules.identity.tokens.access_token import (
7 AccessTokenEntity,
8 AccessTokenIdentifier,
9)
10from kwai.modules.identity.tokens.access_token_query import AccessTokenQuery
11from kwai.modules.identity.tokens.token_identifier import TokenIdentifier
14class AccessTokenNotFoundException(Exception):
15 """Raised when the access token could not be found."""
18class AccessTokenRepository:
19 """Interface for an access token repository."""
21 @abstractmethod
22 def create_query(self) -> AccessTokenQuery:
23 """Create a query for a access token."""
24 raise NotImplementedError
26 @abstractmethod
27 async def create(self, access_token: AccessTokenEntity) -> AccessTokenEntity:
28 """Save a new access token."""
29 raise NotImplementedError
31 @abstractmethod
32 async def update(self, access_token: AccessTokenEntity):
33 """Update the access token."""
34 raise NotImplementedError
36 @abstractmethod
37 async def get(self, id_: AccessTokenIdentifier) -> AccessTokenEntity:
38 """Get the access token with the given id."""
39 raise NotImplementedError
41 @abstractmethod
42 async def get_by_identifier(self, identifier: TokenIdentifier) -> AccessTokenEntity:
43 """Get the access token with the given identifier."""
44 raise NotImplementedError
46 @abstractmethod
47 async def get_all(
48 self,
49 query: AccessTokenQuery | None = None,
50 limit: int | None = None,
51 offset: int | None = None,
52 ) -> Iterator[AccessTokenEntity]:
53 """Get all access token."""
54 raise NotImplementedError