feat: Add validation for invalid duration units in CERTIFICATE_EXPIRA… #1171
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds validation to reject invalid duration units (like
d
,w
,mo
,y
) when usedwith the
CERTIFICATE_EXPIRATION
condition. Go'stime.Duration
only supports units up tohours (
h
), so using larger units like days would silently fail and evaluate to 0.Problem
Previously, when users attempted to use conditions like:
The
14d
would fail to parse as a valid duration and default to 0, causing the condition tobehave unexpectedly without any clear error message.
Related issues:
Solution
Added validation that:
Example Error Message
When using an invalid duration unit:
invalid duration unit in condition '[CERTIFICATE_EXPIRATION] > 14d': Go's time.Duration only supports units up to 'h' (hours). Use hours instead (e.g., '336h' instead of '14d')
Changes
isDurationWithInvalidUnit()
helper to detect invalid duration formatsCondition.Validate()
to check for invalid units in CERTIFICATE_EXPIRATIONconditions
Checklist
README.md
, if applicable.