aboutsummaryrefslogtreecommitdiff
path: root/gn_auth/auth/authorisation/resources/base.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-09-13 08:01:50 +0300
committerFrederick Muriuki Muriithi2023-09-26 03:44:28 +0300
commit9a3b628e2744b658ade8902c1cd33deccbd48b63 (patch)
tree47299176e0c2052f24060a9596417b10a16e2c7c /gn_auth/auth/authorisation/resources/base.py
parenta49f925eaaff5b29ffc387a7f02023e111208d5f (diff)
downloadgn-auth-9a3b628e2744b658ade8902c1cd33deccbd48b63.tar.gz
Extract basic resource types to a separate module.
Diffstat (limited to 'gn_auth/auth/authorisation/resources/base.py')
-rw-r--r--gn_auth/auth/authorisation/resources/base.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/gn_auth/auth/authorisation/resources/base.py b/gn_auth/auth/authorisation/resources/base.py
new file mode 100644
index 0000000..d2075c2
--- /dev/null
+++ b/gn_auth/auth/authorisation/resources/base.py
@@ -0,0 +1,37 @@
+"""Base types for resources."""
+from uuid import UUID
+from typing import Any, Sequence, NamedTuple
+
+from gn_auth.auth.dictify import dictify
+
+class ResourceCategory(NamedTuple):
+ """Class representing a resource category."""
+ resource_category_id: UUID
+ resource_category_key: str
+ resource_category_description: str
+
+ def dictify(self) -> dict[str, Any]:
+ """Return a dict representation of `ResourceCategory` objects."""
+ return {
+ "resource_category_id": self.resource_category_id,
+ "resource_category_key": self.resource_category_key,
+ "resource_category_description": self.resource_category_description
+ }
+
+class Resource(NamedTuple):
+ """Class representing a resource."""
+ resource_id: UUID
+ resource_name: str
+ resource_category: ResourceCategory
+ public: bool
+ resource_data: Sequence[dict[str, Any]] = tuple()
+
+ def dictify(self) -> dict[str, Any]:
+ """Return a dict representation of `Resource` objects."""
+ return {
+ "resource_id": self.resource_id,
+ "resource_name": self.resource_name,
+ "resource_category": dictify(self.resource_category),
+ "public": self.public,
+ "resource_data": self.resource_data
+ }