Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: mehab <[email protected]>
  • Loading branch information
mehab committed Oct 19, 2023
1 parent 72a8337 commit 917754e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.google.api.expr.v1alpha1.Type;
import com.google.protobuf.Timestamp;
import com.google.protobuf.util.Timestamps;
import io.micrometer.core.instrument.Timer;
import org.apache.commons.collections4.MultiValuedMap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ private static Val isComponentOldFunc(Val... vals) {
return Types.boolOf(false);
}

if(!(vals[0].value() instanceof final Component component)){
if (!(vals[0].value() instanceof final Component component)) {
return Err.maybeNoSuchOverloadErr(vals[0]);
}
if(!(vals[1].value() instanceof final String dateValue)){
if (!(vals[1].value() instanceof final String dateValue)) {
return Err.maybeNoSuchOverloadErr(vals[1]);
}
if(!(vals[2].value() instanceof final String comparator)){
if (!(vals[2].value() instanceof final String comparator)) {
return Err.maybeNoSuchOverloadErr(vals[2]);
}
return Types.boolOf(isComponentOld(component, dateValue, comparator));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,13 @@
package org.dependencytrack.policy.cel.compat;

import alpine.common.logging.Logger;
import org.dependencytrack.model.PolicyCondition;

import java.time.Period;
import java.time.format.DateTimeParseException;

public class ComponentAgeCelPolicyScriptSourceBuilder implements CelPolicyScriptSourceBuilder {
private static final Logger LOGGER = Logger.getLogger(ComponentAgeCelPolicyScriptSourceBuilder.class);

@Override
public String apply(PolicyCondition policyCondition) {
final Period agePeriod;
try {
agePeriod = Period.parse(policyCondition.getValue());
} catch (DateTimeParseException e) {
LOGGER.error("Invalid age duration format", e);
return null;
}

if (agePeriod.isZero() || agePeriod.isNegative()) {
LOGGER.warn("Age durations must not be zero or negative");
return null;
}

return """
component.compare_age("%s", "%s")
""".formatted(CelPolicyScriptSourceBuilder.escapeQuotes(agePeriod.toString()), policyCondition.getOperator());
""".formatted(CelPolicyScriptSourceBuilder.escapeQuotes(policyCondition.getValue()), policyCondition.getOperator());
}
}

0 comments on commit 917754e

Please sign in to comment.