Recertification Checking
Relevant source files
The following files were used as context for generating this wiki page:The Recertification Checking module is a core component of the IaC Recertification Engine (ICE). Its primary responsibility is to analyze a list of scanned files and determine whether each file requires recertification based on its age and predefined configuration rules. This component acts as the decision-making heart of the engine, producing a list of results that detail which files have passed their recertification deadline, how overdue they are, and their assigned priority.
The checking process is initiated by the main Engine after files have been scanned and enriched with Git history. The results from the checker are then passed to the Grouping Strategy to bundle related files into pull requests.
Sources: internal/engine/engine.go:110-114, internal/scan/recert_checker.go
Core Logic and Flow
The recertification checking logic is encapsulated within the Checker struct and its Check method. The process iterates through each file, matches it against configured patterns, and performs the age calculation.
Sources: internal/scan/recert_checker.go:18-20
The following diagram illustrates the high-level workflow of the Check method.
This diagram shows the step-by-step logic executed by the Checker.Check method for every file.
Sources: internal/scan/recert_checker.go:23-130
File Matching
For each file, the checker determines the first Pattern that it matches.
- The file's path is made relative to the repository root.
- It iterates through the
patternsdefined in the configuration. - For each enabled pattern, it uses
doublestar.PathMatchto check if the file's relative path matches any of the glob patterns inpattern.Paths. - If a match is found, it then checks against the
pattern.Excludelist. If the file matches an exclusion glob, it is ignored for that pattern. - The first pattern that includes the file and does not exclude it is used for the check.
Sources: internal/scan/recert_checker.go:34-78
Recertification Calculation
Once a file is matched to a pattern, the checker calculates its recertification status.
- Days Since Last Modified: The number of days since the file was last modified is calculated as
int(time.Since(file.LastModified).Hours() / 24). - Threshold: The recertification period in days is retrieved from the matched pattern's
RecertificationDaysfield. - Needs Recertification: A boolean flag,
NeedsRecert, is set totrueif the days since last modification is greater than or equal to the threshold.
Sources: internal/scan/recert_checker.go:87-89
Priority Calculation
A key feature of the checker is to assign a priority to each file. This helps teams prioritize which recertifications to address first. The priority is calculated based on the ratio of how long it has been since the last modification (DaysSince) versus the configured Threshold.
The logic is as follows:
Ratio (DaysSince / Threshold) | NeedsRecert | Priority |
|---|---|---|
| > 1.5 | true | Critical |
| >= 1.0 | true | High |
| >= 0.8 | false | Medium |
| < 0.8 | false | Low |
Note: The code contains a condition for Medium priority when NeedsRecert is true and the ratio is >= 0.8. However, this is superseded by the High and Critical conditions. The effective logic is represented in the table above.
Sources: internal/scan/recert_checker.go:91-107, internal/scan/recert_checker_test.go:20-120
The following diagram visualizes the priority assignment logic.
This diagram shows how the ratio of days since modification to the threshold determines the priority level.
Sources: internal/scan/recert_checker.go:92-107
Data Structures
The checking process relies on several key data structures for its input and output.
Input: config.Pattern
This struct defines the rules for recertification. The checker primarily uses the fields listed below.
| Field | Type | Description |
|---|---|---|
Name | string | A unique name for the pattern. |
Paths | []string | A list of glob patterns to identify files. |
Exclude | []string | A list of glob patterns to exclude files that matched Paths. |
RecertificationDays | int | The number of days before a file needs recertification. |
Enabled | bool | If false, this pattern is ignored. |
Sources: internal/config/types.go:41-49, example.config.yaml:23-44
Input: types.FileInfo
This struct contains the file metadata needed for the check.
| Field | Type | Description |
|---|---|---|
Path | string | The absolute path to the file. |
LastModified | time.Time | The timestamp of the last commit for this file. |
Sources: internal/types/types.go:7-13
Output: types.RecertCheckResult
This is the primary output of the Check method. A slice of these structs is returned, with one entry for each file that matched a pattern.
| Field | Type | Description |
|---|---|---|
File | FileInfo | The original file information. |
PatternName | string | The name of the pattern that the file matched. |
DaysSince | int | The calculated number of days since the file was last modified. |
Threshold | int | The recertification threshold in days, from the matched pattern. |
Priority | string | The calculated priority: "Critical", "High", "Medium", or "Low". |
NeedsRecert | bool | true if the file is due for recertification. |
NextDueDate | time.Time | The calculated date when the file is/was due for recertification. |
Sources: internal/types/types.go:15-23, internal/scan/recert_checker.go:111-121
The relationship between these structures is shown below.
This diagram shows that a Pattern and a FileInfo are used to generate a RecertCheckResult.