Skip to content

Commit

Permalink
[CHORE] - Finalize Credential ID for UNTP DCC MAP (#3280)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jsyro authored Oct 25, 2024
1 parent 48ee3af commit bcb4653
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion services/core-api/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ CHIEF_PERMITTING_OFFICER_DID_WEB_VERIFICATION_METHOD="did:web:registry-dev.apps.
UNTP_DIGITAL_CONFORMITY_CREDENTIAL_CONTEXT=https://test.uncefact.org/vocabulary/untp/dcc/0.5.0/
UNTP_DIGITAL_CONFORMITY_CREDENTIAL_SCHEMA=https://test.uncefact.org/vocabulary/untp/dcc/untp-dcc-schema-0.5.0.json
UNTP_BC_MINES_ACT_PERMIT_CONTEXT=https://bcgov.github.io/digital-trust-toolkit/contexts/BCMinesActPermit/v1.jsonld

ORGBOOK_CREDENTIAL_BASE_URL=https://dev.orgbook.traceability.site/credentials
# Permit Search Service
PERMITS_ENDPOINT=http://haystack
PERMITS_CLIENT_ID=mds-core-api-internal-5194
Expand Down
17 changes: 11 additions & 6 deletions services/core-api/app/api/verifiable_credentials/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# for midware/business level actions between requests and data access
import json

from uuid import uuid4, UUID
from sqlalchemy.exc import IntegrityError
from typing import List, Union, Tuple, Optional
from pydantic import BaseModel, Field, ConfigDict
Expand Down Expand Up @@ -49,6 +50,7 @@ class W3CCred(BaseModel):
Config.UNTP_DIGITAL_CONFORMITY_CREDENTIAL_CONTEXT,
Config.UNTP_BC_MINES_ACT_PERMIT_CONTEXT,
])
id: str
type: List[str]
issuer: Union[str, dict[str, str]]
# TODO: update to `validFrom` for vcdm 2.0 once available in aca-py/traction, which is an optional property
Expand Down Expand Up @@ -169,7 +171,7 @@ def process_all_untp_map_for_orgbook():
task_logger.warning(f"Permit Amendment not found for permit_amendment_guid={row[0]}")
continue

pa_cred = VerifiableCredentialManager.produce_untp_cc_map_payload(public_did, pa)
pa_cred, new_id = VerifiableCredentialManager.produce_untp_cc_map_payload(public_did, pa)
if not pa_cred:
task_logger.warning(f"pa_cred could not be created")
continue
Expand All @@ -187,6 +189,7 @@ def process_all_untp_map_for_orgbook():
permit_amendment_guid=row[0],
party_guid=row[1],
unsigned_payload_hash=payload_hash,
orgbook_credential_id=new_id,
)
records.append((pa_cred, paob))

Expand Down Expand Up @@ -332,7 +335,8 @@ def produce_map_01_credential_payload(cls, did: str, permit_amendment: PermitAme
return credential

@classmethod
def produce_untp_cc_map_payload(cls, did: str, permit_amendment: PermitAmendment):
def produce_untp_cc_map_payload(cls, did: str,
permit_amendment: PermitAmendment) -> Tuple[W3CCred, UUID]:
"""Produce payload for Mines Act Permit UNTP Conformity Credential from permit amendment and did."""

#attributes in anoncreds but not in untp
Expand All @@ -358,7 +362,7 @@ def produce_untp_cc_map_payload(cls, did: str, permit_amendment: PermitAmendment
orgbook_entity = curr_appt.party.party_orgbook_entity
if not orgbook_entity:
current_app.logger.warning("No Orgbook Entity, do not produce Mines Act Permit UNTP CC")
return None
return None, None

untp_party_cpo = base.Identifier(
id="did:web:untp.traceability.site:parties:regulators:CHIEF-PERMITTING-OFFICER",
Expand Down Expand Up @@ -418,8 +422,7 @@ def produce_untp_cc_map_payload(cls, did: str, permit_amendment: PermitAmendment
tzinfo=ZoneInfo("UTC")).isoformat()

cred = UNTPCCMinesActPermit(
id=
f"https://orgbook.gov.bc.ca/entity/{orgbook_entity.registration_id}/credential/PLACEHOLDER",
id=None,
name="Credential for permitNumber=" + permit_amendment.permit_no,
permitNumber=permit_amendment.permit_no,
assessmentLevel=codes.AssessmentLevelCode.GovtApproval,
Expand All @@ -436,7 +439,9 @@ def produce_untp_cc_map_payload(cls, did: str, permit_amendment: PermitAmendment
issuedToParty=untp_party_business,
assessment=[untp_assessment])

new_credential_id = uuid4()
w3c_cred = W3CCred(
id=f"{Config.ORGBOOK_CREDENTIAL_BASE_URL}/{new_credential_id}",
type=[
"VerifiableCredential", "DigitalConformityCredential", "BCMinesActPermitCredential"
],
Expand All @@ -448,4 +453,4 @@ def produce_untp_cc_map_payload(cls, did: str, permit_amendment: PermitAmendment
"type": "JsonSchema"
}])

return w3c_cred
return w3c_cred, new_credential_id
3 changes: 3 additions & 0 deletions services/core-api/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ def JWT_ROLE_CALLBACK(jwt_dict):
UNTP_BC_MINES_ACT_PERMIT_CONTEXT = os.environ.get("UNTP_BC_MINES_ACT_PERMIT_CONTEXT",
"UNTP_BC_MINES_ACT_PERMIT_CONTEXT")

ORGBOOK_CREDENTIAL_BASE_URL = os.environ.get(
"ORGBOOK_CREDENTIAL_BASE_URL", "https://dev.orgbook.traceability.site/credentials/")


class TestConfig(Config):
# The following configs are for testing purposes and all variables and keys are generated using dummy data.
Expand Down
2 changes: 1 addition & 1 deletion services/core-api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ opentelemetry-instrumentation-urllib3==0.43b0
Pillow==10.3.0
setuptools==65.5.1
requests_toolbelt==1.0.0
untp_models==0.1.0
untp_models==0.1.1
urllib3==2.2.2
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_produce_untp_cc_map_payload_happy(self, db_session):
poe = PartyOrgBookEntityFactory(party_guid=permittee_appt.party_guid)
permittee_appt.party.party_orgbook_entity = poe

pa_cred = VerifiableCredentialManager.produce_untp_cc_map_payload(
pa_cred, new_id = VerifiableCredentialManager.produce_untp_cc_map_payload(
"did:test:10230123", permit.permit_amendments[0])

pa = permit.permit_amendments[0]
Expand All @@ -86,7 +86,7 @@ def test_produce_untp_cc_map_payload_null_if_no_orgbook(self, db_session):
mine, permit = create_mine_and_permit()
permittee_appt = MinePartyAppointmentFactory(permittee=True, permit_id=permit.permit_id)

pa_cred = VerifiableCredentialManager.produce_untp_cc_map_payload(
pa_cred, new_id = VerifiableCredentialManager.produce_untp_cc_map_payload(
"did:test:10230123", permit.permit_amendments[0])

assert not pa_cred

0 comments on commit bcb4653

Please sign in to comment.