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 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): class CredentialComponentSchema(Schema):
@post_load @post_load

View File

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

View File

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