forked from p15670423/monkey
Common: Add CredentialTypeField
This commit is contained in:
parent
a8747c9d5d
commit
9a45d777ca
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue