Skip to content

Commit 849b88b

Browse files
committed
🐛 Fix yet another circular import issue
Signed-off-by: ff137 <[email protected]>
1 parent 5214ae6 commit 849b88b

File tree

6 files changed

+108
-87
lines changed

6 files changed

+108
-87
lines changed

acapy_agent/indy/constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""Constants for Indy."""
2+
3+
CATEGORY_CRED_DEF = "credential_def"
4+
CATEGORY_CRED_DEF_PRIVATE = "credential_def_private"
5+
CATEGORY_CRED_DEF_KEY_PROOF = "credential_def_key_proof"
6+
7+
CATEGORY_SCHEMA = "schema"
8+
9+
CATEGORY_REV_REG = "revocation_reg"
10+
CATEGORY_REV_REG_DEF = "revocation_reg_def"
11+
CATEGORY_REV_REG_DEF_PRIVATE = "revocation_reg_def_private"
12+
CATEGORY_REV_REG_INFO = "revocation_reg_info"
13+
CATEGORY_REV_REG_ISSUER = "revocation_reg_def_issuer"

acapy_agent/indy/credx/issuer.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import asyncio
44
import logging
5-
from typing import Optional, Sequence, Tuple
5+
from typing import TYPE_CHECKING, Optional, Sequence, Tuple
66

77
from aries_askar import AskarError
88
from indy_credx import (
@@ -18,8 +18,17 @@
1818
Schema,
1919
)
2020

21-
from ...askar.profile import AskarProfile
2221
from ...utils.general import strip_did_prefix
22+
from ..constants import (
23+
CATEGORY_CRED_DEF,
24+
CATEGORY_CRED_DEF_KEY_PROOF,
25+
CATEGORY_CRED_DEF_PRIVATE,
26+
CATEGORY_REV_REG,
27+
CATEGORY_REV_REG_DEF,
28+
CATEGORY_REV_REG_DEF_PRIVATE,
29+
CATEGORY_REV_REG_INFO,
30+
CATEGORY_SCHEMA,
31+
)
2332
from ..issuer import (
2433
DEFAULT_CRED_DEF_TAG,
2534
DEFAULT_SIGNATURE_TYPE,
@@ -28,23 +37,16 @@
2837
IndyIssuerRevocationRegistryFullError,
2938
)
3039

31-
LOGGER = logging.getLogger(__name__)
40+
if TYPE_CHECKING:
41+
from ...askar.profile import AskarProfile
3242

33-
CATEGORY_CRED_DEF = "credential_def"
34-
CATEGORY_CRED_DEF_PRIVATE = "credential_def_private"
35-
CATEGORY_CRED_DEF_KEY_PROOF = "credential_def_key_proof"
36-
CATEGORY_SCHEMA = "schema"
37-
CATEGORY_REV_REG = "revocation_reg"
38-
CATEGORY_REV_REG_INFO = "revocation_reg_info"
39-
CATEGORY_REV_REG_DEF = "revocation_reg_def"
40-
CATEGORY_REV_REG_DEF_PRIVATE = "revocation_reg_def_private"
41-
CATEGORY_REV_REG_ISSUER = "revocation_reg_def_issuer"
43+
LOGGER = logging.getLogger(__name__)
4244

4345

4446
class IndyCredxIssuer(IndyIssuer):
4547
"""Indy-Credx issuer class."""
4648

47-
def __init__(self, profile: AskarProfile):
49+
def __init__(self, profile: "AskarProfile"):
4850
"""Initialize an IndyCredxIssuer instance.
4951
5052
Args:
@@ -54,7 +56,7 @@ def __init__(self, profile: AskarProfile):
5456
self._profile = profile
5557

5658
@property
57-
def profile(self) -> AskarProfile:
59+
def profile(self) -> "AskarProfile":
5860
"""Accessor for the profile instance."""
5961
return self._profile
6062

acapy_agent/indy/util.py

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Utilities for dealing with Indy conventions."""
22

3-
import asyncio
43
import logging
54
import os
65
from os import getenv, makedirs, urandom
@@ -9,10 +8,6 @@
98
from platform import system
109
from typing import Optional
1110

12-
from ..core.profile import Profile
13-
from ..revocation.models.issuer_rev_reg_record import IssuerRevRegRecord
14-
from .issuer import IndyIssuerError
15-
1611
LOGGER = logging.getLogger(__name__)
1712

1813
REVOCATION_REGISTRY_CREATION_TIMEOUT = float(
@@ -52,69 +47,3 @@ def indy_client_dir(subpath: Optional[str] = None, create: bool = False) -> str:
5247
makedirs(target_dir, exist_ok=True)
5348

5449
return target_dir
55-
56-
57-
async def wait_for_active_revocation_registry(profile: Profile, cred_def_id: str) -> None:
58-
"""Wait for revocation registry setup to complete.
59-
60-
Polls for the creation of revocation registry definitions until we have
61-
the 1 active registry or timeout occurs.
62-
63-
Args:
64-
profile: The profile
65-
cred_def_id: The credential definition ID
66-
67-
Raises:
68-
IndyIssuerError: If timeout occurs before completion
69-
"""
70-
LOGGER.debug(
71-
"Waiting for revocation setup completion for cred_def_id: %s", cred_def_id
72-
)
73-
74-
expected_count = 1 # Active registry
75-
poll_interval = 0.5 # Poll every 500ms
76-
max_iterations = int(REVOCATION_REGISTRY_CREATION_TIMEOUT / poll_interval)
77-
registries = []
78-
79-
for _iteration in range(max_iterations):
80-
try:
81-
# Check for finished revocation registry definitions
82-
async with profile.session() as session:
83-
registries = await IssuerRevRegRecord.query_by_cred_def_id(
84-
session, cred_def_id, IssuerRevRegRecord.STATE_ACTIVE
85-
)
86-
87-
current_count = len(registries)
88-
LOGGER.debug(
89-
"Revocation setup progress for %s: %d registries active",
90-
cred_def_id,
91-
current_count,
92-
)
93-
94-
if current_count >= expected_count:
95-
LOGGER.info(
96-
"Revocation setup completed for cred_def_id: %s "
97-
"(%d registries created)",
98-
cred_def_id,
99-
current_count,
100-
)
101-
return
102-
103-
except Exception as e:
104-
LOGGER.warning(
105-
"Error checking revocation setup progress for %s: %s", cred_def_id, e
106-
)
107-
# Continue polling despite errors - they might be transient
108-
109-
await asyncio.sleep(poll_interval) # Wait before next poll
110-
111-
# Timeout occurred
112-
current_count = len(registries)
113-
114-
raise IndyIssuerError(
115-
"Timeout waiting for revocation setup completion for credential definition "
116-
f"{cred_def_id}. Expected 1 active revocation registries, but none "
117-
f"were active within {REVOCATION_REGISTRY_CREATION_TIMEOUT} seconds. "
118-
"Note: Revocation registry creation may still be in progress in the "
119-
"background. You can check status using the revocation registry endpoints."
120-
)

acapy_agent/messaging/credential_definitions/routes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from ...core.profile import Profile
2424
from ...indy.issuer import IndyIssuer, IndyIssuerError
2525
from ...indy.models.cred_def import CredentialDefinitionSchema
26-
from ...indy.util import wait_for_active_revocation_registry
26+
from ...utils.wait_for_active_registry import wait_for_active_revocation_registry
2727
from ...ledger.base import BaseLedger
2828
from ...ledger.error import LedgerError
2929
from ...ledger.multiple_ledger.ledger_requests_executor import (

acapy_agent/revocation/models/issuer_rev_reg_record.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from uuid_utils import uuid4
1515

1616
from ...core.profile import Profile, ProfileSession
17-
from ...indy.credx.issuer import (
17+
from ...indy.constants import (
1818
CATEGORY_CRED_DEF,
1919
CATEGORY_REV_REG,
2020
CATEGORY_REV_REG_DEF_PRIVATE,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
"""Utility method for waiting for active revocation registry."""
2+
3+
import asyncio
4+
import logging
5+
6+
from ..core.profile import Profile
7+
from ..indy.issuer import IndyIssuerError
8+
from ..indy.util import REVOCATION_REGISTRY_CREATION_TIMEOUT
9+
from ..revocation.models.issuer_rev_reg_record import IssuerRevRegRecord
10+
11+
LOGGER = logging.getLogger(__name__)
12+
13+
14+
async def wait_for_active_revocation_registry(profile: Profile, cred_def_id: str) -> None:
15+
"""Wait for revocation registry setup to complete.
16+
17+
Polls for the creation of revocation registry definitions until we have
18+
the 1 active registry or timeout occurs.
19+
20+
Args:
21+
profile: The profile
22+
cred_def_id: The credential definition ID
23+
24+
Raises:
25+
IndyIssuerError: If timeout occurs before completion
26+
"""
27+
LOGGER.debug(
28+
"Waiting for revocation setup completion for cred_def_id: %s", cred_def_id
29+
)
30+
31+
expected_count = 1 # Active registry
32+
poll_interval = 0.5 # Poll every 500ms
33+
max_iterations = int(REVOCATION_REGISTRY_CREATION_TIMEOUT / poll_interval)
34+
registries = []
35+
36+
for _iteration in range(max_iterations):
37+
try:
38+
# Check for finished revocation registry definitions
39+
async with profile.session() as session:
40+
registries = await IssuerRevRegRecord.query_by_cred_def_id(
41+
session, cred_def_id, IssuerRevRegRecord.STATE_ACTIVE
42+
)
43+
44+
current_count = len(registries)
45+
LOGGER.debug(
46+
"Revocation setup progress for %s: %d registries active",
47+
cred_def_id,
48+
current_count,
49+
)
50+
51+
if current_count >= expected_count:
52+
LOGGER.info(
53+
"Revocation setup completed for cred_def_id: %s "
54+
"(%d registries created)",
55+
cred_def_id,
56+
current_count,
57+
)
58+
return
59+
60+
except Exception as e:
61+
LOGGER.warning(
62+
"Error checking revocation setup progress for %s: %s", cred_def_id, e
63+
)
64+
# Continue polling despite errors - they might be transient
65+
66+
await asyncio.sleep(poll_interval) # Wait before next poll
67+
68+
# Timeout occurred
69+
current_count = len(registries)
70+
71+
raise IndyIssuerError(
72+
"Timeout waiting for revocation setup completion for credential definition "
73+
f"{cred_def_id}. Expected 1 active revocation registries, but none "
74+
f"were active within {REVOCATION_REGISTRY_CREATION_TIMEOUT} seconds. "
75+
"Note: Revocation registry creation may still be in progress in the "
76+
"background. You can check status using the revocation registry endpoints."
77+
)

0 commit comments

Comments
 (0)