Skip to content

Commit 1f237c2

Browse files
weiivdbluhm
authored andcommitted
refactor: relocate init function
Signed-off-by: Ivan Wei <[email protected]>
1 parent 4b77c59 commit 1f237c2

File tree

4 files changed

+10
-86
lines changed

4 files changed

+10
-86
lines changed
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1 @@
11
"""Status List Plugin v1.0."""
2-
3-
import logging
4-
5-
from acapy_agent.config.injection_context import InjectionContext
6-
from acapy_agent.core.event_bus import Event, EventBus
7-
from acapy_agent.core.profile import Profile
8-
from acapy_agent.core.util import STARTUP_EVENT_PATTERN
9-
from acapy_agent.storage.error import StorageNotFoundError
10-
11-
from .error import StatusListError
12-
from .models import StatusListReg
13-
from .status_handler import get_wallet_id
14-
15-
LOGGER = logging.getLogger(__name__)
16-
17-
18-
async def setup(context: InjectionContext):
19-
"""Setup the plugin."""
20-
21-
event_bus = context.inject(EventBus)
22-
event_bus.subscribe(STARTUP_EVENT_PATTERN, on_startup)
23-
24-
25-
async def on_startup(profile: Profile, event: Event):
26-
"""Startup event handler."""
27-
28-
async with profile.session() as session:
29-
wallet_id = get_wallet_id(profile.context)
30-
try:
31-
registry = await StatusListReg.retrieve_by_id(session, wallet_id)
32-
if registry.list_count < 0:
33-
raise StatusListError("Status list registry has negative list count.")
34-
except StorageNotFoundError:
35-
registry = StatusListReg(id=wallet_id, list_count=0, new_with_id=True)
36-
await registry.save(session, reason="Create new status list registry.")

status_list/status_list/v1_0/status_handler.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from acapy_agent.admin.request_context import AdminRequestContext
1212
from acapy_agent.core.profile import ProfileSession
13+
from acapy_agent.storage.error import StorageNotFoundError
1314
from acapy_agent.wallet.util import bytes_to_b64
1415

1516
from .config import Config
@@ -75,9 +76,14 @@ def get_status_list_file_path(
7576
async def assign_status_list_number(session: ProfileSession, wallet_id: str):
7677
"""Get status list number."""
7778

78-
registry = await StatusListReg.retrieve_by_id(session, wallet_id, for_update=True)
79-
if registry.list_count < 0:
80-
raise StatusListError("Status list registry has negative list count.")
79+
try:
80+
registry = await StatusListReg.retrieve_by_id(
81+
session, wallet_id, for_update=True
82+
)
83+
if registry.list_count < 0:
84+
raise StatusListError("Status list registry has negative list count.")
85+
except StorageNotFoundError:
86+
registry = StatusListReg(id=wallet_id, list_count=0, new_with_id=True)
8187

8288
list_number = registry.list_count
8389
registry.list_count += 1

status_list/status_list/v1_0/tests/conftest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from ..models import StatusListDef, StatusListCred
1717
from ..config import Config
18-
from .. import on_startup, status_handler
18+
from .. import status_handler
1919

2020

2121
def pytest_collection_modifyitems(items):
@@ -95,7 +95,6 @@ async def init(context: AdminRequestContext):
9595
seed="testseed000000000000000000000001",
9696
did="did:web:dev.lab.di.gov.on.ca",
9797
)
98-
await on_startup(context.profile, None)
9998
yield
10099

101100

status_list/status_list/v1_0/tests/test_init.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)