Common: Add CredentialTypeField

This commit is contained in:
Mike Salvatore 2022-07-06 11:07:46 -04:00
parent a8747c9d5d
commit 9a45d777ca
3 changed files with 17 additions and 13 deletions

View File

@ -1,7 +1,17 @@
from marshmallow import Schema, post_load
from marshmallow import Schema, post_load, validate
from marshmallow_enum import EnumField
from common.utils.code_utils import del_key
from . import CredentialComponentType
class CredentialTypeField(EnumField):
def __init__(self, credential_component_type: CredentialComponentType):
super().__init__(
CredentialComponentType, validate=validate.Equal(credential_component_type)
)
class CredentialComponentSchema(Schema):
@post_load

View File

@ -1,16 +1,13 @@
from dataclasses import dataclass, field
from marshmallow import fields, validate
from marshmallow_enum import EnumField
from marshmallow import fields
from . import CredentialComponentType, ICredentialComponent
from .credential_component_schema import CredentialComponentSchema
from .credential_component_schema import CredentialComponentSchema, CredentialTypeField
class PasswordSchema(CredentialComponentSchema):
credential_type = EnumField(
CredentialComponentType, validate=validate.Equal(CredentialComponentType.PASSWORD)
)
credential_type = CredentialTypeField(CredentialComponentType.PASSWORD)
password = fields.Str()

View File

@ -1,16 +1,13 @@
from dataclasses import dataclass, field
from marshmallow import fields, validate
from marshmallow_enum import EnumField
from marshmallow import fields
from . import CredentialComponentType, ICredentialComponent
from .credential_component_schema import CredentialComponentSchema
from .credential_component_schema import CredentialComponentSchema, CredentialTypeField
class UsernameSchema(CredentialComponentSchema):
credential_type = EnumField(
CredentialComponentType, validate=validate.Equal(CredentialComponentType.USERNAME)
)
credential_type = CredentialTypeField(CredentialComponentType.USERNAME)
username = fields.Str()