Reporters

Base reporter

class hammurabi.reporters.base.Reporter(laws: List[hammurabi.law.Law])[source]

Abstract class which describes the bare minimum and helper functions for Reporters. A reporter can generate different outputs from the results of the execution. Also, reporters can be extended by additional data which may not contain data for every execution like GitHub pull request url. The report file’s name set by report_name config parameter.

Note

Reporters measures the execution time for the complete execution from checking out the git branch until the pull request creation finished. Although the completion time is measured, it is not detailed for the rules. At this moment measuring execution time of rules is not planned.

Example usage:

>>> from hammurabi.reporters.base import Reporter
>>>
>>>
>>> class JsonReporter(Reporter):
>>>     def report(self) -> str:
>>>         return self._get_report().json()
Parameters

laws (Iterable[Law]) – Iterable Law objects which will be included to the report

Formatted reporters

JsonReporter

class hammurabi.reporters.json.JsonReporter(laws: List[hammurabi.law.Law])[source]

Generate reports in Json format and write into file. JsonReporter is the default reporter of the pillar. The example below shows the way how to replace a reporter which could base on the JsonReporter.

The report will be written into the configured report file. The report file’s name set by report_name config parameter.

Example usage:

>>> from pathlib import Path
>>> from hammurabi import Law, Pillar, OwnerChanged
>>> from my_company import MyJsonReporter
>>>
>>> example_law = Law(
>>>     name="Name of the law",
>>>     description="Well detailed description what this law does.",
>>>     rules=(
>>>         OwnerChanged(
>>>             name="Change ownership of nginx config",
>>>             path=Path("./nginx.conf"),
>>>             new_value="www:web_admin"
>>>         ),
>>>     )
>>> )
>>>
>>> # override pillar's default JsonReporter reporter
>>> pillar = Pillar(reporter_class=MyJsonReporter)