From 0a98f1634ae73eeffb125699fd9468e306ad650d Mon Sep 17 00:00:00 2001 From: yannick Date: Thu, 16 Mar 2023 13:56:03 +0100 Subject: [PATCH] Add GroupAccess enum --- bitwarden_access_manager.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bitwarden_access_manager.py b/bitwarden_access_manager.py index 1c34327..c2bca86 100644 --- a/bitwarden_access_manager.py +++ b/bitwarden_access_manager.py @@ -86,6 +86,9 @@ class MemberType(Enum): MANAGER = 3 CUSTOM = 4 +class GroupAccess(Enum): + READONLY = 0 + WRITE = 1 class Member(NamedTuple): id: str @@ -188,17 +191,17 @@ def format_toml(self) -> str: class GroupCollectionAccess(NamedTuple): name: str - access: str + access: GroupAccess @staticmethod def from_toml_dict(data: Dict[str, Any]) -> GroupCollectionAccess: return GroupCollectionAccess( name=data["group_name"], - access=data["access"], + access=GroupAccess[data["access"].upper()], ) def format_toml(self) -> str: - return "{ group_name = " + self.name + '", access = "' + self.access + '" }' + return "{ group_name = " + self.name + '", access = "' + str(self.access).lower() + '" }' class Collection(NamedTuple): @@ -332,9 +335,9 @@ def get_collection_members( def get_collection_groups(self, groups: Any) -> Iterable[GroupCollectionAccess]: for group in groups: if group["readOnly"] == True: - access = "readonly" + access = GroupAccess["READONLY"] else: - access = "write" + access = GroupAccess["WRITE"] group_id = group["id"] yield GroupCollectionAccess(