Skip to content

Commit 3eba909

Browse files
committed
Fixing formatting issues and unit tests
Signed-off-by: pradeepp88 <pradeep.prakasam@ontario.ca>
1 parent 69b7515 commit 3eba909

2 files changed

Lines changed: 121 additions & 43 deletions

File tree

aries_cloudagent/revocation/routes.py

Lines changed: 106 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ class TxnOrRevRegResultSchema(OpenAPISchema):
101101
"""Result schema for credential definition send request."""
102102

103103
sent = fields.Nested(
104-
RevRegResultSchema(), required=False, definition="Content sent"
104+
RevRegResultSchema(),
105+
required=False,
106+
definition="Content sent",
105107
)
106108
txn = fields.Nested(
107109
TransactionRecordSchema(),
@@ -130,15 +132,19 @@ def validate_fields(self, data, **kwargs):
130132
)
131133

132134
rev_reg_id = fields.Str(
133-
description="Revocation registry identifier", required=False, **INDY_REV_REG_ID
135+
description="Revocation registry identifier",
136+
required=False,
137+
**INDY_REV_REG_ID,
134138
)
135139
cred_rev_id = fields.Str(
136140
description="Credential revocation identifier",
137141
required=False,
138142
**INDY_CRED_REV_ID,
139143
)
140144
cred_ex_id = fields.Str(
141-
description="Credential exchange identifier", required=False, **UUID4
145+
description="Credential exchange identifier",
146+
required=False,
147+
**UUID4,
142148
)
143149

144150

@@ -147,13 +153,18 @@ class RevRegId(OpenAPISchema):
147153

148154
@validates_schema
149155
def validate_fields(self, data, **kwargs):
150-
"""Validate schema fields - must have (rr-id and cr-id) xor cx-id."""
156+
"""Validate schema fields - must have either rr-id or cr-id."""
151157

152158
rev_reg_id = data.get("rev_reg_id")
153159
cred_def_id = data.get("cred_def_id")
154160

161+
if not (rev_reg_id or cred_def_id):
162+
raise ValidationError("Request must have either rev_reg_id or cred_def_id")
163+
155164
rev_reg_id = fields.Str(
156-
description="Revocation registry identifier", required=False, **INDY_REV_REG_ID
165+
description="Revocation registry identifier",
166+
required=False,
167+
**INDY_REV_REG_ID,
157168
)
158169
cred_def_id = fields.Str(
159170
description="Credential definition identifier",
@@ -191,7 +202,8 @@ def validate_fields(self, data, **kwargs):
191202
required=False,
192203
)
193204
notify = fields.Boolean(
194-
description="Send a notification to the credential recipient", required=False
205+
description="Send a notification to the credential recipient",
206+
required=False,
195207
)
196208
notify_version = fields.String(
197209
description="Specify which version of the revocation notification should be sent",
@@ -238,7 +250,9 @@ class TxnOrPublishRevocationsResultSchema(OpenAPISchema):
238250
"""Result schema for credential definition send request."""
239251

240252
sent = fields.Nested(
241-
PublishRevocationsSchema(), required=False, definition="Content sent"
253+
PublishRevocationsSchema(),
254+
required=False,
255+
definition="Content sent",
242256
)
243257
txn = fields.Nested(
244258
TransactionRecordSchema(),
@@ -280,7 +294,9 @@ class CredRevRecordDetailsResultSchema(OpenAPISchema):
280294
class CredRevIndyRecordsResultSchema(OpenAPISchema):
281295
"""Result schema for revoc reg delta."""
282296

283-
rev_reg_delta = fields.Dict(description="Indy revocation registry delta")
297+
rev_reg_delta = fields.Dict(
298+
description="Indy revocation registry delta",
299+
)
284300

285301

286302
class RevRegIssuedResultSchema(OpenAPISchema):
@@ -297,19 +313,22 @@ class RevRegUpdateRequestMatchInfoSchema(OpenAPISchema):
297313
"""Path parameters and validators for request taking rev reg id."""
298314

299315
apply_ledger_update = fields.Bool(
300-
description="Apply updated accumulator transaction to ledger", required=True
316+
description="Apply updated accumulator transaction to ledger",
317+
required=True,
301318
)
302319

303320

304321
class RevRegWalletUpdatedResultSchema(OpenAPISchema):
305322
"""Number of wallet revocation entries status updated."""
306323

307-
rev_reg_delta = fields.Dict(description="Indy revocation registry delta")
324+
rev_reg_delta = fields.Dict(
325+
description="Indy revocation registry delta",
326+
)
308327
accum_calculated = fields.Dict(
309-
description="Calculated accumulator for phantom revocations"
328+
description="Calculated accumulator for phantom revocations",
310329
)
311330
accum_fixed = fields.Dict(
312-
description="Applied ledger transaction to fix revocations"
331+
description="Applied ledger transaction to fix revocations",
313332
)
314333

315334

@@ -375,7 +394,9 @@ class RevRegIdMatchInfoSchema(OpenAPISchema):
375394
"""Path parameters and validators for request taking rev reg id."""
376395

377396
rev_reg_id = fields.Str(
378-
description="Revocation Registry identifier", required=True, **INDY_REV_REG_ID
397+
description="Revocation Registry identifier",
398+
required=True,
399+
**INDY_REV_REG_ID,
379400
)
380401

381402

@@ -393,7 +414,8 @@ class CreateRevRegTxnForEndorserOptionSchema(OpenAPISchema):
393414
"""Class for user to input whether to create a transaction for endorser or not."""
394415

395416
create_transaction_for_endorser = fields.Boolean(
396-
description="Create Transaction For Endorser's signature", required=False
417+
description="Create Transaction For Endorser's signature",
418+
required=False,
397419
)
398420

399421

@@ -405,7 +427,10 @@ class RevRegConnIdMatchInfoSchema(OpenAPISchema):
405427
)
406428

407429

408-
@docs(tags=["revocation"], summary="Revoke an issued credential")
430+
@docs(
431+
tags=["revocation"],
432+
summary="Revoke an issued credential",
433+
)
409434
@request_schema(RevokeRequestSchema())
410435
@response_schema(RevocationModuleResponseSchema(), description="")
411436
async def revoke(request: web.BaseRequest):
@@ -477,7 +502,9 @@ async def publish_revocations(request: web.BaseRequest):
477502
rev_manager = RevocationManager(context.profile)
478503

479504
try:
480-
rev_reg_resp = await rev_manager.publish_pending_revocations(rrid2crid)
505+
rev_reg_resp = await rev_manager.publish_pending_revocations(
506+
rrid2crid,
507+
)
481508
except (RevocationError, StorageError, IndyIssuerError, LedgerError) as err:
482509
raise web.HTTPBadRequest(reason=err.roll_up) from err
483510

@@ -548,7 +575,9 @@ async def create_rev_reg(request: web.BaseRequest):
548575
try:
549576
revoc = IndyRevocation(profile)
550577
issuer_rev_reg_rec = await revoc.init_issuer_registry(
551-
credential_definition_id, max_cred_num=max_cred_num, notify=False
578+
credential_definition_id,
579+
max_cred_num=max_cred_num,
580+
notify=False,
552581
)
553582
except RevocationNotSupportedError as e:
554583
raise web.HTTPBadRequest(reason=e.message) from e
@@ -598,7 +627,10 @@ async def rev_regs_created(request: web.BaseRequest):
598627
)
599628

600629

601-
@docs(tags=["revocation"], summary="Get revocation registry by revocation registry id")
630+
@docs(
631+
tags=["revocation"],
632+
summary="Get revocation registry by revocation registry id",
633+
)
602634
@match_info_schema(RevRegIdMatchInfoSchema())
603635
@response_schema(RevRegResultSchema(), 200, description="")
604636
async def get_rev_reg(request: web.BaseRequest):
@@ -693,7 +725,10 @@ async def get_rev_reg_issued(request: web.BaseRequest):
693725
return web.json_response(results)
694726

695727

696-
@docs(tags=["revocation"], summary="Get details of revoked credentials from ledger")
728+
@docs(
729+
tags=["revocation"],
730+
summary="Get details of revoked credentials from ledger",
731+
)
697732
@match_info_schema(RevRegIdMatchInfoSchema())
698733
@response_schema(CredRevIndyRecordsResultSchema(), 200, description="")
699734
async def get_rev_reg_indy_recs(request: web.BaseRequest):
@@ -714,7 +749,11 @@ async def get_rev_reg_indy_recs(request: web.BaseRequest):
714749
revoc = IndyRevocation(context.profile)
715750
rev_reg_delta = await revoc.get_issuer_rev_reg_delta(rev_reg_id)
716751

717-
return web.json_response({"rev_reg_delta": rev_reg_delta})
752+
return web.json_response(
753+
{
754+
"rev_reg_delta": rev_reg_delta,
755+
}
756+
)
718757

719758

720759
@docs(
@@ -805,7 +844,10 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
805844
)
806845

807846

808-
@docs(tags=["revocation"], summary="Get credential revocation status")
847+
@docs(
848+
tags=["revocation"],
849+
summary="Get credential revocation status",
850+
)
809851
@querystring_schema(CredRevRecordQueryStringSchema())
810852
@response_schema(CredRevRecordResultSchema(), 200, description="")
811853
async def get_cred_rev_record(request: web.BaseRequest):
@@ -902,7 +944,10 @@ async def get_tails_file(request: web.BaseRequest) -> web.FileResponse:
902944
return web.FileResponse(path=rev_reg.tails_local_path, status=200)
903945

904946

905-
@docs(tags=["revocation"], summary="Upload local tails file to server")
947+
@docs(
948+
tags=["revocation"],
949+
summary="Upload local tails file to server",
950+
)
906951
@match_info_schema(RevRegIdMatchInfoSchema())
907952
@response_schema(RevocationModuleResponseSchema(), description="")
908953
async def upload_tails_file(request: web.BaseRequest):
@@ -933,7 +978,10 @@ async def upload_tails_file(request: web.BaseRequest):
933978
return web.json_response({})
934979

935980

936-
@docs(tags=["revocation"], summary="Send revocation registry definition to ledger")
981+
@docs(
982+
tags=["revocation"],
983+
summary="Send revocation registry definition to ledger",
984+
)
937985
@match_info_schema(RevRegIdMatchInfoSchema())
938986
@querystring_schema(CreateRevRegTxnForEndorserOptionSchema())
939987
@querystring_schema(RevRegConnIdMatchInfoSchema())
@@ -1003,7 +1051,9 @@ async def send_rev_reg_def(request: web.BaseRequest):
10031051
rev_reg = await revoc.get_issuer_rev_reg_record(rev_reg_id)
10041052

10051053
rev_reg_resp = await rev_reg.send_def(
1006-
profile, write_ledger=write_ledger, endorser_did=endorser_did
1054+
profile,
1055+
write_ledger=write_ledger,
1056+
endorser_did=endorser_did,
10071057
)
10081058
LOGGER.debug("published rev reg definition: %s", rev_reg_id)
10091059
except StorageNotFoundError as err:
@@ -1043,7 +1093,10 @@ async def send_rev_reg_def(request: web.BaseRequest):
10431093
return web.json_response({"txn": transaction.serialize()})
10441094

10451095

1046-
@docs(tags=["revocation"], summary="Send revocation registry entry to ledger")
1096+
@docs(
1097+
tags=["revocation"],
1098+
summary="Send revocation registry entry to ledger",
1099+
)
10471100
@match_info_schema(RevRegIdMatchInfoSchema())
10481101
@querystring_schema(CreateRevRegTxnForEndorserOptionSchema())
10491102
@querystring_schema(RevRegConnIdMatchInfoSchema())
@@ -1111,7 +1164,9 @@ async def send_rev_reg_entry(request: web.BaseRequest):
11111164
revoc = IndyRevocation(profile)
11121165
rev_reg = await revoc.get_issuer_rev_reg_record(rev_reg_id)
11131166
rev_entry_resp = await rev_reg.send_entry(
1114-
profile, write_ledger=write_ledger, endorser_did=endorser_did
1167+
profile,
1168+
write_ledger=write_ledger,
1169+
endorser_did=endorser_did,
11151170
)
11161171
LOGGER.debug("published registry entry: %s", rev_reg_id)
11171172

@@ -1127,7 +1182,8 @@ async def send_rev_reg_entry(request: web.BaseRequest):
11271182
transaction_mgr = TransactionManager(profile)
11281183
try:
11291184
transaction = await transaction_mgr.create_record(
1130-
messages_attach=rev_entry_resp["result"], connection_id=connection_id
1185+
messages_attach=rev_entry_resp["result"],
1186+
connection_id=connection_id,
11311187
)
11321188
except StorageError as err:
11331189
raise web.HTTPBadRequest(reason=err.roll_up) from err
@@ -1268,7 +1324,9 @@ async def generate(rr_record: IssuerRevRegRecord) -> dict:
12681324
public_uri = tails_base_url.rstrip("/") + f"/{registry_record.revoc_reg_id}"
12691325
await rr_record.set_tails_file_public_uri(profile, public_uri)
12701326
rev_reg_resp = await rr_record.send_def(
1271-
profile, write_ledger=write_ledger, endorser_did=endorser_did
1327+
profile,
1328+
write_ledger=write_ledger,
1329+
endorser_did=endorser_did,
12721330
)
12731331
if write_ledger:
12741332
# Upload the tails file
@@ -1305,7 +1363,8 @@ async def generate(rr_record: IssuerRevRegRecord) -> dict:
13051363
responder = profile.inject_or(BaseResponder)
13061364
if responder:
13071365
await responder.send(
1308-
revo_transaction_request, connection_id=connection.connection_id
1366+
revo_transaction_request,
1367+
connection_id=connection.connection_id,
13091368
)
13101369
else:
13111370
LOGGER.warning(
@@ -1352,7 +1411,9 @@ async def on_revocation_entry_event(profile: Profile, event: Event):
13521411
async with profile.session() as session:
13531412
registry_record = await IssuerRevRegRecord.retrieve_by_id(session, record_id)
13541413
rev_entry_resp = await registry_record.send_entry(
1355-
profile, write_ledger=write_ledger, endorser_did=endorser_did
1414+
profile,
1415+
write_ledger=write_ledger,
1416+
endorser_did=endorser_did,
13561417
)
13571418

13581419
if not write_ledger:
@@ -1384,7 +1445,8 @@ async def on_revocation_entry_event(profile: Profile, event: Event):
13841445
responder = profile.inject_or(BaseResponder)
13851446
if responder:
13861447
await responder.send(
1387-
revo_transaction_request, connection_id=connection.connection_id
1448+
revo_transaction_request,
1449+
connection_id=connection.connection_id,
13881450
)
13891451
else:
13901452
LOGGER.warning(
@@ -1435,6 +1497,7 @@ async def on_revocation_registry_endorsed_event(profile: Profile, event: Event):
14351497
@querystring_schema(RevRegId())
14361498
@docs(tags=["revocation"], summary="Delete the tail files")
14371499
async def delete_tails(request: web.BaseRequest) -> json:
1500+
"""Delete Tails Files."""
14381501
context: AdminRequestContext = request["context"]
14391502
rev_reg_id = request.query.get("rev_reg_id")
14401503
cred_def_id = request.query.get("cred_def_id")
@@ -1463,7 +1526,8 @@ async def delete_tails(request: web.BaseRequest) -> json:
14631526
try:
14641527
flag = 0
14651528
for i in filenames:
1466-
if re.search(cred_def_id, i):
1529+
safe_cred_def_id = re.escape(cred_def_id)
1530+
if re.search(safe_cred_def_id, i):
14671531
shutil.rmtree(main_dir_cred + "/" + i)
14681532
flag = 1
14691533
if flag:
@@ -1482,13 +1546,16 @@ async def register(app: web.Application):
14821546
web.post("/revocation/revoke", revoke),
14831547
web.post("/revocation/publish-revocations", publish_revocations),
14841548
web.post(
1485-
"/revocation/clear-pending-revocations", clear_pending_revocations
1549+
"/revocation/clear-pending-revocations",
1550+
clear_pending_revocations,
14861551
),
14871552
web.get(
14881553
"/revocation/credential-record", get_cred_rev_record, allow_head=False
14891554
),
14901555
web.get(
1491-
"/revocation/registries/created", rev_regs_created, allow_head=False
1556+
"/revocation/registries/created",
1557+
rev_regs_created,
1558+
allow_head=False,
14921559
),
14931560
web.get("/revocation/registry/{rev_reg_id}", get_rev_reg, allow_head=False),
14941561
web.get(
@@ -1521,11 +1588,15 @@ async def register(app: web.Application):
15211588
get_tails_file,
15221589
allow_head=False,
15231590
),
1524-
web.patch("/revocation/registry/{rev_reg_id}/set-state", set_rev_reg_state),
1591+
web.patch(
1592+
"/revocation/registry/{rev_reg_id}/set-state",
1593+
set_rev_reg_state,
1594+
),
15251595
web.put(
15261596
"/revocation/registry/{rev_reg_id}/fix-revocation-entry-state",
15271597
update_rev_reg_revoked_state,
15281598
),
1599+
web.delete("/revocation/registry/delete-tails-file", delete_tails),
15291600
]
15301601
)
15311602

0 commit comments

Comments
 (0)