-
Notifications
You must be signed in to change notification settings - Fork 59
Include enforcement date in warnings for future effective_on violations #3412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -997,7 +997,14 @@ func (f *LegacyPostEvaluationFilter) CategorizeResults( | |
| } | ||
| case "failure": | ||
| if getSeverity(result) == severityWarning || !isResultEffective(result, effectiveTime) { | ||
| warnings = append(warnings, result) | ||
| // If being demoted due to future effective_on, enhance the message | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] correctness When a deny result has both severity:warning AND a future effective_on, the message claims it will become a failure, but the severity annotation keeps it as a warning even after the date passes. This is misleading for contradictory rule configurations. Suggested fix: Consider guarding the enhancement to only fire when the demotion reason is exclusively the future effective_on (i.e., getSeverity != severityWarning), or add a code comment noting this edge case. |
||
| if !isResultEffective(result, effectiveTime) { | ||
| enhancedResult := result | ||
| enhancedResult.Message = formatFutureEnforcementMessage(result) | ||
| warnings = append(warnings, enhancedResult) | ||
| } else { | ||
| warnings = append(warnings, result) | ||
| } | ||
| } else { | ||
| failures = append(failures, result) | ||
| } | ||
|
|
@@ -1120,7 +1127,14 @@ func (f *UnifiedPostEvaluationFilter) CategorizeResults( | |
| } | ||
| case "failure": | ||
| if getSeverity(filteredResult) == severityWarning || !isResultEffective(filteredResult, effectiveTime) { | ||
| warnings = append(warnings, filteredResult) | ||
| // If being demoted due to future effective_on, enhance the message | ||
| if !isResultEffective(filteredResult, effectiveTime) { | ||
| enhancedResult := filteredResult | ||
| enhancedResult.Message = formatFutureEnforcementMessage(filteredResult) | ||
| warnings = append(warnings, enhancedResult) | ||
| } else { | ||
| warnings = append(warnings, filteredResult) | ||
| } | ||
| } else { | ||
| failures = append(failures, filteredResult) | ||
| } | ||
|
|
@@ -1204,3 +1218,21 @@ func (f *UnifiedPostEvaluationFilter) determineOriginalType(filteredResult Resul | |
|
|
||
| return "unknown" | ||
| } | ||
|
|
||
| // formatFutureEnforcementMessage enhances a result message to indicate when | ||
| // a future effective_on date will cause enforcement to begin. | ||
| // Returns the enhanced message if effective_on is present, otherwise returns | ||
| // the original message unchanged. | ||
| func formatFutureEnforcementMessage(result Result) string { | ||
| originalMessage := result.Message | ||
|
|
||
| // Check if this result has an effective_on date | ||
| effectiveOnStr, ok := result.Metadata[metadataEffectiveOn].(string) | ||
| if !ok || effectiveOnStr == "" { | ||
| return originalMessage | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [low] correctness strings.TrimRight(originalMessage, ".") removes all trailing characters in the cutset, not just a single trailing period. If a message ends with "..." (ellipsis), all three dots are stripped. strings.TrimSuffix would be more precise. Suggested fix: Replace strings.TrimRight(originalMessage, ".") with strings.TrimSuffix(originalMessage, ".") to remove exactly one trailing period. |
||
|
|
||
| // Append enforcement notice with the effective_on date as-is | ||
| return fmt.Sprintf("%s. This will become a failure starting on %s", | ||
| strings.TrimRight(originalMessage, "."), effectiveOnStr) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[low] maintainability
The same 7-line enhancement block is duplicated in both LegacyPostEvaluationFilter.CategorizeResults and UnifiedPostEvaluationFilter.CategorizeResults. Changes to message format or guards require updating both sites.
Suggested fix: Extract a small helper function (e.g., appendWithEnhancement) to eliminate the duplication.