Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add status list support for acapy #1470

Merged
merged 4 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor: relocate init function
Signed-off-by: Ivan Wei <ivan.wei@ontario.ca>
  • Loading branch information
weiiv committed Feb 5, 2025
commit e534717130be2dc0e7fb147f1a363e04bd41030a
35 changes: 0 additions & 35 deletions status_list/status_list/v1_0/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
"""Status List Plugin v1.0."""

import logging

from acapy_agent.config.injection_context import InjectionContext
from acapy_agent.core.event_bus import Event, EventBus
from acapy_agent.core.profile import Profile
from acapy_agent.core.util import STARTUP_EVENT_PATTERN
from acapy_agent.storage.error import StorageNotFoundError

from .error import StatusListError
from .models import StatusListReg
from .status_handler import get_wallet_id

LOGGER = logging.getLogger(__name__)


async def setup(context: InjectionContext):
"""Setup the plugin."""

event_bus = context.inject(EventBus)
event_bus.subscribe(STARTUP_EVENT_PATTERN, on_startup)


async def on_startup(profile: Profile, event: Event):
"""Startup event handler."""

async with profile.session() as session:
wallet_id = get_wallet_id(profile.context)
try:
registry = await StatusListReg.retrieve_by_id(session, wallet_id)
if registry.list_count < 0:
raise StatusListError("Status list registry has negative list count.")
except StorageNotFoundError:
registry = StatusListReg(id=wallet_id, list_count=0, new_with_id=True)
await registry.save(session, reason="Create new status list registry.")
12 changes: 9 additions & 3 deletions status_list/status_list/v1_0/status_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from acapy_agent.admin.request_context import AdminRequestContext
from acapy_agent.core.profile import ProfileSession
from acapy_agent.storage.error import StorageNotFoundError
from acapy_agent.wallet.util import bytes_to_b64

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

registry = await StatusListReg.retrieve_by_id(session, wallet_id, for_update=True)
if registry.list_count < 0:
raise StatusListError("Status list registry has negative list count.")
try:
registry = await StatusListReg.retrieve_by_id(
session, wallet_id, for_update=True
)
if registry.list_count < 0:
raise StatusListError("Status list registry has negative list count.")
except StorageNotFoundError:
registry = StatusListReg(id=wallet_id, list_count=0, new_with_id=True)

list_number = registry.list_count
registry.list_count += 1
Expand Down
3 changes: 1 addition & 2 deletions status_list/status_list/v1_0/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from ..models import StatusListDef, StatusListCred
from ..config import Config
from .. import on_startup, status_handler
from .. import status_handler


def pytest_collection_modifyitems(items):
Expand Down Expand Up @@ -95,7 +95,6 @@ async def init(context: AdminRequestContext):
seed="testseed000000000000000000000001",
did="did:web:dev.lab.di.gov.on.ca",
)
await on_startup(context.profile, None)
yield


Expand Down
46 changes: 0 additions & 46 deletions status_list/status_list/v1_0/tests/test_init.py

This file was deleted.