chore: use more understandable names for functions

This commit is contained in:
Victor Golovanenko
2025-08-04 18:08:27 +03:00
parent 117622257b
commit 77ff60920a

View File

@@ -38,14 +38,14 @@ def set_shell_access_creds(config: ET.Element, protocol: Literal['SSH', 'Telnet'
return True return True
def is_access_enabled(config: ET.Element, def is_shell_access_enabled(config: ET.Element, interface: Literal['LAN', 'WAN'] = 'LAN',
interface: Literal['LAN', 'WAN'] = 'LAN', protocol: Literal['SSH', 'Telnet'] = 'SSH') -> bool: protocol: Literal['SSH', 'Telnet'] = 'SSH') -> bool:
ssh_policy = config.find(f".//ServiceControl/*[ServiceList='{protocol.upper()}'][Interface='{interface}']/Policy") ssh_policy = config.find(f".//ServiceControl/*[ServiceList='{protocol.upper()}'][Interface='{interface}']/Policy")
return ssh_policy.text == "Permit" return ssh_policy.text == "Permit"
def enable_access(config: ET.Element, interface: Literal['LAN', 'WAN'] = 'LAN', def enable_shell_access(config: ET.Element, interface: Literal['LAN', 'WAN'] = 'LAN',
protocol: Literal['SSH', 'Telnet'] = 'SSH', disable: bool = False) -> bool: protocol: Literal['SSH', 'Telnet'] = 'SSH', disable: bool = False) -> bool:
service_policy = config.find( service_policy = config.find(
f".//ServiceControl/*[ServiceList='{protocol.upper()}'][Interface='{interface}']/Policy") f".//ServiceControl/*[ServiceList='{protocol.upper()}'][Interface='{interface}']/Policy")
remote_management = config.find(f'.//RemoteManagement/{protocol.upper()}/{protocol}Enable') remote_management = config.find(f'.//RemoteManagement/{protocol.upper()}/{protocol}Enable')
@@ -132,9 +132,9 @@ if __name__ == '__main__':
else: else:
print(f'Failed to change {protocol} credentials', file=sys.stderr) print(f'Failed to change {protocol} credentials', file=sys.stderr)
enabled = is_access_enabled(config, interface, protocol) enabled = is_shell_access_enabled(config, interface, protocol)
if disable == enabled: if disable == enabled:
if enable_access(config, interface, protocol, disable=disable): if enable_shell_access(config, interface, protocol, disable=disable):
print(f'{protocol} access from {interface}', 'disabled' if disable else 'enabled') print(f'{protocol} access from {interface}', 'disabled' if disable else 'enabled')
config_changed = True config_changed = True
else: else: