Provide ability to get JSON representation of policy AST (#266)

closes #265

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
This commit is contained in:
Anand Krishnamoorthi
2024-06-08 21:58:30 -04:00
committed by GitHub
parent 25902bab57
commit df98c8d168
15 changed files with 191 additions and 6 deletions

View File

@@ -12,7 +12,9 @@ keywords = ["interpreter", "opa", "policy-as-code", "rego"]
crate-type = ["cdylib"]
[features]
default = ["regorus/std", "regorus/full-opa"]
default = ["ast", "coverage", "regorus/std", "regorus/full-opa"]
ast = ["regorus/ast"]
coverage = ["regorus/coverage"]
[dependencies]
anyhow = "1.0"

View File

@@ -312,6 +312,7 @@ impl Engine {
/// Get coverage report as json.
///
#[cfg(feature = "coverage")]
pub fn get_coverage_report_as_json(&self) -> Result<String> {
let report = self.engine.get_coverage_report()?;
serde_json::to_string_pretty(&report).map_err(|e| anyhow!("{e}"))
@@ -319,12 +320,14 @@ impl Engine {
/// Get coverage report as pretty printable string.
///
#[cfg(feature = "coverage")]
pub fn get_coverage_report_pretty(&self) -> Result<String> {
self.engine.get_coverage_report()?.to_string_pretty()
}
/// Clear coverage data.
///
#[cfg(feature = "coverage")]
pub fn clear_coverage_data(&mut self) {
self.engine.clear_coverage_data();
}
@@ -350,6 +353,13 @@ impl Engine {
engine: self.engine.clone(),
}
}
/// Get AST of policies.
///
#[cfg(feature = "ast")]
pub fn get_ast_as_json(&self) -> Result<String> {
self.engine.get_ast_as_json()
}
}
#[pymodule]