Skip to content

Commit 6b3eb24

Browse files
committed
docs: add a step to declare the ORM mapped class for checks
Signed-off-by: behnazh-w <[email protected]>
1 parent 17aa29a commit 6b3eb24

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/macaron/slsa_analyzer/checks/README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ These are the steps for creating a Check in Macaron:
1111
1. Create a module with the name `<name>_check.py`. Note that Macaron **only** loads check modules that have this name format.
1212
2. Create a class that inherits `BaseCheck` and initiates the attributes of a `BaseCheck` instance.
1313
3. Register the newly created Check class to the Registry ([registry.py](../registry.py)). This will make the Check available to Macaron. For example:
14-
```
14+
```python
1515
from macaron.slsa_analyzer.registry import registry
1616

1717
# Check class is defined here
@@ -20,5 +20,23 @@ from macaron.slsa_analyzer.registry import registry
2020

2121
registry.register(ExampleCheck())
2222
```
23+
4. Add an ORM mapped class for the check facts so that the policy engine can reason about the properties. To provide the mapped class, all you need to do is to add a class that inherits from `CheckFacts` class and add the following attributes (rename the `MyCheckFacts` check name and `__tablename__` as appropriate).
24+
25+
```python
26+
class MyCheckFacts(CheckFacts):
27+
"""The ORM mapping for justifications in my check."""
28+
29+
__tablename__ = "_my_check"
30+
31+
#: The primary key.
32+
id: Mapped[int] = mapped_column(ForeignKey("_check_facts.id"), primary_key=True) # noqa: A003
33+
34+
#: The name of the column (property) that becomes available to policy engine.
35+
my_column_name: Mapped[str] = mapped_column(String, nullable=False)
36+
37+
__mapper_args__ = {
38+
"polymorphic_identity": "_my_check",
39+
}
40+
```
2341

2442
For more examples, please see the existing Checks in [checks/](./).

0 commit comments

Comments
 (0)