Skip to content

Commit

Permalink
feat: digital credential queue service tests (#2330)
Browse files Browse the repository at this point in the history
* feat: devcontainer configuraton for vscode

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: issue credentials through Traction tenant

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: app initialization workflow

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use out-of-band invitation for connecting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use v2.0 for issuing credential

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: web socket implmentation with flask-socketio

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: db migration script to enable revocation

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: revocation endpoint

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: replace endpoints

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update requirements

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: traction token exchanger

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: ws cors setting is a config option

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: clean up init in digital credential service

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* 18284: digital credentials (#2260)

* feat: devcontainer configuraton for vscode

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: issue credentials through Traction tenant

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: app initialization workflow

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use out-of-band invitation for connecting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use v2.0 for issuing credential

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: web socket implmentation with flask-socketio

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: db migration script to enable revocation

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: revocation endpoint

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: replace endpoints

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update requirements

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: traction token exchanger

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: ws cors setting is a config option

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: clean up init in digital credential service

Signed-off-by: Akiff Manji <amanji@petridish.dev>

---------

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: endpoints to reset credential offers

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: credential id lookup table

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add business roles

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* 18284 Add pre-fork server hook to gunicorn config (#2285)

* chore: fix tests and linting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* 18284 feat: digital credentials (#2281)

* feat: devcontainer configuraton for vscode

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: issue credentials through Traction tenant

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: app initialization workflow

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use out-of-band invitation for connecting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use v2.0 for issuing credential

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: web socket implmentation with flask-socketio

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: db migration script to enable revocation

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: revocation endpoint

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: replace endpoints

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update requirements

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: traction token exchanger

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: ws cors setting is a config option

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: clean up init in digital credential service

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: endpoints to reset credential offers

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: credential id lookup table

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add business roles

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix tests and linting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

---------

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: remove records from Traction on deletion

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* Revert "feat: web socket implmentation with flask-socketio"

This reverts commit 79a2631.

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: port so it doesnt overlap with airplay server on OSX

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* Revert "fix: port so it doesnt overlap with airplay server on OSX"

This reverts commit 9763a17.

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: digital credentials (#2287)

* feat: devcontainer configuraton for vscode

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: hard code digital business card schema

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: issue credentials through Traction tenant

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: app initialization workflow

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use out-of-band invitation for connecting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: use v2.0 for issuing credential

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: web socket implmentation with flask-socketio

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: db migration script to enable revocation

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: revocation endpoint

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: replace endpoints

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update requirements

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: traction token exchanger

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: update workflow variables

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: ws cors setting is a config option

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: clean up init in digital credential service

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: endpoints to reset credential offers

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: credential id lookup table

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add business roles

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix tests and linting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: remove records from Traction on deletion

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* Revert "feat: web socket implmentation with flask-socketio"

This reverts commit 79a2631.

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: port so it doesnt overlap with airplay server on OSX

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* Revert "fix: port so it doesnt overlap with airplay server on OSX"

This reverts commit 9763a17.

Signed-off-by: Akiff Manji <amanji@petridish.dev>

---------

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: base and scaffolding queue

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add placeholders for events to capture

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add processor scaffolding and revocation reasons

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: clean up code based on review comments

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: 404 errors when attempting to remove invitations and credentials

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: update digital credential helpers

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add init file for helpers module

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: move methods into digital credential service

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add query methods

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: more code re-organization

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: complete queue event processors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add manual revocation processor

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: improved token validation in traction auth decorator

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: address first set of code review comments

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: address second set of code reivew comments

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: address third set of code reivew comments

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: clean up config file for edc queue

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add DevOps config files

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: address code review comments

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: relax error logging level

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: add k8s files

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: rename admin revoke processor

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: digital credential queue worker tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: digital credential queue worker code cleanup

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* refactor: move fixtures to conftest

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* chore: fix linting errors

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* feat: add digital credential queue processor tests

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: update q_cli for admin filing types

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: q_cli formatting

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: add another check to test dissolution

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: code smells

Signed-off-by: Akiff Manji <amanji@petridish.dev>

* fix: code smells

Signed-off-by: Akiff Manji <amanji@petridish.dev>

---------

Signed-off-by: Akiff Manji <amanji@petridish.dev>
Co-authored-by: Argus Chiu <argus@highwaythreesolutions.com>
  • Loading branch information
amanji and argush3 authored Nov 27, 2023
1 parent dcacb42 commit e8d0216
Show file tree
Hide file tree
Showing 16 changed files with 933 additions and 27 deletions.
11 changes: 9 additions & 2 deletions queue_services/entity-digital-credentials/q_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,20 +87,26 @@ def subscription_options():

payload = {
'specversion': '1.x-wip',
'type': f'bc.registry.business.{filing_type}',
'source': f'/businesses/{identifier}',
'id': str(uuid.uuid4()),
'time': datetime.utcfromtimestamp(time.time()).replace(tzinfo=timezone.utc).isoformat(),
'datacontenttype': 'application/json',
'identifier': identifier,
'data': {
'filing': {
'header': {'filingId': filing_id},
'business': {'identifier': identifier}
}
}
}

if filing_type == 'admin.revoke':
payload['type'] = 'bc.registry.admin.revoke'
else:
payload['type'] = f'bc.registry.business.{filing_type}'

if filing_id is not None:
payload['data']['filing']['header'] = {'filingId': filing_id}

await sc.publish(subject=subscription_options().get('subject'),
payload=json.dumps(payload).encode('utf-8'))

Expand All @@ -114,6 +120,7 @@ def subscription_options():
except getopt.GetoptError:
print('q_cli.py -i <identifier> -f <filing_id> -t <filing_type>')
sys.exit(2)
filing_id = None
for opt, arg in opts:
if opt == '-h':
print('q_cli.py -i <identifier> -f <filing_id> -t <filing_type>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class _Config(): # pylint: disable=too-few-public-methods
DB_NAME = os.getenv('ENTITY_DATABASE_NAME', '')
DB_HOST = os.getenv('ENTITY_DATABASE_HOST', '')
DB_PORT = os.getenv('ENTITY_DATABASE_PORT', '5432')
# pylint: disable=consider-using-f-string
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
user=DB_USER,
password=DB_PASSWORD,
Expand Down Expand Up @@ -141,6 +142,7 @@ class TestConfig(_Config): # pylint: disable=too-few-public-methods
DB_HOST = os.getenv('DATABASE_TEST_HOST', '')
DB_PORT = os.getenv('DATABASE_TEST_PORT', '5432')
DEPLOYMENT_ENV = 'testing'
# pylint: disable=consider-using-f-string
SQLALCHEMY_DATABASE_URI = 'postgresql://{user}:{password}@{host}:{port}/{name}'.format(
user=DB_USER,
password=DB_PASSWORD,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright © 2023 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Entity Digital Credentials service.
This module contains processors for issuing and revoking digital credentials for entity related events.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Processing manual actions."""
"""Processing admin revocation actions."""

from entity_queue_common.service_utils import logger
from legal_api.models import Business, DCRevocationReason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async def process(business: Business, filing_sub_type: str):
logger.warning('No issued credentials found for business: %s', business.identifier)
return None

if filing_sub_type == 'voluntary':
if filing_sub_type == 'voluntary': # pylint: disable=no-else-return
reason = DCRevocationReason.VOLUNTARY_DISSOLUTION
return replace_issued_digital_credential(business=business,
issued_credential=issued_credentials[0],
Expand All @@ -43,4 +43,4 @@ async def process(business: Business, filing_sub_type: str):
issued_credential=issued_credentials[0],
reason=reason)
else:
raise Exception('Invalid filing sub type.')
raise Exception('Invalid filing sub type.') # pylint: disable=broad-exception-raised
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ def get_issued_digital_credentials(business: Business):
try:
# pylint: disable=superfluous-parens
if not (connection := DCConnection.find_active_by(business_id=business.id)):
raise Exception(f'{Business.identifier} active connection not found.')
# pylint: disable=broad-exception-raised
raise Exception(f'{business.identifier} active connection not found.')

# pylint: disable=superfluous-parens
if not (issued_credentials := DCIssuedCredential.find_by(dc_connection_id=connection.id)):
return []

return issued_credentials
# pylint: disable=broad-exception-raised
except Exception as err: # noqa: B902
raise err

Expand All @@ -48,11 +50,13 @@ def issue_digital_credential(business: Business, user: User, credential_type: DC
if not (definition := DCDefinition.find_by(DCDefinition.CredentialType[credential_type],
digital_credentials.business_schema_id,
digital_credentials.business_cred_def_id)):
# pylint: disable=broad-exception-raised
raise Exception(f'Definition not found for credential type: {credential_type}')

# pylint: disable=superfluous-parens
if not (connection := DCConnection.find_active_by(business_id=business.id)):
raise Exception(f'{Business.identifier} active connection not found.')
# pylint: disable=broad-exception-raised
raise Exception(f'{business.identifier} active connection not found.')

credential_data = DigitalCredentialsHelpers.get_digital_credential_data(business,
user,
Expand All @@ -62,7 +66,7 @@ def issue_digital_credential(business: Business, user: User, credential_type: DC
if not (response := digital_credentials.issue_credential(connection_id=connection.connection_id,
definition=definition,
data=credential_data)):
raise Exception('Failed to issue credential.')
raise Exception('Failed to issue credential.') # pylint: disable=broad-exception-raised

issued_credential = DCIssuedCredential(
dc_definition_id=definition.id,
Expand All @@ -73,6 +77,7 @@ def issue_digital_credential(business: Business, user: User, credential_type: DC
issued_credential.save()

return issued_credential
# pylint: disable=broad-exception-raised
except Exception as err: # noqa: B902
raise err

Expand All @@ -83,22 +88,25 @@ def revoke_issued_digital_credential(business: Business,
"""Revoke an issued digital credential for a business."""
try:
if not issued_credential.is_issued or issued_credential.is_revoked:
# pylint: disable=broad-exception-raised
raise Exception('Credential is not issued yet or is revoked already.')

# pylint: disable=superfluous-parens
if not (connection := DCConnection.find_active_by(business_id=business.id)):
raise Exception(f'{Business.identifier} active connection not found.')
# pylint: disable=broad-exception-raised
raise Exception(f'{business.identifier} active connection not found.')

if (revoked := digital_credentials.revoke_credential(connection.connection_id,
issued_credential.credential_revocation_id,
issued_credential.revocation_registry_id,
reason) is None):
raise Exception('Failed to revoke credential.')
raise Exception('Failed to revoke credential.') # pylint: disable=broad-exception-raised

issued_credential.is_revoked = True
issued_credential.save()

return revoked
# pylint: disable=broad-exception-raised
except Exception as err: # noqa: B902
raise err

Expand All @@ -116,17 +124,20 @@ def replace_issued_digital_credential(business: Business,
issued_credential.credential_exchange_id) is not None and
digital_credentials.remove_credential_exchange_record(
issued_credential.credential_exchange_id) is None):
raise Exception('Failed to remove credential exchange record.')
raise Exception('Failed to remove credential exchange record.') # pylint: disable=broad-exception-raised

if not (issued_business_user_credential := DCIssuedBusinessUserCredential.find_by_id(
dc_issued_business_user_id=issued_credential.credential_id)):
# pylint: disable=broad-exception-raised
raise Exception('Unable to find buisness user for issued credential.')

if not (user := User.find_by_id(issued_business_user_credential.user_id)): # pylint: disable=superfluous-parens
# pylint: disable=broad-exception-raised
raise Exception('Unable to find user for issued business user credential.')

issued_credential.delete()

return issue_digital_credential(business, user, credential_type)
# pylint: disable=broad-exception-raised
except Exception as err: # noqa: B902
raise err
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"""
import json
import os
from enum import Enum

import nats
from entity_queue_common.service import QueueServiceManager
Expand All @@ -40,10 +41,10 @@

from entity_digital_credentials import config
from entity_digital_credentials.digital_credentials_processors import (
admin_revoke,
business_number,
change_of_registration,
dissolution,
manual,
put_back_on,
)

Expand All @@ -62,15 +63,30 @@
flags.init_app(FLASK_APP)


class AdminMessage(Enum):
"""Entity Digital Credential admin message type."""

REVOKE = 'bc.registry.admin.revoke'


class BusinessMessage(Enum):
"""Entity Digital Credential business message type."""

BN = 'bc.registry.business.bn'
CHANGE_OF_REGISTRATION = f'bc.registry.business.{FilingCore.FilingTypes.CHANGEOFREGISTRATION.value}'
DISSOLUTION = f'bc.registry.business.{FilingCore.FilingTypes.DISSOLUTION.value}'
PUT_BACK_ON = f'bc.registry.business.{FilingCore.FilingTypes.PUTBACKON.value}'


async def process_digital_credential(dc_msg: dict, flask_app: Flask):
# pylint: disable=too-many-branches, too-many-statements
"""Process any digital credential messages in queue."""
if not dc_msg or dc_msg.get('type') not in [
f'bc.registry.business.{FilingCore.FilingTypes.CHANGEOFREGISTRATION.value}',
f'bc.registry.business.{FilingCore.FilingTypes.DISSOLUTION.value}',
f'bc.registry.business.{FilingCore.FilingTypes.PUTBACKON.value}',
'bc.registry.admin.bn',
'bc.registry.admin.manual'
BusinessMessage.CHANGE_OF_REGISTRATION.value,
BusinessMessage.DISSOLUTION.value,
BusinessMessage.PUT_BACK_ON.value,
BusinessMessage.BN.value,
AdminMessage.REVOKE.value
]:
return None

Expand All @@ -80,26 +96,27 @@ async def process_digital_credential(dc_msg: dict, flask_app: Flask):
with flask_app.app_context():
logger.debug('Attempting to process digital credential message: %s', dc_msg)

if dc_msg['type'] in ('bc.registry.business.bn', 'bc.registry.business.manual'):
if dc_msg['type'] in (BusinessMessage.BN.value, AdminMessage.REVOKE.value):
# When a BN is added or changed or there is a manuak administrative update the queue message does not have
# a data object. We queue the business information using the identifier and revoke/reissue the credential
# immediately.
if dc_msg['identifier'] is None:
if dc_msg.get('identifier') is None:
raise QueueException('Digital credential message is missing identifier')

identifier = dc_msg['identifier']
if not (business := Business.find_by_identifier(identifier)): # pylint: disable=superfluous-parens
# pylint: disable=broad-exception-raised
raise Exception(f'Business with identifier: {identifier} not found.')

if dc_msg['type'] == 'bc.registry.business.bn':
if dc_msg['type'] == BusinessMessage.BN.value:
await business_number.process(business)
elif dc_msg['type'] == 'bc.registry.business.manual':
await manual.process(business)
elif dc_msg['type'] == AdminMessage.REVOKE.value:
await admin_revoke.process(business)
else:
if dc_msg['data'] is None \
or dc_msg['data']['filing'] is None \
or dc_msg['data']['filing']['header'] is None \
or dc_msg['data']['filing']['header']['filingId'] is None:
if dc_msg.get('data') is None \
or dc_msg.get('data').get('filing') is None \
or dc_msg.get('data').get('filing').get('header') is None \
or dc_msg.get('data').get('filing').get('header').get('filingId') is None:
raise QueueException('Digital credential message is missing data.')

filing_id = dc_msg['data']['filing']['header']['filingId']
Expand All @@ -115,6 +132,7 @@ async def process_digital_credential(dc_msg: dict, flask_app: Flask):

business_id = filing.business_id
if not (business := Business.find_by_internal_id(business_id)): # pylint: disable=superfluous-parens
# pylint: disable=broad-exception-raised
raise Exception(f'Business with internal id: {business_id} not found.')

# Process individual filing events
Expand All @@ -140,6 +158,6 @@ async def cb_subscription_handler(msg: nats.aio.client.Msg):
logger.error('Queue Blocked - Database Issue: %s',
json.dumps(dc_msg), exc_info=True)
raise err # We don't want to handle the error, as a DB down would drain the queue
except (QueueException, Exception) as err: # noqa B902; pylint: disable=W0703;
except (QueueException, Exception) as err: # noqa B902; pylint: disable=W0703, disable=unused-variable
# Catch Exception so that any error is still caught and the message is removed from the queue
logger.error('Queue Error: %s', json.dumps(dc_msg), exc_info=True)
14 changes: 14 additions & 0 deletions queue_services/entity-digital-credentials/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright © 2023 Province of British Columbia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""The Test Suites to ensure that the service is built and operating correctly."""
Loading

0 comments on commit e8d0216

Please sign in to comment.