Skip to content

Commit

Permalink
🎨 apply pre-commit run --all-files
Browse files Browse the repository at this point in the history
Signed-off-by: ff137 <[email protected]>
  • Loading branch information
ff137 committed Aug 15, 2024
1 parent ca00cb1 commit 927d6d7
Show file tree
Hide file tree
Showing 331 changed files with 1,145 additions and 2,889 deletions.
6 changes: 2 additions & 4 deletions aries_cloudagent/admin/request_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(
context: Optional[InjectionContext] = None,
settings: Optional[Mapping[str, object]] = None,
root_profile: Optional[Profile] = None,
metadata: Optional[dict] = None
metadata: Optional[dict] = None,
):
"""Initialize an instance of AdminRequestContext."""
self._context = (context or profile.context).start_scope(settings)
Expand Down Expand Up @@ -154,8 +154,6 @@ def __repr__(self) -> str:
"""
skip = ("session",)
items = (
"{}={}".format(k, repr(v))
for k, v in self.__dict__.items()
if k not in skip
"{}={}".format(k, repr(v)) for k, v in self.__dict__.items() if k not in skip
)
return "<{}({})>".format(self.__class__.__name__, ", ".join(items))
8 changes: 2 additions & 6 deletions aries_cloudagent/admin/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,13 @@ class AdminResetSchema(OpenAPISchema):
class AdminStatusLivelinessSchema(OpenAPISchema):
"""Schema for the liveliness endpoint."""

alive = fields.Boolean(
metadata={"description": "Liveliness status", "example": True}
)
alive = fields.Boolean(metadata={"description": "Liveliness status", "example": True})


class AdminStatusReadinessSchema(OpenAPISchema):
"""Schema for the readiness endpoint."""

ready = fields.Boolean(
metadata={"description": "Readiness status", "example": True}
)
ready = fields.Boolean(metadata={"description": "Readiness status", "example": True})


class AdminShutdownSchema(OpenAPISchema):
Expand Down
8 changes: 2 additions & 6 deletions aries_cloudagent/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,7 @@ def __init__(
"""
self.app = None
self.admin_api_key = context.settings.get("admin.admin_api_key")
self.admin_insecure_mode = bool(
context.settings.get("admin.admin_insecure_mode")
)
self.admin_insecure_mode = bool(context.settings.get("admin.admin_insecure_mode"))
self.host = host
self.port = port
self.context = context
Expand Down Expand Up @@ -602,9 +600,7 @@ async def websocket_handler(self, request):
msg_received = receive.result()
msg_api_key = msg_received.get("x-api-key")
except Exception:
LOGGER.exception(
"Exception in websocket receiving task:"
)
LOGGER.exception("Exception in websocket receiving task:")
if self.admin_api_key and general_utils.const_compare(
self.admin_api_key, msg_api_key
):
Expand Down
11 changes: 3 additions & 8 deletions aries_cloudagent/admin/tests/test_admin_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,17 +171,13 @@ async def test_start_stop(self):
server = self.get_admin_server(settings)
await server.start()
assert server.app._client_max_size == 4 * 1024 * 1024
with mock.patch.object(
server, "websocket_queues", mock.MagicMock()
) as mock_wsq:
with mock.patch.object(server, "websocket_queues", mock.MagicMock()) as mock_wsq:
mock_wsq.values = mock.MagicMock(
return_value=[mock.MagicMock(stop=mock.MagicMock())]
)
await server.stop()

with mock.patch.object(
web.TCPSite, "start", mock.CoroutineMock()
) as mock_start:
with mock.patch.object(web.TCPSite, "start", mock.CoroutineMock()) as mock_start:
mock_start.side_effect = OSError("Failure to launch")
with self.assertRaises(AdminSetupError):
await self.get_admin_server(settings).start()
Expand Down Expand Up @@ -280,8 +276,7 @@ async def test_visit_secure_mode(self):
assert response.headers["Access-Control-Allow-Headers"] == "X-API-KEY"
assert response.headers["Access-Control-Allow-Methods"] == "GET"
assert (
response.headers["Access-Control-Allow-Origin"]
== "http://localhost:3000"
response.headers["Access-Control-Allow-Origin"] == "http://localhost:3000"
)

async with self.client_session.ws_connect(
Expand Down
2 changes: 0 additions & 2 deletions aries_cloudagent/admin/tests/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class TestAdminAuthentication(IsolatedAsyncioTestCase):
def setUp(self) -> None:

self.profile = InMemoryProfile.test_profile(
settings={
"admin.admin_api_key": "admin_api_key",
Expand Down Expand Up @@ -64,7 +63,6 @@ async def test_valid_api_key(self):

class TestTenantAuthentication(IsolatedAsyncioTestCase):
def setUp(self) -> None:

self.profile = InMemoryProfile.test_profile(
settings={
"admin.admin_api_key": "admin_api_key",
Expand Down
4 changes: 1 addition & 3 deletions aries_cloudagent/anoncreds/default/legacy_indy/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ async def get_endorser_info(profile, options: Optional[dict] = None):
connection_record = await ConnRecord.retrieve_by_id(
session, endorser_connection_id
)
endorser_info = await connection_record.metadata_get(
session, "endorser_info"
)
endorser_info = await connection_record.metadata_get(session, "endorser_info")
except StorageNotFoundError as err:
raise web.HTTPNotFound(
reason=f"Connection for endorser with id {endorser_connection_id} not found"
Expand Down
10 changes: 6 additions & 4 deletions aries_cloudagent/anoncreds/default/legacy_indy/recover.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ async def _check_tails_hash_for_inconsistency(tails_location: str, tails_hash: s
LOGGER.debug("Tails URL: %s", tails_location)
tails_data_http_response = await session.get(tails_location)
tails_data = await tails_data_http_response.read()
remote_tails_hash = base58.b58encode(
hashlib.sha256(tails_data).digest()
).decode("utf-8")
remote_tails_hash = base58.b58encode(hashlib.sha256(tails_data).digest()).decode(
"utf-8"
)
if remote_tails_hash != tails_hash:
raise RevocRecoveryException(
f"Tails hash mismatch {remote_tails_hash} {tails_hash}"
Expand All @@ -48,7 +48,9 @@ async def _check_tails_hash_for_inconsistency(tails_location: str, tails_hash: s
LOGGER.debug(f"Checked tails hash: {tails_hash}")


async def fetch_txns(genesis_txns: str, registry_id: str, issuer_id: str) -> tuple[
async def fetch_txns(
genesis_txns: str, registry_id: str, issuer_id: str
) -> tuple[
dict,
set[int],
]:
Expand Down
28 changes: 7 additions & 21 deletions aries_cloudagent/anoncreds/default/legacy_indy/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,7 @@ async def register_schema(
profile, options
)

write_ledger = (
True if endorser_did is None and not create_transaction else False
)
write_ledger = True if endorser_did is None and not create_transaction else False

# Get either the transaction or the seq_no or the created schema
async with ledger:
Expand Down Expand Up @@ -428,9 +426,7 @@ async def register_credential_definition(
profile, options
)

write_ledger = (
True if endorser_did is None and not create_transaction else False
)
write_ledger = True if endorser_did is None and not create_transaction else False

async with ledger:
try:
Expand Down Expand Up @@ -611,9 +607,7 @@ async def register_revocation_registry_definition(
profile, options
)

write_ledger = (
True if endorser_did is None and not create_transaction else False
)
write_ledger = True if endorser_did is None and not create_transaction else False

try:
async with ledger:
Expand Down Expand Up @@ -890,9 +884,7 @@ async def register_revocation_list(
profile, options
)

write_ledger = (
True if endorser_did is None and not create_transaction else False
)
write_ledger = True if endorser_did is None and not create_transaction else False

result = await self._revoc_reg_entry_with_fix(
profile,
Expand Down Expand Up @@ -996,9 +988,7 @@ async def update_revocation_list(
profile, options
)

write_ledger = (
True if endorser_did is None and not create_transaction else False
)
write_ledger = True if endorser_did is None and not create_transaction else False

result = await self._revoc_reg_entry_with_fix(
profile,
Expand Down Expand Up @@ -1116,9 +1106,7 @@ def _wallet_accumalator_matches_ledger_list(
)

async with ledger:
(rev_reg_delta, _) = await ledger.get_revoc_reg_delta(
rev_list.rev_reg_def_id
)
(rev_reg_delta, _) = await ledger.get_revoc_reg_delta(rev_list.rev_reg_def_id)

async with profile.session() as session:
LOGGER.debug(f"revocation_list = {rev_list.revocation_list}")
Expand Down Expand Up @@ -1163,9 +1151,7 @@ async def _revoked_issuer_cred_rev_record_ids() -> List[int]:
session, rev_reg_id=rev_list.rev_reg_def_id
)
return [
int(rec.cred_rev_id)
for rec in cred_rev_records
if rec.state == "revoked"
int(rec.cred_rev_id) for rec in cred_rev_records if rec.state == "revoked"
]

def _revocation_list_to_array_of_indexes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@

@pytest.mark.anoncreds
class TestLegacyIndyRecover(IsolatedAsyncioTestCase):

@mock.patch.object(
indy_vdr,
"open_pool",
Expand Down Expand Up @@ -108,7 +107,6 @@ async def test_fetch_txns(self, *_):
),
)
async def test_generate_ledger_rrrecovery_txn(self):

# Has updates
result = await generate_ledger_rrrecovery_txn(
GENESIS,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,7 @@ async def test_supported_did_regex(self):
assert self.registry.supported_identifiers_regex == SUPPORTED_ID_REGEX
assert bool(self.registry.supported_identifiers_regex.match(TEST_INDY_DID))
assert bool(self.registry.supported_identifiers_regex.match(TEST_INDY_DID_1))
assert bool(
self.registry.supported_identifiers_regex.match(TEST_INDY_SCHEMA_ID)
)
assert bool(self.registry.supported_identifiers_regex.match(TEST_INDY_SCHEMA_ID))
assert bool(
self.registry.supported_identifiers_regex.match(TEST_INDY_REV_REG_DEF_ID)
)
Expand Down Expand Up @@ -790,9 +788,7 @@ async def test_register_revocation_registry_definition_with_create_transaction_a
async def test_txn_submit(self):
self.profile.context.injector.bind_instance(
BaseLedger,
mock.MagicMock(
txn_submit=mock.CoroutineMock(return_value="transaction_id")
),
mock.MagicMock(txn_submit=mock.CoroutineMock(return_value="transaction_id")),
)
async with self.profile.session() as session:
ledger = session.inject(BaseLedger)
Expand Down Expand Up @@ -883,7 +879,6 @@ async def test_register_revocation_list_no_endorsement(
async def test_register_revocation_list_with_author_role(
self, mock_send_revoc_reg_entry, mock_create_record, _
):

self.profile.inject_or = mock.MagicMock()
self.profile.settings.set_value("endorser.author", True)

Expand Down Expand Up @@ -1104,7 +1099,6 @@ async def test_register_revocation_list_with_create_transaction_option_and_auto_
mock.CoroutineMock(return_value=MockTxn()),
)
async def test_fix_ledger_entry(self, *_):

self.profile.context.injector.bind_instance(
BaseLedger,
mock.MagicMock(send_revoc_reg_entry=mock.CoroutineMock(return_value={})),
Expand Down
21 changes: 5 additions & 16 deletions aries_cloudagent/anoncreds/holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ async def get_master_secret(self) -> str:
# isn't accepted by cred.process
secret = record.value.decode("ascii")
except AnoncredsError as err:
raise AnonCredsHolderError(
"Error loading master secret"
) from err
raise AnonCredsHolderError("Error loading master secret") from err
break
else:
try:
Expand Down Expand Up @@ -236,9 +234,7 @@ async def _finish_store_credential(
schema_id = cred_recvd.schema_id
schema_id_parts = re.match(r"^(\w+):2:([^:]+):([^:]+)$", schema_id)
if not schema_id_parts:
raise AnonCredsHolderError(
f"Error parsing credential schema ID: {schema_id}"
)
raise AnonCredsHolderError(f"Error parsing credential schema ID: {schema_id}")
cred_def_id = cred_recvd.cred_def_id
cdef_id_parts = re.match(r"^(\w+):3:CL:([^:]+):([^:]+)$", cred_def_id)
if not cdef_id_parts:
Expand Down Expand Up @@ -478,9 +474,7 @@ async def get_credentials_for_presentation_request_by_referent(
if row.name in creds:
creds[row.name]["presentation_referents"].add(reft)
else:
cred_info = _make_cred_info(
row.name, Credential.load(row.raw_value)
)
cred_info = _make_cred_info(row.name, Credential.load(row.raw_value))
creds[row.name] = {
"cred_info": cred_info,
"interval": presentation_request.get("non_revoked"),
Expand Down Expand Up @@ -590,9 +584,7 @@ async def get_mime_type(
credential_id,
)
except AskarError as err:
raise AnonCredsHolderError(
"Error retrieving credential mime types"
) from err
raise AnonCredsHolderError("Error retrieving credential mime types") from err
values = mime_types_record and mime_types_record.value_json
if values:
return values.get(attr) if attr else values
Expand Down Expand Up @@ -676,10 +668,7 @@ def get_rev_state(cred_id: str, detail: dict):
present_creds,
self_attest,
secret,
{
schema_id: schema.to_native()
for schema_id, schema in schemas.items()
},
{schema_id: schema.to_native() for schema_id, schema in schemas.items()},
{
cred_def_id: cred_def.to_native()
for cred_def_id, cred_def in credential_definitions.items()
Expand Down
17 changes: 4 additions & 13 deletions aries_cloudagent/anoncreds/issuer.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,7 @@ async def create_and_register_credential_definition(
raise ValueError("max_cred_num must be an integer")

# Don't allow revocable cred def to be created without tails server base url
if (
not self.profile.settings.get("tails_server_base_url")
and support_revocation
):
if not self.profile.settings.get("tails_server_base_url") and support_revocation:
raise AnonCredsIssuerError(
"tails_server_base_url not configured. Can't create revocable credential definition." # noqa: E501
)
Expand Down Expand Up @@ -568,9 +565,7 @@ async def create_credential_offer(self, credential_definition_id: str) -> str:
CATEGORY_CRED_DEF_KEY_PROOF, credential_definition_id
)
except AskarError as err:
raise AnonCredsIssuerError(
"Error retrieving credential definition"
) from err
raise AnonCredsIssuerError("Error retrieving credential definition") from err
if not cred_def or not key_proof:
raise AnonCredsIssuerError(
"Credential definition not found for credential offer"
Expand Down Expand Up @@ -611,9 +606,7 @@ async def create_credential(
CATEGORY_CRED_DEF_PRIVATE, cred_def_id
)
except AskarError as err:
raise AnonCredsIssuerError(
"Error retrieving credential definition"
) from err
raise AnonCredsIssuerError("Error retrieving credential definition") from err

if not cred_def or not cred_def_private:
raise AnonCredsIssuerError(
Expand Down Expand Up @@ -670,9 +663,7 @@ async def create_credential_w3c(
CATEGORY_CRED_DEF_PRIVATE, cred_def_id
)
except AskarError as err:
raise AnonCredsIssuerError(
"Error retrieving credential definition"
) from err
raise AnonCredsIssuerError("Error retrieving credential definition") from err

if not cred_def or not cred_def_private:
raise AnonCredsIssuerError(
Expand Down
4 changes: 1 addition & 3 deletions aries_cloudagent/anoncreds/models/anoncreds_revocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,7 @@ def __init__(
@property
def rev_reg_def_id(self):
"""Revocation Registry Definition ID."""
return (
self.revocation_registry_definition_state.revocation_registry_definition_id
)
return self.revocation_registry_definition_state.revocation_registry_definition_id

@property
def rev_reg_def(self):
Expand Down
Loading

0 comments on commit 927d6d7

Please sign in to comment.