1
0
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:
Ethan Paul 2020-02-24 21:29:10 -05:00
parent f7d93bd68c
commit 8c1e0fff0a
2 changed files with 40 additions and 6 deletions

View File

@ -1,11 +1,17 @@
from typing import List
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):
uuid = msh.fields.UUID(required=True)
created = msh.fields.DateTime(required=True)
updated = msh.fields.DateTime(required=True)
created = custom_fields.Epoch(required=True)
updated = custom_fields.Epoch(required=True)
name = msh.fields.String(required=True)
audience = msh.fields.String(required=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")
lifespan_access = msh.fields.Boolean(required=True, data_key="lifespan-access")
lifespan_refresh = msh.fields.Boolean(required=True, data_key="lifespan-refresh")
access_list_names = msh.fields.List(
msh.fields.String(), required=True, data_key="access-lists"
access_lists = msh.fields.List(
msh.fields.Nested(DomainAccessListSerializer),
required=True,
data_key="access-lists",
)
permission_names = msh.fields.List(
msh.fields.String(), required=True, data_key="permissions"
permissions = msh.fields.List(
msh.fields.Nested(DomainPermissionSerializer), required=True
)
@staticmethod
def creation_fields() -> List[str]:
return ["uuid", "created", "updated"]

View 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))