Skip to content

Commit 6921888

Browse files
committed
Add feature and rename structs
1 parent ba47b39 commit 6921888

4 files changed

Lines changed: 20 additions & 9 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ default = ["full-opa", "arc"]
2323

2424
arc = ["scientific/arc"]
2525
ast = []
26+
azure_policy = []
2627
base64 = ["dep:data-encoding"]
2728
base64url = ["dep:data-encoding"]
2829
coverage = []

bindings/ffi/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ pub extern "C" fn regorus_engine_get_ast_as_json(engine: *mut RegorusEngine) ->
461461
///
462462
/// See https://docs.rs/regorus/latest/regorus/coverage/struct.Engine.html#method.get_policy_package_names
463463
#[no_mangle]
464+
#[cfg(feature = "azure_policy")]
464465
pub extern "C" fn regorus_engine_get_policy_package_names(engine: *mut RegorusEngine) -> RegorusResult {
465466
let output = || -> Result<String> { serde_json::to_string_pretty(&to_ref(engine)?.engine.get_policy_package_names()?).map_err(anyhow::Error::msg) }();
466467
match output {
@@ -477,6 +478,7 @@ pub extern "C" fn regorus_engine_get_policy_package_names(engine: *mut RegorusEn
477478
///
478479
/// See https://docs.rs/regorus/latest/regorus/coverage/struct.Engine.html#method.get_policy_parameters
479480
#[no_mangle]
481+
#[cfg(feature = "azure_policy")]
480482
pub extern "C" fn regorus_engine_get_policy_parameters(engine: *mut RegorusEngine) -> RegorusResult {
481483
let output = || -> Result<String> { serde_json::to_string_pretty(&to_ref(engine)?.engine.get_policy_parameters()?).map_err(anyhow::Error::msg) }();
482484
match output {

src/engine.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ pub struct PolicyPackageNameDefinition {
3030
}
3131

3232
#[derive(Debug, Clone, Serialize)]
33-
pub struct PolicyParameterDetails {
33+
pub struct PolicyParameter {
3434
pub name: String,
3535
pub modifiable: bool,
3636
pub required: bool,
3737
}
3838

3939
#[derive(Debug, Clone, Serialize)]
40-
pub struct PolicyModifierDetails {
40+
pub struct PolicyModifier {
4141
pub name: String,
4242
}
4343

4444
#[derive(Debug, Clone, Serialize)]
45-
pub struct PolicyParameterDefinition {
45+
pub struct PolicyParameters {
4646
pub source_file: String,
47-
pub parameters: Vec<PolicyParameterDetails>,
48-
pub modifiers: Vec<PolicyModifierDetails>,
47+
pub parameters: Vec<PolicyParameter>,
48+
pub modifiers: Vec<PolicyModifier>,
4949
}
5050

5151
/// Create a default engine.
@@ -950,6 +950,8 @@ impl Engine {
950950
/// # Ok(())
951951
/// # }
952952
/// ```
953+
#[cfg(feature = "azure_policy")]
954+
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
953955
pub fn get_policy_package_names(&self) -> Result<Vec<PolicyPackageNameDefinition>> {
954956
let mut package_names = vec![];
955957
for m in &self.modules {
@@ -981,7 +983,9 @@ impl Engine {
981983
/// # Ok(())
982984
/// # }
983985
/// ```
984-
pub fn get_policy_parameters(&self) -> Result<Vec<PolicyParameterDefinition>> {
986+
#[cfg(feature = "azure_policy")]
987+
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
988+
pub fn get_policy_parameters(&self) -> Result<Vec<PolicyParameters>> {
985989
let mut policy_parameter_definitions = vec![];
986990
for m in &self.modules {
987991
let mut parameters = vec![];
@@ -996,7 +1000,7 @@ impl Engine {
9961000

9971001
if paths.len() == 2 && paths[0] == "parameters" {
9981002
// Todo: Fetch fields other than name from rego metadoc for the parameter
999-
parameters.push(PolicyParameterDetails {
1003+
parameters.push(PolicyParameter {
10001004
name: paths[1].to_string(),
10011005
modifiable: false,
10021006
required: false,
@@ -1014,7 +1018,7 @@ impl Engine {
10141018

10151019
if paths.len() == 2 && paths[0] == "parameters" {
10161020
// Todo: Fetch fields other than name from rego metadoc for the parameter
1017-
modifiers.push(PolicyModifierDetails {
1021+
modifiers.push(PolicyModifier {
10181022
name: paths[1].to_string(),
10191023
})
10201024
}
@@ -1025,7 +1029,7 @@ impl Engine {
10251029
}
10261030
}
10271031

1028-
policy_parameter_definitions.push(PolicyParameterDefinition {
1032+
policy_parameter_definitions.push(PolicyParameters {
10291033
source_file: m.package.span.source.file().to_string(),
10301034
parameters,
10311035
modifiers,

tests/engine/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ fn extension_with_state() -> Result<()> {
103103
}
104104

105105
#[test]
106+
#[cfg(feature = "azure_policy")]
107+
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
106108
fn get_policy_package_names() -> Result<()> {
107109
let mut engine = Engine::new();
108110
engine.add_policy(
@@ -138,6 +140,8 @@ fn get_policy_package_names() -> Result<()> {
138140
}
139141

140142
#[test]
143+
#[cfg(feature = "azure_policy")]
144+
#[cfg_attr(docsrs, doc(cfg(feature = "azure_policy")))]
141145
fn get_policy_parameters() -> Result<()> {
142146
let mut engine = Engine::new();
143147
engine.add_policy(

0 commit comments

Comments
 (0)