Update code based on PR comments.

This commit is contained in:
Marek Wolan
2023-08-07 17:24:14 +01:00
parent 22afdc9134
commit 7eb0bb428f
3 changed files with 54 additions and 20 deletions

View File

@@ -11,25 +11,25 @@ _LOGGER = getLogger(__name__)
class AccountType(Enum):
"""Whether the account is intended for a user to log in or for a service to use."""
service = 1
SERVICE = 1
"Service accounts are used to grant permissions to software on nodes to perform actions"
user = 2
USER = 2
"User accounts are used to allow agents to log in and perform actions"
class AccountStatus(Enum):
"""Whether the account is active."""
enabled = 1
disabled = 2
ENABLED = 1
DISABLED = 2
class PasswordPolicyLevel(Enum):
"""Complexity requirements for account passwords."""
low = 1
medium = 2
high = 3
LOW = 1
MEDIUM = 2
HIGH = 3
class Account(SimComponent):
@@ -47,7 +47,7 @@ class Account(SimComponent):
"Account password."
account_type: AccountType
"Account Type, currently this can be service account (used by apps) or user account."
status: AccountStatus = AccountStatus.disabled
status: AccountStatus = AccountStatus.DISABLED
def describe_state(self) -> Dict:
"""Describe state for agent observations."""
@@ -55,11 +55,11 @@ class Account(SimComponent):
def enable(self):
"""Set the status to enabled."""
self.status = AccountStatus.enabled
self.status = AccountStatus.ENABLED
def disable(self):
"""Set the status to disabled."""
self.status = AccountStatus.disabled
self.status = AccountStatus.DISABLED
def log_on(self) -> None:
"""TODO."""

View File

@@ -47,7 +47,11 @@ class GroupMembershipValidator(ActionPermissionValidator):
"""Permit actions based on group membership."""
def __init__(self, allowed_groups: List[AccountGroup]) -> None:
"""TODO."""
"""Store a list of groups that should be granted permission.
:param allowed_groups: List of AccountGroups that are permitted to perform some action.
:type allowed_groups: List[AccountGroup]
"""
self.allowed_groups = allowed_groups
def __call__(self, request: List[str], context: Dict) -> bool:
@@ -64,7 +68,7 @@ class DomainController(SimComponent):
"""Main object for controlling the domain."""
# owned objects
accounts: List[Account] = []
accounts: Dict[str, Account] = {}
groups: Final[List[AccountGroup]] = list(AccountGroup)
domain_group_membership: Dict[Literal[AccountGroup.domain_admin, AccountGroup.domain_user], List[Account]] = {}
@@ -73,10 +77,10 @@ class DomainController(SimComponent):
] = {}
# references to non-owned objects. Not sure if all are needed here.
nodes: List[temp_node] = []
applications: List[temp_application] = []
folders: List[temp_folder] = []
files: List[temp_file] = []
nodes: Dict[str, temp_node] = {}
applications: Dict[str, temp_application] = {}
folders: List[temp_folder] = {}
files: List[temp_file] = {}
def _register_account(self, account: Account) -> None:
"""TODO."""