Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoblon committed Nov 16, 2020
1 parent 8a5beba commit 1ea2d78
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 21 deletions.
2 changes: 1 addition & 1 deletion rudder-lang/src/generator/cfengine/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ mod tests {
.condition("debian".to_string())
.build()).to_string()
,
"bundle agent test {\n\n methods:\n # component:\n # \n # \n # \n \"component_${report_data.directive_id}_0\" usebundle => _method_reporting_context(\"component\", \"parameter\"),\n if => concat(\"debian\");\n \"component_${report_data.directive_id}_0\" usebundle => package_present(vim),\n if => concat(\"debian\");\n \"component_${report_data.directive_id}_0\" usebundle => _classes_noop(canonify(\"${class_prefix}_package_present_parameter\")),\n unless => concat(\"debian\");\n \"component_${report_data.directive_id}_0\" usebundle => log_rudder(\"Skipping method \'component\' with key parameter \'parameter\' since condition \'debian\' is not reached\", \"parameter\", canonify(\"${class_prefix}_package_present_parameter\"), canonify(\"${class_prefix}_package_present_parameter\"), @{args}),\n unless => concat(\"debian\");\n\n}"
"bundle agent test {\n\n methods:\n # component:\n # \n # \n # \n \"component_${report_data.directive_id}_0\" usebundle => _method_reporting_context(\"component\", \"parameter\");\n \"component_${report_data.directive_id}_0\" usebundle => log_na_rudder(\"\'component\' method is not available on classic Rudder agent, skip\", \"parameter\", \"${class_prefix}_package_present_parameter\", @{args});\n\n}"
);
}

Expand Down
52 changes: 37 additions & 15 deletions rudder-lang/src/ir/ir1.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2019-2020 Normation SAS

use super::{context::*, enums::EnumList, resource::*, value::*};
use super::{
context::*,
enums::{EnumExpression, EnumExpressionPart, EnumList},
resource::*,
value::*,
};
use crate::{error::*, parser::*};
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -196,19 +201,36 @@ impl<'src> IR1<'src> {
},
}
}
// for variable in cond_var {
// let PCondVariableDef {
// metadata,
// name,
// resource,
// state,
// state_params,
// } = variable;
// state_params
// .iter()
// .map(|arg| Value::from_pvalue(&self.enum_list, context, arg))
// .collect() // TODO TODODODODODODODO
// }
for variable in cond_var {
println!("VAR = {:#?}", variable);
let PCondVariableDef {
metadata,
name,
resource,
state,
state_params,
} = variable;
// recreate a complex value based on bool condition_from_ exception and add it to the context
match context.add_variable_declaration(name, Type::Boolean) {
Err(e) => self.errors.push(e),
Ok(()) => {
self.variable_definitions.insert(
name,
ComplexValue::new(
name,
vec![(
EnumExpression {
source: name,
expression: EnumExpressionPart::Default(resource),
},
// bool value is set at true but it should not be used bc the real value is not known at compile time
Some(Value::Boolean(name, true)),
)],
),
);
}
}
}
}

/// Add the variables extensions to the global definition space
Expand Down Expand Up @@ -400,7 +422,7 @@ mod tests {
let mut source = source.clone();
source.push_str(append);
let res = parse_str(name, &source);
assert!(res.is_err(), "OK instead of Error {:?}", res);
assert!(res.is_err(), "OK instead of Error {:#?}", res);
}

fn parse_str<'src>(name: &'src str, source: &'src str) -> Result<IR1<'src>> {
Expand Down
7 changes: 7 additions & 0 deletions rudder-lang/src/ir/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ pub struct ComplexValue<'src> {
cases: Vec<(EnumExpression<'src>, Option<Value<'src>>)>,
}
impl<'src> ComplexValue<'src> {
pub fn new(
source: Token<'src>,
cases: Vec<(EnumExpression<'src>, Option<Value<'src>>)>,
) -> Self {
Self { source, cases }
}

pub fn from_pcomplex_value(
enum_list: &EnumList<'src>,
context: &VarContext<'src>,
Expand Down
4 changes: 0 additions & 4 deletions rudder-lang/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@ fn pinteger(i: PInput) -> PResult<(Token, i64)> {
fn plist(i: PInput) -> PResult<Vec<PValue>> {
wsequence!(
{
// s: tag("[");
// values: separated_list(sp(etag(",")), pvalue);
// _x: or_fail(peek(is_not(",")), || PErrorKind::ExpectedToken("parameter"));
// _x: or_fail(tag("]"),|| PErrorKind::UnterminatedDelimiter(s));
values: delimited_list("[", pvalue, ",", "]");
} => values
)(i)
Expand Down
1 change: 0 additions & 1 deletion rudder-lang/tests/techniques/cis/technique.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ function Cis {
} else {
_rudder_common_report_na -componentName "Service started" -componentKey "${service}" -message "Not applicable" -reportId $reportId -techniqueName $techniqueName -auditOnly:$auditOnly
}

}

0 comments on commit 1ea2d78

Please sign in to comment.