-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #792 from bcgov/feat/untp-vc
feat: W3C credential support
- Loading branch information
Showing
65 changed files
with
2,617 additions
and
456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: '3' | ||
services: | ||
vcr-api: | ||
command: ["sh", "-c", "pip install debugpy -t /tmp && python ./manage.py migrate && python /tmp/debugpy --wait-for-client --listen 0.0.0.0:5678 ./manage.py runserver 0.0.0.0:8080"] | ||
volumes: | ||
- ../server/vcr-server/vcr_server:/opt/app-root/src/vcr_server | ||
- ../server/vcr-server/subscriptions:/opt/app-root/src/subscriptions | ||
- ../server/vcr-server/agent_webhooks:/opt/app-root/src/agent_webhooks | ||
- ../server/vcr-server/api:/opt/app-root/src/api | ||
ports: | ||
- 5678:5678 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from .format import FormatEnum | ||
from .mapping_type import MappingTypeEnum | ||
|
||
__all__ = ["FormatEnum", "MappingTypeEnum"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from enum import Enum | ||
|
||
|
||
class FormatEnum(str, Enum): | ||
"""Format enum""" | ||
|
||
VC_DI = "vc_di" | ||
ANONCREDS = "anoncreds" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from enum import Enum | ||
|
||
|
||
class MappingTypeEnum(str, Enum): | ||
"""MappingType enum""" | ||
|
||
EFFECTIVE_DATE = "effective_date" | ||
EXPIRY_DATE = "expiry_date" | ||
REVOKED_DATE = "revoked_date" |
33 changes: 33 additions & 0 deletions
33
server/vcr-server/agent_webhooks/handlers/vc_di_credential.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
from marshmallow import ValidationError | ||
|
||
from api.v2.models.Credential import Credential | ||
from api.v4.serializers.rest.credential import CredentialSerializer | ||
|
||
from agent_webhooks.enums import FormatEnum | ||
from agent_webhooks.schemas import CredentialDefSchema | ||
from agent_webhooks.utils.vc_di_credential import CredentialManager | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
format = FormatEnum.VC_DI.value | ||
|
||
def handle_credential( | ||
message: CredentialDefSchema, | ||
) -> Credential: | ||
f"""Webhook message handler for a {format} credential.""" | ||
|
||
try: | ||
credential_schema = CredentialDefSchema() | ||
credential_schema.load(message) | ||
credential_manager = CredentialManager() | ||
|
||
credential = credential_manager.update_credential(message) | ||
return CredentialSerializer(credential).data | ||
except ValidationError as err: | ||
LOGGER.error(f"Invalid {format} credential type definition: {err.messages}") | ||
raise err | ||
except Exception as err: | ||
LOGGER.error(f"Error handling {format} credential type webhook: {err}") | ||
raise err |
33 changes: 33 additions & 0 deletions
33
server/vcr-server/agent_webhooks/handlers/vc_di_credential_type.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
|
||
from marshmallow import ValidationError | ||
|
||
from agent_webhooks.enums import FormatEnum | ||
from agent_webhooks.schemas import CredentialTypeRegistrationDefSchema | ||
|
||
from agent_webhooks.utils.issuer import IssuerManager, IssuerRegistrationResult | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
format = FormatEnum.VC_DI.value | ||
|
||
|
||
def handle_credential_type( | ||
message: CredentialTypeRegistrationDefSchema, | ||
) -> IssuerRegistrationResult: | ||
f"""Webhook message handler for a {format} credential type.""" | ||
|
||
try: | ||
credential_type_registration_schema = CredentialTypeRegistrationDefSchema() | ||
credential_type_registration_schema.load(message) | ||
issuer_manager = IssuerManager() | ||
|
||
# Convert the credential type definition to an issuer registration definition | ||
issuer_registration_def = credential_type_registration_schema.dump(message) | ||
return issuer_manager.register_issuer(issuer_registration_def) | ||
except ValidationError as err: | ||
LOGGER.error(f"Invalid {format} credential type definition: {err.messages}") | ||
raise err | ||
except Exception as err: | ||
LOGGER.error(f"Error handling {format} credential type webhook: {err}") | ||
raise err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import logging | ||
|
||
from marshmallow.exceptions import ValidationError | ||
|
||
from agent_webhooks.enums import FormatEnum | ||
from agent_webhooks.schemas import IssuerDefSchema, IssuerRegistrationDefSchema | ||
from agent_webhooks.utils.issuer import IssuerManager, IssuerRegistrationResult | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
format = FormatEnum.VC_DI.value | ||
|
||
|
||
def handle_issuer(message: IssuerDefSchema) -> IssuerRegistrationResult: | ||
f"""Webhook message handler for a {format} issuer.""" | ||
|
||
try: | ||
IssuerDefSchema().load(message) | ||
issuer_manager = IssuerManager() | ||
|
||
# Convert the issuer definition to an issuer registration definition | ||
issuer_registration_def = IssuerRegistrationDefSchema().dump({"issuer": message}) | ||
return issuer_manager.register_issuer(issuer_registration_def, issuer_only=True) | ||
except ValidationError as err: | ||
LOGGER.error(f"Invalid {format} issuer definition: {err.messages}") | ||
raise err | ||
except Exception as err: | ||
LOGGER.error(f"Error handling {format} issuer webhook: {err}") | ||
raise err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from .base import PathBaseSchema | ||
|
||
from .credential_def import CredentialDefSchema | ||
from .credential_mapping_def import CredentialMappingDefSchema | ||
from .issuer_def import IssuerDefSchema | ||
from .mapping_def import MappingDefSchema | ||
from .topic_def import TopicDefSchema | ||
|
||
# Import order matters here because of circular dependencies | ||
from .credential_type_def import CredentialTypeDefSchema | ||
from .issuer_registration_def import IssuerRegistrationDefSchema | ||
from .credential_type_registration_def import CredentialTypeRegistrationDefSchema | ||
|
||
__all__ = [ | ||
"PathBaseSchema", | ||
"CredentialDefSchema", | ||
"CredentialMappingDefSchema", | ||
"CredentialTypeDefSchema", | ||
"CredentialTypeRegistrationDefSchema", | ||
"IssuerDefSchema", | ||
"IssuerRegistrationDefSchema", | ||
"MappingDefSchema", | ||
"TopicDefSchema", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .path import PathBaseSchema | ||
|
||
__all__ = ["PathBaseSchema"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from marshmallow import Schema, fields | ||
|
||
|
||
class PathBaseSchema(Schema): | ||
|
||
path = fields.String(required=True) |
15 changes: 15 additions & 0 deletions
15
server/vcr-server/agent_webhooks/schemas/credential_def.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from marshmallow import Schema, fields | ||
|
||
from agent_webhooks.enums import FormatEnum | ||
|
||
|
||
class CredentialDefSchema(Schema): | ||
format = fields.Enum(FormatEnum, by_value=True, required=True) | ||
schema = fields.String(required=True) | ||
version = fields.String(required=True) | ||
origin_did = fields.String(required=True) | ||
credential_id = fields.String(required=True) | ||
# We don't make any assumptions about the fields in the raw_data dictionary | ||
# since there are different credential formats. Eventually we should define | ||
# schemas for different credential formats. | ||
raw_data = fields.Dict(required=True) |
7 changes: 7 additions & 0 deletions
7
server/vcr-server/agent_webhooks/schemas/credential_mapping_def.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from marshmallow import fields | ||
|
||
from agent_webhooks.schemas import PathBaseSchema | ||
|
||
|
||
class CredentialMappingDefSchema(PathBaseSchema): | ||
name = fields.String(required=True) |
22 changes: 22 additions & 0 deletions
22
server/vcr-server/agent_webhooks/schemas/credential_type_def.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from marshmallow import Schema, fields | ||
|
||
from agent_webhooks.enums import FormatEnum, MappingTypeEnum | ||
from agent_webhooks.schemas import ( | ||
CredentialMappingDefSchema, | ||
MappingDefSchema, | ||
TopicDefSchema, | ||
) | ||
|
||
|
||
class CredentialTypeDefSchema(Schema): | ||
format = fields.Enum(FormatEnum, by_value=True, required=True) | ||
schema = fields.String(required=True) | ||
version = fields.String(required=True) | ||
origin_did = fields.String(required=True) | ||
topic = fields.Nested(TopicDefSchema, required=True) | ||
mappings = fields.List(fields.Nested(MappingDefSchema)) | ||
credential = fields.Dict( | ||
keys=fields.Enum(MappingTypeEnum, by_value=True), | ||
values=fields.Nested(CredentialMappingDefSchema), | ||
) | ||
raw_data = fields.Dict() |
15 changes: 15 additions & 0 deletions
15
server/vcr-server/agent_webhooks/schemas/credential_type_registration_def.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from marshmallow import fields | ||
|
||
from agent_webhooks.schemas import CredentialTypeDefSchema, IssuerRegistrationDefSchema | ||
|
||
|
||
class CredentialTypeRegistrationDefSchema(IssuerRegistrationDefSchema): | ||
credential_type = fields.Nested( | ||
CredentialTypeDefSchema, required=True, load_only=True | ||
) | ||
|
||
def get_issuer_registration(self, obj): | ||
return { | ||
"issuer": obj.get("issuer"), | ||
"credential_types": [obj.get("credential_type")], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from marshmallow import Schema, fields | ||
|
||
|
||
class IssuerDefSchema(Schema): | ||
name = fields.String(required=True) | ||
did = fields.String(required=True) | ||
abbreviation = fields.String(required=True) | ||
email = fields.String(required=True) | ||
url = fields.String(required=True) | ||
endpoint = fields.String() | ||
logo_b64 = fields.String() |
11 changes: 11 additions & 0 deletions
11
server/vcr-server/agent_webhooks/schemas/issuer_registration_def.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from marshmallow import Schema, fields | ||
|
||
from agent_webhooks.schemas import IssuerDefSchema | ||
|
||
|
||
class IssuerRegistrationDefSchema(Schema): | ||
issuer = fields.Nested(IssuerDefSchema, required=True, load_only=True) | ||
issuer_registration = fields.Method("get_issuer_registration") | ||
|
||
def get_issuer_registration(self, obj): | ||
return {"issuer": obj.get("issuer")} |
Oops, something went wrong.