Skip to content

Commit

Permalink
Merge branch 'main' into gha_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ianco authored Apr 1, 2021
2 parents affc176 + d64c3a0 commit 5ab4235
Show file tree
Hide file tree
Showing 35 changed files with 404 additions and 174 deletions.
43 changes: 28 additions & 15 deletions aries_cloudagent/protocols/issue_credential/v2_0/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,15 @@ async def get_detail_record(

async with self._profile.session() as session:
detail_cls = fmt.detail
try:
return await detail_cls.retrieve_by_cred_ex_id(session, cred_ex_id)
except StorageNotFoundError:
return None
records = await detail_cls.query_by_cred_ex_id(session, cred_ex_id)
if len(records) > 1:
LOGGER.warning(
"Cred ex id %s has %d %s detail records: should be 1",
cred_ex_id,
len(records),
fmt.api,
)
return records[0] if records else None

async def prepare_send(
self,
Expand Down Expand Up @@ -408,6 +413,16 @@ async def receive_offer(

return cred_ex_record

async def _check_uniqueness(self, cred_ex_id: str):
"""Raise exception on evidence that cred ex already has cred issued to it."""
async with self._profile.session() as session:
for fmt in V20CredFormat.Format:
if await fmt.detail.query_by_cred_ex_id(session, cred_ex_id):
raise V20CredManagerError(
f"{fmt.api} detail record already "
f"exists for cred ex id {cred_ex_id}"
)

async def create_request(
self, cred_ex_record: V20CredExRecord, holder_did: str, comment: str = None
) -> Tuple[V20CredExRecord, V20CredRequest]:
Expand Down Expand Up @@ -470,6 +485,7 @@ async def _create_indy():
if not cred_req_result:
cred_req_result = await _create_indy()

await self._check_uniqueness(cred_ex_record.cred_ex_id)
detail_record = V20CredExRecordIndy(
cred_ex_id=cred_ex_record.cred_ex_id,
cred_request_metadata=cred_req_result["metadata"],
Expand Down Expand Up @@ -629,7 +645,7 @@ async def issue_credential(
)
if retries > 0:
LOGGER.info(
("Waiting 2s on posted rev reg " "for cred def %s, retrying"),
"Waiting 2s on posted rev reg for cred def %s, retrying",
cred_def_id,
)
await asyncio.sleep(2)
Expand All @@ -640,7 +656,7 @@ async def issue_credential(
)

raise V20CredManagerError(
f"Cred def id {cred_def_id} " "has no active revocation registry"
f"Cred def id {cred_def_id} has no active revocation registry"
)
del revoc

Expand All @@ -658,7 +674,7 @@ async def issue_credential(
rev_reg_id,
tails_path,
)

await self._check_uniqueness(cred_ex_record.cred_ex_id)
detail_record = V20CredExRecordIndy(
cred_ex_id=cred_ex_record.cred_ex_id,
rev_reg_id=rev_reg_id,
Expand Down Expand Up @@ -894,14 +910,11 @@ async def delete_cred_ex_record(self, cred_ex_id: str) -> None:

async with self._profile.session() as session:
for fmt in V20CredFormat.Format: # details first: do not strand any orphans
try:
detail_record = await fmt.detail.retrieve_by_cred_ex_id(
session,
cred_ex_id,
)
await detail_record.delete_record(session)
except StorageNotFoundError:
pass
for record in await fmt.detail.query_by_cred_ex_id(
session,
cred_ex_id,
):
await record.delete_record(session)

cred_ex_record = await V20CredExRecord.retrieve_by_id(session, cred_ex_id)
await cred_ex_record.delete_record(session)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""DIF-specific credential exchange information with non-secrets storage."""

from typing import Any
from typing import Any, Sequence

from marshmallow import EXCLUDE, fields

Expand Down Expand Up @@ -57,16 +57,15 @@ def record_value(self) -> dict:
}

@classmethod
async def retrieve_by_cred_ex_id(
async def query_by_cred_ex_id(
cls,
session: ProfileSession,
cred_ex_id: str,
) -> "V20CredExRecordDIF":
) -> Sequence:
"""Retrieve a credential exchange DIF detail record by its cred ex id."""
return await cls.retrieve_by_tag_filter(
session,
{"cred_ex_id": cred_ex_id},
None,
return await cls.query(
session=session,
tag_filter={"cred_ex_id": cred_ex_id},
)

def __eq__(self, other: Any) -> bool:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Indy-specific credential exchange information with non-secrets storage."""

from typing import Any, Mapping
from typing import Any, Mapping, Sequence

from marshmallow import EXCLUDE, fields

Expand Down Expand Up @@ -60,16 +60,15 @@ def record_value(self) -> dict:
}

@classmethod
async def retrieve_by_cred_ex_id(
async def query_by_cred_ex_id(
cls,
session: ProfileSession,
cred_ex_id: str,
) -> "V20CredExRecordIndy":
"""Retrieve a credential exchange indy detail record by its cred ex id."""
return await cls.retrieve_by_tag_filter(
session,
{"cred_ex_id": cred_ex_id},
None,
) -> Sequence:
"""Retrieve credential exchange indy detail record(s) by its cred ex id."""
return await cls.query(
session=session,
tag_filter={"cred_ex_id": cred_ex_id},
)

def __eq__(self, other: Any) -> bool:
Expand Down
Loading

0 comments on commit 5ab4235

Please sign in to comment.