Skip to content

Commit

Permalink
Small refactor
Browse files Browse the repository at this point in the history
Signed-off-by: jamshale <[email protected]>
  • Loading branch information
jamshale committed Mar 15, 2024
1 parent 3ec52e3 commit 974ec1d
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 28 deletions.
22 changes: 12 additions & 10 deletions aries_cloudagent/messaging/credential_definitions/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
)

# check if we need to endorse
if is_author_role(context.profile):
if is_author_role(profile):
# authors cannot write to the ledger
write_ledger = False
create_transaction_for_endorser = True
if not connection_id:
# author has not provided a connection id, so determine which to use
connection_id = await get_endorser_connection_id(context.profile)
connection_id = await get_endorser_connection_id(profile)
if not connection_id:
raise web.HTTPBadRequest(reason="No endorser connection found")

Expand Down Expand Up @@ -317,7 +317,7 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
if not create_transaction_for_endorser:
# Notify event
meta_data["processing"]["auto_create_rev_reg"] = True
await notify_cred_def_event(context.profile, cred_def_id, meta_data)
await notify_cred_def_event(profile, cred_def_id, meta_data)

return web.json_response(
{
Expand All @@ -335,7 +335,7 @@ async def credential_definitions_send_credential_definition(request: web.BaseReq
"endorser.auto_create_rev_reg"
)

transaction_mgr = TransactionManager(context.profile)
transaction_mgr = TransactionManager(profile)
try:
transaction = await transaction_mgr.create_record(
messages_attach=cred_def["signed_txn"],
Expand Down Expand Up @@ -417,15 +417,16 @@ async def credential_definitions_get_credential_definition(request: web.BaseRequ
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

cred_def_id = request.match_info["cred_def_id"]

async with context.profile.session() as session:
async with profile.session() as session:
multitenant_mgr = session.inject_or(BaseMultitenantManager)
if multitenant_mgr:
ledger_exec_inst = IndyLedgerRequestsExecutor(context.profile)
ledger_exec_inst = IndyLedgerRequestsExecutor(profile)
else:
ledger_exec_inst = session.inject(IndyLedgerRequestsExecutor)
ledger_id, ledger = await ledger_exec_inst.get_ledger_for_identifier(
Expand Down Expand Up @@ -466,16 +467,17 @@ async def credential_definitions_fix_cred_def_wallet_record(request: web.BaseReq
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

cred_def_id = request.match_info["cred_def_id"]

async with context.profile.session() as session:
async with profile.session() as session:
storage = session.inject(BaseStorage)
multitenant_mgr = session.inject_or(BaseMultitenantManager)
if multitenant_mgr:
ledger_exec_inst = IndyLedgerRequestsExecutor(context.profile)
ledger_exec_inst = IndyLedgerRequestsExecutor(profile)
else:
ledger_exec_inst = session.inject(IndyLedgerRequestsExecutor)
ledger_id, ledger = await ledger_exec_inst.get_ledger_for_identifier(
Expand Down
11 changes: 6 additions & 5 deletions aries_cloudagent/messaging/schemas/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,16 @@ async def schemas_get_schema(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

schema_id = request.match_info["schema_id"]

async with context.profile.session() as session:
async with profile.session() as session:
multitenant_mgr = session.inject_or(BaseMultitenantManager)
if multitenant_mgr:
ledger_exec_inst = IndyLedgerRequestsExecutor(context.profile)
ledger_exec_inst = IndyLedgerRequestsExecutor(profile)
else:
ledger_exec_inst = session.inject(IndyLedgerRequestsExecutor)
ledger_id, ledger = await ledger_exec_inst.get_ledger_for_identifier(
Expand Down Expand Up @@ -429,8 +430,8 @@ async def schemas_fix_schema_wallet_record(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]

profile = context.profile

is_anoncreds_profile_raise_web_exception(profile)

schema_id = request.match_info["schema_id"]
Expand All @@ -439,7 +440,7 @@ async def schemas_fix_schema_wallet_record(request: web.BaseRequest):
storage = session.inject(BaseStorage)
multitenant_mgr = session.inject_or(BaseMultitenantManager)
if multitenant_mgr:
ledger_exec_inst = IndyLedgerRequestsExecutor(context.profile)
ledger_exec_inst = IndyLedgerRequestsExecutor(profile)
else:
ledger_exec_inst = session.inject(IndyLedgerRequestsExecutor)
ledger_id, ledger = await ledger_exec_inst.get_ledger_for_identifier(
Expand Down
34 changes: 22 additions & 12 deletions aries_cloudagent/revocation/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,13 +698,14 @@ async def clear_pending_revocations(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

body = await request.json()
purge = body.get("purge")

rev_manager = RevocationManager(context.profile)
rev_manager = RevocationManager(profile)

try:
results = await rev_manager.clear_pending_revocations(purge)
Expand Down Expand Up @@ -853,6 +854,7 @@ async def get_rev_reg(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]
Expand Down Expand Up @@ -883,10 +885,13 @@ async def get_rev_reg_issued_count(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]

async with context.profile.session() as session:
async with profile.session() as session:
try:
await IssuerRevRegRecord.retrieve_by_revoc_reg_id(session, rev_reg_id)
except StorageNotFoundError as err:
Expand Down Expand Up @@ -915,13 +920,14 @@ async def get_rev_reg_issued(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]

recs = []
async with context.profile.session() as session:
async with profile.session() as session:
try:
await IssuerRevRegRecord.retrieve_by_revoc_reg_id(session, rev_reg_id)
except StorageNotFoundError as err:
Expand Down Expand Up @@ -951,12 +957,13 @@ async def get_rev_reg_indy_recs(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]

revoc = IndyRevocation(context.profile)
revoc = IndyRevocation(profile)
rev_reg_delta = await revoc.get_issuer_rev_reg_delta(rev_reg_id)

return web.json_response(
Expand Down Expand Up @@ -984,8 +991,9 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]

Expand All @@ -995,7 +1003,7 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):

rev_reg_record = None
genesis_transactions = None
async with context.profile.session() as session:
async with profile.session() as session:
try:
rev_reg_record = await IssuerRevRegRecord.retrieve_by_revoc_reg_id(
session, rev_reg_id
Expand Down Expand Up @@ -1028,7 +1036,7 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
reason += ": missing wallet-type?"
raise web.HTTPInternalServerError(reason=reason)

rev_manager = RevocationManager(context.profile)
rev_manager = RevocationManager(profile)
try:
(
rev_reg_delta,
Expand Down Expand Up @@ -1074,15 +1082,16 @@ async def get_cred_rev_record(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(context.profile)
is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.query.get("rev_reg_id")
cred_rev_id = request.query.get("cred_rev_id") # numeric string
cred_ex_id = request.query.get("cred_ex_id")

try:
async with context.profile.session() as session:
async with profile.session() as session:
if rev_reg_id and cred_rev_id:
rec = await IssuerCredRevRecord.retrieve_by_ids(
session, rev_reg_id, cred_rev_id
Expand Down Expand Up @@ -1148,6 +1157,7 @@ async def get_tails_file(request: web.BaseRequest) -> web.FileResponse:
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_anoncreds_profile_raise_web_exception(profile)

rev_reg_id = request.match_info["rev_reg_id"]
Expand Down
3 changes: 2 additions & 1 deletion aries_cloudagent/revocation_anoncreds/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ async def revoke(request: web.BaseRequest):
"""
context: AdminRequestContext = request["context"]
profile = context.profile

is_not_anoncreds_profile_raise_web_exception(profile)

body = await request.json()
Expand Down Expand Up @@ -951,7 +952,7 @@ async def update_rev_reg_revoked_state(request: web.BaseRequest):
reason += ": missing wallet-type?"
raise web.HTTPInternalServerError(reason=reason)

rev_manager = RevocationManager(context.profile)
rev_manager = RevocationManager(profile)
try:
(
rev_reg_delta,
Expand Down

0 comments on commit 974ec1d

Please sign in to comment.