mirror of
https://github.com/enpaul/keyosk.git
synced 2024-11-24 23:47:49 +00:00
Add serializers for domain extras
Update domain serializer to properly access extras
This commit is contained in:
parent
f7d93bd68c
commit
8c1e0fff0a
@ -1,11 +1,17 @@
|
|||||||
|
from typing import List
|
||||||
|
|
||||||
import marshmallow as msh
|
import marshmallow as msh
|
||||||
|
|
||||||
|
from keyosk import fields as custom_fields
|
||||||
|
from keyosk.serializers.domain_extras import DomainAccessListSerializer
|
||||||
|
from keyosk.serializers.domain_extras import DomainPermissionSerializer
|
||||||
|
|
||||||
|
|
||||||
class DomainSerializer(msh.Schema):
|
class DomainSerializer(msh.Schema):
|
||||||
|
|
||||||
uuid = msh.fields.UUID(required=True)
|
uuid = msh.fields.UUID(required=True)
|
||||||
created = msh.fields.DateTime(required=True)
|
created = custom_fields.Epoch(required=True)
|
||||||
updated = msh.fields.DateTime(required=True)
|
updated = custom_fields.Epoch(required=True)
|
||||||
name = msh.fields.String(required=True)
|
name = msh.fields.String(required=True)
|
||||||
audience = msh.fields.String(required=True)
|
audience = msh.fields.String(required=True)
|
||||||
title = msh.fields.String(required=True, allow_none=True)
|
title = msh.fields.String(required=True, allow_none=True)
|
||||||
@ -21,9 +27,15 @@ class DomainSerializer(msh.Schema):
|
|||||||
enable_refresh = msh.fields.Boolean(required=True, data_key="enable-refresh")
|
enable_refresh = msh.fields.Boolean(required=True, data_key="enable-refresh")
|
||||||
lifespan_access = msh.fields.Boolean(required=True, data_key="lifespan-access")
|
lifespan_access = msh.fields.Boolean(required=True, data_key="lifespan-access")
|
||||||
lifespan_refresh = msh.fields.Boolean(required=True, data_key="lifespan-refresh")
|
lifespan_refresh = msh.fields.Boolean(required=True, data_key="lifespan-refresh")
|
||||||
access_list_names = msh.fields.List(
|
access_lists = msh.fields.List(
|
||||||
msh.fields.String(), required=True, data_key="access-lists"
|
msh.fields.Nested(DomainAccessListSerializer),
|
||||||
|
required=True,
|
||||||
|
data_key="access-lists",
|
||||||
)
|
)
|
||||||
permission_names = msh.fields.List(
|
permissions = msh.fields.List(
|
||||||
msh.fields.String(), required=True, data_key="permissions"
|
msh.fields.Nested(DomainPermissionSerializer), required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def creation_fields() -> List[str]:
|
||||||
|
return ["uuid", "created", "updated"]
|
||||||
|
22
keyosk/serializers/domain_extras.py
Normal file
22
keyosk/serializers/domain_extras.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
from typing import Dict
|
||||||
|
|
||||||
|
import marshmallow as msh
|
||||||
|
|
||||||
|
|
||||||
|
class DomainAccessListSerializer(msh.Schema):
|
||||||
|
|
||||||
|
name = msh.fields.String(required=True)
|
||||||
|
|
||||||
|
@msh.pre_load
|
||||||
|
def _from_string(self, data: str, *args, **kwargs) -> Dict[str, str]:
|
||||||
|
return {"name": data}
|
||||||
|
|
||||||
|
@msh.post_dump
|
||||||
|
def _to_string(self, data, *args, **kwargs) -> str:
|
||||||
|
return data["name"]
|
||||||
|
|
||||||
|
|
||||||
|
class DomainPermissionSerializer(msh.Schema):
|
||||||
|
|
||||||
|
name = msh.fields.String(required=True)
|
||||||
|
bitindex = msh.fields.Integer(required=True, validate=msh.validate.Range(min=0))
|
Loading…
Reference in New Issue
Block a user