mirror of
https://github.com/microsoft/regorus.git
synced 2026-08-05 02:16:11 +00:00
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:
committed by
GitHub
parent
25902bab57
commit
df98c8d168
@@ -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"
|
||||
|
||||
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user