-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: extract PolicyGenerator trait and collapse parallel engine fields #79
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a12113f
docs: add issue-checking step to /pr command
boorad 9346d44
refactor: collapse Finding stub fields into policy_outputs
boorad 191fd40
refactor: collapse rule TOML templates into policy_templates
boorad b9497c6
refactor: extract PolicyGenerator trait
boorad 8bca940
refactor: tighten PolicyGenerator dispatch and dedupe engine entries
boorad 6627b80
fix: address PR #79 review feedback
boorad fc3779d
docs: clarify /pr token extraction and plan search rules
boorad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| //! [`PolicyGenerator`] implementation for Cedar. Thin adapter over the | ||
| //! engine-specific `templates`, `validator`, and `grouping` modules. | ||
|
|
||
| use std::collections::HashMap; | ||
| use std::path::Path; | ||
|
|
||
| use crate::policy::{PolicyFile, PolicyGenerator, ValidationResult}; | ||
| use crate::types::{AuthCategory, Confidence, Finding, PolicyEngine}; | ||
|
|
||
| pub struct CedarGenerator; | ||
|
|
||
| impl PolicyGenerator for CedarGenerator { | ||
| fn engine(&self) -> PolicyEngine { | ||
| PolicyEngine::Cedar | ||
| } | ||
|
|
||
| fn validate(&self, policy: &str) -> ValidationResult { | ||
| let r = super::validator::validate_cedar(policy); | ||
| ValidationResult { | ||
| valid: r.valid, | ||
| error: r.error, | ||
| } | ||
| } | ||
|
|
||
| fn render_template(&self, template: &str, vars: &HashMap<String, String>) -> String { | ||
| super::templates::render_template(template, vars) | ||
| } | ||
|
|
||
| fn default_stub(&self, category: AuthCategory, snippet: &str) -> String { | ||
| super::templates::generate_default_stub(category, snippet) | ||
| } | ||
|
|
||
| fn wrap_by_confidence(&self, body: &str, confidence: Confidence) -> String { | ||
| super::templates::apply_confidence_wrapping(body, confidence) | ||
| } | ||
|
|
||
| fn group_and_generate( | ||
| &self, | ||
| findings: &[Finding], | ||
| policy_prefix: &str, | ||
| output_dir: &Path, | ||
| ) -> Vec<PolicyFile> { | ||
| super::grouping::group_findings(findings, policy_prefix, output_dir) | ||
| .into_iter() | ||
| .map(|f| PolicyFile { | ||
| label: f.label, | ||
| output_path: f.output_path, | ||
| content: f.content, | ||
| finding_count: f.finding_count, | ||
| }) | ||
| .collect() | ||
| } | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| pub mod generator; | ||
| pub mod grouping; | ||
| pub mod templates; | ||
| pub mod validator; | ||
|
|
||
| pub use generator::CedarGenerator; | ||
| pub use grouping::group_findings; | ||
| pub use templates::render_template; |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.