forked from p15670423/monkey
Common: Add CredentialComponentSchema
Extract common _strip_credential_type() post_load function from PasswordSchema and UsernameSchema into a parent class.
This commit is contained in:
parent
037b4ef8c5
commit
a8747c9d5d
|
@ -0,0 +1,10 @@
|
|||
from marshmallow import Schema, post_load
|
||||
|
||||
from common.utils.code_utils import del_key
|
||||
|
||||
|
||||
class CredentialComponentSchema(Schema):
|
||||
@post_load
|
||||
def _strip_credential_type(self, data, **kwargs):
|
||||
del_key(data, "credential_type")
|
||||
return data
|
|
@ -1,24 +1,18 @@
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
from marshmallow import Schema, fields, post_load, validate
|
||||
from marshmallow import fields, validate
|
||||
from marshmallow_enum import EnumField
|
||||
|
||||
from common.utils.code_utils import del_key
|
||||
|
||||
from . import CredentialComponentType, ICredentialComponent
|
||||
from .credential_component_schema import CredentialComponentSchema
|
||||
|
||||
|
||||
class PasswordSchema(Schema):
|
||||
class PasswordSchema(CredentialComponentSchema):
|
||||
credential_type = EnumField(
|
||||
CredentialComponentType, validate=validate.Equal(CredentialComponentType.PASSWORD)
|
||||
)
|
||||
password = fields.Str()
|
||||
|
||||
@post_load
|
||||
def _strip_credential_type(self, data, **kwargs):
|
||||
del_key(data, "credential_type")
|
||||
return data
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Password(ICredentialComponent):
|
||||
|
|
|
@ -1,24 +1,18 @@
|
|||
from dataclasses import dataclass, field
|
||||
|
||||
from marshmallow import Schema, fields, post_load, validate
|
||||
from marshmallow import fields, validate
|
||||
from marshmallow_enum import EnumField
|
||||
|
||||
from common.utils.code_utils import del_key
|
||||
|
||||
from . import CredentialComponentType, ICredentialComponent
|
||||
from .credential_component_schema import CredentialComponentSchema
|
||||
|
||||
|
||||
class UsernameSchema(Schema):
|
||||
class UsernameSchema(CredentialComponentSchema):
|
||||
credential_type = EnumField(
|
||||
CredentialComponentType, validate=validate.Equal(CredentialComponentType.USERNAME)
|
||||
)
|
||||
username = fields.Str()
|
||||
|
||||
@post_load
|
||||
def _strip_credential_type(self, data, **kwargs):
|
||||
del_key(data, "credential_type")
|
||||
return data
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class Username(ICredentialComponent):
|
||||
|
|
Loading…
Reference in New Issue