fix(policy): report correct rule count in /policy status when using policy_file#1901
Merged
fix(policy): report correct rule count in /policy status when using policy_file#1901
Conversation
…olicy_file handle_policy_command() was using policy_config.rules.len() which only counts inline TOML rules. Rules loaded via policy_file are merged during PolicyEnforcer::compile() and never reflected in that field. Add PolicyEnforcer::rule_count() accessor and use PolicyEnforcer::compile() in the status handler to get the merged total, falling back to inline count on compile error. Closes #1898.
65bad32 to
d818379
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
/policy statusreportedrules: 0when all rules came from an externalpolicy_filehandle_policy_command()usedpolicy_config.rules.len()which only counts inline TOML entries; file-loaded rules are merged inPolicyEnforcer::compile()and never written back topolicy_config.rulesPolicyEnforcer::rule_count()accessor; status handler now callsPolicyEnforcer::compile()to get the merged total, with fallback to the inline count on compile errorTest plan
cargo nextest run --workspace --features full --lib --bins)cargo clippy --features full --workspace --lib --bins -- -D warningspassescargo +nightly fmt --checkpassespolicy_fileonly shows correct non-zero rule count in/policy statusCloses #1898.