From 0b96b5b48d1d5fdd18629a26b7ecd0b659fadad7 Mon Sep 17 00:00:00 2001 From: Alexander Popov Date: Sun, 21 Apr 2024 03:12:20 +0300 Subject: [PATCH] Don't use the `type` name for the class methods There should be no functional changes --- kernel_hardening_checker/__init__.py | 6 ++--- kernel_hardening_checker/engine.py | 38 ++++++++++++++-------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/kernel_hardening_checker/__init__.py b/kernel_hardening_checker/__init__.py index 858341a..89c24f7 100644 --- a/kernel_hardening_checker/__init__.py +++ b/kernel_hardening_checker/__init__.py @@ -85,16 +85,16 @@ def print_unknown_options(checklist, parsed_options, opt_type): known_options = [] for o1 in checklist: - if o1.type != 'complex': + if o1.opt_type != 'complex': known_options.append(o1.name) continue for o2 in o1.opts: - if o2.type != 'complex': + if o2.opt_type != 'complex': if hasattr(o2, 'name'): known_options.append(o2.name) continue for o3 in o2.opts: - assert(o3.type != 'complex'), \ + assert(o3.opt_type != 'complex'), \ f'unexpected ComplexOptCheck inside {o2.name}' if hasattr(o3, 'name'): known_options.append(o3.name) diff --git a/kernel_hardening_checker/engine.py b/kernel_hardening_checker/engine.py index 5190708..00344fe 100644 --- a/kernel_hardening_checker/engine.py +++ b/kernel_hardening_checker/engine.py @@ -58,7 +58,7 @@ class OptCheck: self.result = None @property - def type(self): + def opt_type(self): return None def set_state(self, data): @@ -99,14 +99,14 @@ class OptCheck: self.result = f'FAIL: "{self.state}"' def table_print(self, _mode, with_results): - print(f'{self.name:<40}|{self.type:^7}|{self.expected:^12}|{self.decision:^10}|{self.reason:^18}', end='') + print(f'{self.name:<40}|{self.opt_type:^7}|{self.expected:^12}|{self.decision:^10}|{self.reason:^18}', end='') if with_results: print(f'| {colorize_result(self.result)}', end='') def json_dump(self, with_results): dump = { "option_name": self.name, - "type": self.type, + "type": self.opt_type, "desired_val": self.expected, "decision": self.decision, "reason": self.reason, @@ -123,19 +123,19 @@ class KconfigCheck(OptCheck): self.name = f'CONFIG_{self.name}' @property - def type(self): + def opt_type(self): return 'kconfig' class CmdlineCheck(OptCheck): @property - def type(self): + def opt_type(self): return 'cmdline' class SysctlCheck(OptCheck): @property - def type(self): + def opt_type(self): return 'sysctl' @@ -150,7 +150,7 @@ class VersionCheck: self.result = None @property - def type(self): + def opt_type(self): return 'version' def set_state(self, data): @@ -197,7 +197,7 @@ class ComplexOptCheck: self.result = None @property - def type(self): + def opt_type(self): return 'complex' @property @@ -296,33 +296,33 @@ SIMPLE_OPTION_TYPES = ('kconfig', 'cmdline', 'sysctl', 'version') def populate_simple_opt_with_data(opt, data, data_type): - assert(opt.type != 'complex'), \ + assert(opt.opt_type != 'complex'), \ f'unexpected ComplexOptCheck "{opt.name}"' - assert(opt.type in SIMPLE_OPTION_TYPES), \ - f'invalid opt type "{opt.type}"' + assert(opt.opt_type in SIMPLE_OPTION_TYPES), \ + f'invalid opt_type "{opt.opt_type}"' assert(data_type in SIMPLE_OPTION_TYPES), \ - f'invalid data type "{data_type}"' + f'invalid data_type "{data_type}"' assert(data), \ 'empty data' - if data_type != opt.type: + if data_type != opt.opt_type: return if data_type in ('kconfig', 'cmdline', 'sysctl'): opt.set_state(data.get(opt.name, None)) else: assert(data_type == 'version'), \ - f'unexpected data type "{data_type}"' + f'unexpected data_type "{data_type}"' opt.set_state(data) def populate_opt_with_data(opt, data, data_type): - assert(opt.type != 'version'), 'a single VersionCheck is useless' - if opt.type != 'complex': + assert(opt.opt_type != 'version'), 'a single VersionCheck is useless' + if opt.opt_type != 'complex': populate_simple_opt_with_data(opt, data, data_type) else: for o in opt.opts: - if o.type != 'complex': + if o.opt_type != 'complex': populate_simple_opt_with_data(o, data, data_type) else: # Recursion for nested ComplexOptCheck objects @@ -337,8 +337,8 @@ def populate_with_data(checklist, data, data_type): def override_expected_value(checklist, name, new_val): for opt in checklist: if opt.name == name: - assert(opt.type in ('kconfig', 'cmdline', 'sysctl')), \ - f'overriding an expected value for "{opt.type}" checks is not supported yet' + assert(opt.opt_type in ('kconfig', 'cmdline', 'sysctl')), \ + f'overriding an expected value for "{opt.opt_type}" checks is not supported yet' opt.expected = new_val -- 2.31.1