BOAReportAbstract¶
This file contains the class which is the base for the Report, which is the class that displays the information about all the found threats.
- class reports.boar_abstract.BOAReportAbstract(severity_enum, args)¶
BOAReportAbstract class.
It implements the necessary methods to initialize, fill and display the threats report after the analysis.
If you want to define your own Report class you will have to define a new class which inherits from this one.
- Raises
BOAReportException – this exception could be raised anywhere in the class.
- __init__(severity_enum, args)¶
It initializes the class with the necessary variables.
- Parameters
severity_enum (type) – enumeration which will be used for the threats severity. It has to inherit from SeverityBase but not be SeverityBase.
- Raises
BOAReportEnumTypeNotExpected – when severity_enum is not a type of SeverityBase or is SeverityBase.
TypeError – when severity_enum is not a type or at least not an expected instance.
- __weakref__¶
list of weak references to the object (if defined)
- add(who, description, severity, advice=None, row=None, col=None, sort_by_severity=True, severity_enum=None)¶
It adds a new record to the main report.
- Parameters
who (str) – “module_name.class_name” (without quotes) format to identify who raised the threat.
description (str) – description about the found threat.
severity (SeverityBase) – threat severity.
advice (str) – advice to solve the threat. It is optional.
row (int) – threat row. It is optional.
col (int) – threat col. It is optional.
sort_by_severity (bool) – if True, the threats will be added sorting by severity (higher values will be added first). The default value is True.
severity_enum (type) – enumeration which will be used for the threats severity. This arg is intended to be able to join different Report instances. Default is None which means to use self.severity_enum.
- Returns
status code
- Return type
int
- append(report_instance, sort_by_severity=True, stop_if_fails=False, who=None)¶
It appends other threats report records to this.
The goal of this method is to be able to append multiple reports which will be created for each module and end up with only a report to show to the user.
- Parameters
report_instance (Report) – the report to be appended to this.
sort_by_severity (bool) – if True, the threats will be added sorting by severity (higher values will be added first). The default value is True.
stop_if_fails (bool) – if True and any threat record cannot be appended, the execution will stop. The default value if False.
who (str) – the module name which is going to be used to set the relation between the module and the report instance.
- Returns
status code
- Return type
int
- abstract display(who, display=True)¶
It displays all the threats from a concrete module.
This method is intended to be invoked by display_all.
- Parameters
who (str) – the module which found the threat.
display (bool) – if True, it displays the threat.
- Raises
BOAReportWhoNotFound – if the given module is not found.
- Returns
text to be displayed
- Return type
str
- abstract display_all(print_summary=True, display=True)¶
It displays all the threats from all the modules. Moreover, it prints a summary at the end optionally.
This method should invoke display which should invoke pretty_print_tuple. You can avoid this overriding the methods using “pass”, but if you do this, this method will have to make all the work.
- Parameters
print_summary (bool) – if True, it prints a summary with statistics about all the found threats.
display (bool) – if True, it displays the threat.
- Returns
text to be displayed
- Return type
str
- get_severity_enum_instance()¶
It returns the severity enumeration instance which is being used.
- Returns
severity enumeration being used
- Return type
Note
This is the GENERAL severity enum reference, which may not be what you are looking for. If you want the severity enum instance of a concrete module, use get_severity_enum_instance_by_who() instead.
- get_severity_enum_instance_by_who(who)¶
It returns the severity enum instance of a concrete module.
- Parameters
who (str) – module name in format “module_name.class_name”.
- Returns
the severity enum instance which is used for the given module. None if who is not found
- Return type
- get_summary()¶
It returns a summary of all the threat records.
- Returns
summary of threat records. Its key format is (without quotes) “module_name.class_name” and the value is a list of tuples
- Return type
dict
- get_who()¶
It returns the modules which are in the current report.
- Returns
list containing the modules which are in the current report
- Return type
list (str)
- abstract pretty_print_tuple(t, first_time=False, reported_by=False, display=True)¶
It prints a pretty line about a found threat record.
This method is intended to be invoked by display.
The expected format for the tuple is next:
str: module who raised the threat.
str: threat description.
SeverityBase: threat severity.
str (optional): advice for solving the threat. If it is not provided, the string “not specified” will be displayed.
int (optional): threat row. If it is not provided, the value -1 will be displayed.
int (optional): threat col. If it is not provided, the value -1 will be displayed.
- type: SeverityBase type which will be used to display
the severity. This value is intented to be able to join different Report instances.
- Parameters
t (tuple) – threat record.
first_time (bool) – if you want to display a pretty box around the module name who raised the threat, this value must be True. The default value is False.
reported_by (bool) – if you want to display the module who raised the threat, this value must be True. This arg should be used when you want to avoid the arg first_time. The default value is False.
display (bool) – if True, it displays the threat.
- Returns
text to be displayed
- Return type
str
Note
If you want to show orderly the threats, you should use first_time=True for the first record and first_time=False for the rest. If you do not want to show it orderly, you should use reported_by=True.
- set_severity_enum_mapping(who, severity_enum_instance)¶
It sets the relation between a module and a severity enum.
- Parameters
who (str) – the module name in format “module_name.class_name”.
severity_enum_instance (SeverityBase) – severity enum instance.
- Returns
it returns True if the relation was set. False otherwise
- Return type
bool