use of com.walmartlabs.concord.policyengine.ContainerRule in project concord by walmartlabs.
the class ContainerPolicyApplier method apply.
@Override
@SuppressWarnings("unchecked")
public void apply(Payload payload, PolicyEngine policy) {
ProcessKey processKey = payload.getProcessKey();
Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
Path p = workDir.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
if (!Files.exists(p)) {
return;
}
Map<String, Object> containerOptions;
try (InputStream in = Files.newInputStream(p)) {
Map<String, Object> m = objectMapper.readValue(in, Map.class);
containerOptions = (Map<String, Object>) m.get(Constants.Request.CONTAINER);
} catch (IOException e) {
logManager.error(processKey, "Error while reading container configuration: {}", e);
throw new ProcessException(processKey, "Error while reading container configuration", e);
}
CheckResult<ContainerRule, Object> result = policy.getContainerPolicy().check(containerOptions);
result.getWarn().forEach(i -> {
policyWarn.inc();
logManager.warn(processKey, appendMsg("Potential container policy violation (policy: {})", i.getMsg()), i.getRule());
});
result.getDeny().forEach(i -> {
policyDeny.inc();
logManager.error(processKey, appendMsg("Container policy violation", i.getMsg()), i.getRule());
});
if (!result.getDeny().isEmpty()) {
throw new ProcessException(processKey, "Found container policy violations");
}
}
Aggregations