Skip to content

Commit

Permalink
PolicyDefinition make parseDefinition non-static and adjust accesses
Browse files Browse the repository at this point in the history
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
  • Loading branch information
kingthorin committed Nov 8, 2024
1 parent 94ffcbd commit 9f85171
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ public void verifyParameters(AutomationProgress progress) {
break;
case "policyDefinition":
// Parse the policy defn
PolicyDefinition.parsePolicyDefinition(
jobData.get(key), policyDefinition, this.getName(), progress);
policyDefinition.parsePolicyDefinition(
jobData.get(key), this.getName(), progress);
break;
case "name":
case "tests":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void verifyParameters(AutomationProgress progress) {
break;
case "policyDefinition":
// Parse the policy defn
PolicyDefinition.parsePolicyDefinition(
jobData.get(key), policyDefinition, this.getName(), progress);
policyDefinition.parsePolicyDefinition(
jobData.get(key), this.getName(), progress);
break;
case "name":
case "tests":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,28 +43,25 @@ public class PolicyDefinition extends AutomationData {
private String defaultThreshold = JobUtils.thresholdToI18n(AlertThreshold.MEDIUM.name());
private List<Rule> rules = new ArrayList<>();

public static void parsePolicyDefinition(
Object policyDefnObj,
PolicyDefinition policyDefinition,
String jobName,
AutomationProgress progress) {
public void parsePolicyDefinition(
Object policyDefnObj, String jobName, AutomationProgress progress) {

if (policyDefnObj instanceof LinkedHashMap<?, ?>) {
LinkedHashMap<?, ?> policyDefnData = (LinkedHashMap<?, ?>) policyDefnObj;

if (policyDefnData.isEmpty()) {
policyDefinition.setDefaultStrength(null);
this.defaultStrength = null;
return;
}

JobUtils.applyParamsToObject(
policyDefnData,
policyDefinition,
this,
jobName,
new String[] {PolicyDefinition.RULES_ELEMENT_NAME},
progress);

List<Rule> rules = new ArrayList<>();
this.rules = new ArrayList<>();
ScanPolicy scanPolicy = new ScanPolicy();
PluginFactory pluginFactory = scanPolicy.getPluginFactory();

Expand Down Expand Up @@ -94,7 +91,7 @@ public static void parsePolicyDefinition(
if (strength != null) {
rule.setStrength(strength.name().toLowerCase());
}
rules.add(rule);
this.rules.add(rule);

} else {
progress.warn(
Expand All @@ -103,7 +100,6 @@ public static void parsePolicyDefinition(
}
}
}
policyDefinition.setRules(rules);
} else if (o != null) {
progress.warn(
Constant.messages.getString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void shouldParseValidDefinition() {
Object data = yaml.load(yamlStr);

// When
PolicyDefinition.parsePolicyDefinition(data, policyDefinition, "test", progress);
policyDefinition.parsePolicyDefinition(data, "test", progress);

// Then
assertThat(progress.hasErrors(), is(equalTo(false)));
Expand Down Expand Up @@ -223,7 +223,7 @@ void shouldWarnIfUnknownRule() {
Object data = yaml.load(yamlStr);

// When
PolicyDefinition.parsePolicyDefinition(data, policyDefinition, "test", progress);
policyDefinition.parsePolicyDefinition(data, "test", progress);

// Then
assertThat(progress.hasErrors(), is(equalTo(false)));
Expand All @@ -250,7 +250,7 @@ void shouldWarnIfDefnNotList() {
Object data = yaml.load(yamlStr);

// When
PolicyDefinition.parsePolicyDefinition(data, policyDefinition, "test", progress);
policyDefinition.parsePolicyDefinition(data, "test", progress);

// Then
assertThat(progress.hasErrors(), is(equalTo(false)));
Expand All @@ -270,7 +270,7 @@ void shouldWarnIfRulesNotList() {
Object data = yaml.load(yamlStr);

// When
PolicyDefinition.parsePolicyDefinition(data, policyDefinition, "test", progress);
policyDefinition.parsePolicyDefinition(data, "test", progress);

// Then
assertThat(progress.hasErrors(), is(equalTo(false)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void verifyParameters(AutomationProgress progress) {
case "policyDefinition":
// Parse the policy defn
policyDefinition.parsePolicyDefinition(
jobData.get(key), policyDefinition, this.getName(), progress);
jobData.get(key), this.getName(), progress);
break;
case "name":
case "tests":
Expand Down

0 comments on commit 9f85171

Please sign in to comment.