Skip to content

Commit

Permalink
Merge pull request #206 from bcgov/feature/v1-events-for-showcase
Browse files Browse the repository at this point in the history
Remove all unused event/notification code.
  • Loading branch information
usingtechnology authored Jun 24, 2022
2 parents 291a747 + d321bf8 commit 160a95b
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 106 deletions.
18 changes: 0 additions & 18 deletions services/showcase/api/services/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
OutOfBandRepository,
)
from api.db.repositories.job_applicant import ApplicantRepository
from api.services.websockets import notifier
from api.services import traction

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -216,30 +215,13 @@ async def handle_credential_revoked(lob: Lob, payload: dict, db: AsyncSession):

async def handle_webhook(lob: Lob, topic: str, payload: dict, db: AsyncSession):
logger.info(f"handle_webhook(lob = {lob.name}, topic = {topic})")
# TODO - make proper notifications to FE that are useful...
await notifier.push(
{
"topic": topic,
"payload": payload,
"lob": {
"sandbox_id": str(lob.sandbox_id),
"id": str(lob.id),
"name": lob.name,
},
}
)
# topic = "connections" is the acapy event, ignore that one
if "connection" == topic:
return await handle_connections(lob, payload, db)
elif "issuer" == topic:
return await handle_issuer(lob, payload, db)
elif "schema" == topic:
return await handle_schema(lob, payload, db)
# topic = "issue_credential" is the acapy event, ignore that one
elif "issue_cred" == topic:
return await handle_issue_credential(lob, payload, db)
elif "present_req" == topic:
return await handle_presentation_request(lob, payload, db)
elif "present_proof" == topic:
return await handle_present_proof(lob, payload, db)
elif "issuer_cred_rev" == topic:
Expand Down
4 changes: 0 additions & 4 deletions services/showcase/frontend/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ Vue.use(VueNativeSock, socketApi, {
}
let message = event;
let target = eventName.toUpperCase();
if (target === 'SOCKET_ONMESSAGE' && this.format === 'json' && event.data) {
message = JSON.parse(event.data);
target = 'notifications/onNotification';
}
this.store.commit(target, message);
},
});
Expand Down
5 changes: 0 additions & 5 deletions services/showcase/frontend/src/store/modules/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ export default {
state.notifications = state.notifications.filter(
notification => notification.id !== notificationToRemove.id
);
},
onNotification(state, notification) {
console.log('onNotification()'); // eslint-disable-line no-console
console.log(notification); // eslint-disable-line no-console
// TODO: this is where the notifications from the ws will end up in this code.
}
},
actions: {
Expand Down
2 changes: 0 additions & 2 deletions services/traction/api/endpoints/models/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ class TenantEventTopicType(str, Enum):
connection = "connection"
issuer = "issuer"
schema = "schema"
issue_cred = "issue_cred"
present_req = "present_req"
issuer_cred_rev = "issuer_cred_rev"


Expand Down
10 changes: 0 additions & 10 deletions services/traction/api/services/IssueCredentialWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ async def find_workflow_id(cls, profile: Profile, webhook_message: dict):
issue_cred = await issue_repo.create(issue_cred)
logger.debug(f">>> created new cred issue: {issue_cred}")

# if new, and offer_received, send webhook to tenant
logger.info(f">>> sending webhook with cred offer: {issue_cred}")
await TenantWorkflowNotifier(profile.db).issuer_workflow_cred_offer(
issue_cred
)
# return None - we want the tenant to accept the credential offer
return None

Expand Down Expand Up @@ -219,11 +214,6 @@ async def run_step(self, webhook_message: dict = None) -> TenantWorkflowRead:
issue_cred, webhook_message
)

logger.info(f">>> sending credential acked: {issue_cred}")
await self.workflow_notifier.issuer_workflow_credential_acked(
issue_cred
)

# finish off our workflow
await self.complete_workflow()

Expand Down
15 changes: 0 additions & 15 deletions services/traction/api/services/PresentCredentialWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from api.endpoints.models.tenant_workflow import (
TenantWorkflowStateType,
)
from api.services.tenant_workflow_notifier import TenantWorkflowNotifier
from api.endpoints.models.credentials import (
PresentCredentialProtocolType,
PresentationStateType,
Expand Down Expand Up @@ -109,11 +108,6 @@ async def find_workflow_id(cls, profile: Profile, webhook_message: dict):
)
present_cred = await present_repo.create(present_cred)
logger.warn(f">>> created new present request: {present_cred}")

# if new, and offer_received, send webhook to tenant
logger.info(f">>> sending webhook with proof req: {present_cred}")
notifier = TenantWorkflowNotifier(profile.db)
await notifier.verifier_workflow_proof_req(present_cred)
# return None - we want the tenant to respond to the request
return None

Expand Down Expand Up @@ -171,15 +165,6 @@ async def run_step(self, webhook_message: dict = None) -> TenantWorkflowRead:
present_cred, webhook_state
)

if webhook_state == PresentationStateType.verified:
# if verified, send webhook to tenant
logger.info(
f">>> sending webhook with verified proof: {present_cred}"
)
await self.workflow_notifier.verifier_workflow_proof_req(
present_cred
)

if (
webhook_state == PresentationStateType.presentation_acked
or webhook_state == PresentationStateType.verified
Expand Down
52 changes: 0 additions & 52 deletions services/traction/api/services/tenant_workflow_notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from api.db.models.tenant_connection import TenantConnectionRead
from api.db.models.tenant_issuer import TenantIssuerRead
from api.db.models.tenant_schema import TenantSchemaRead
from api.db.models.present_credential import PresentCredentialRead
from api.endpoints.models.webhooks import (
TenantEventTopicType,
TRACTION_EVENT_PREFIX,
Expand Down Expand Up @@ -46,40 +45,6 @@ async def issuer_workflow_connection_active(

await profile.notify(event_topic, {"topic": topic, "payload": payload})

async def issuer_workflow_credential_acked(self, issued_cred: IssueCredentialRead):
logger.info("issued credential acknowledged")
# emit an event for any interested listeners
profile = Profile(issued_cred.wallet_id, issued_cred.tenant_id, self.db)
topic = TenantEventTopicType.issue_cred
event_topic = TRACTION_EVENT_PREFIX + topic
logger.info(f"profile.notify {event_topic}")

# TODO: Webhook payload schema's should become pydantic models?
payload = {
"status": issued_cred.issue_state,
"role": issued_cred.issue_role,
"issued_credential": issued_cred.json(),
}

await profile.notify(event_topic, {"topic": topic, "payload": payload})

async def issuer_workflow_cred_offer(self, cred_offer: IssueCredentialRead):
logger.info("received cred offer")
# emit an event for any interested listeners
profile = Profile(cred_offer.wallet_id, cred_offer.tenant_id, self.db)
topic = TenantEventTopicType.issue_cred
event_topic = TRACTION_EVENT_PREFIX + topic
logger.info(f"profile.notify {event_topic}")

# TODO: Webhook payload schema's should become pydantic models?
payload = {
"status": "offer_received",
"credential": cred_offer.json(),
"cred_issue_id": str(cred_offer.id),
}

await profile.notify(event_topic, {"topic": topic, "payload": payload})

async def issuer_workflow_cred_revoc(
self, cred_info: IssueCredentialRead, comment: str
):
Expand Down Expand Up @@ -133,20 +98,3 @@ async def schema_workflow_completed(self, tenant_schema: TenantSchemaRead):
}

await profile.notify(event_topic, {"topic": topic, "payload": payload})

async def verifier_workflow_proof_req(self, present_req: PresentCredentialRead):
logger.info("received proof request")
# emit an event for any interested listeners
profile = Profile(present_req.wallet_id, present_req.tenant_id, self.db)
topic = TenantEventTopicType.present_req
event_topic = TRACTION_EVENT_PREFIX + topic
logger.info(f"profile.notify {event_topic}")

# TODO: Webhook payload schema's should become pydantic models?
payload = {
"status": present_req.present_state,
"present_req": present_req.json(),
"present_req_id": str(present_req.id),
}

await profile.notify(event_topic, {"topic": topic, "payload": payload})

0 comments on commit 160a95b

Please sign in to comment.