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 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
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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()
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue