use of com.walmartlabs.concord.policyengine.FileRule in project concord by walmartlabs.
the class FilePolicyApplier method apply.
@Override
public void apply(Payload payload, PolicyEngine policy) throws Exception {
ProcessKey processKey = payload.getProcessKey();
Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
CheckResult<FileRule, Path> result = policy.getFilePolicy().check(workDir);
result.getWarn().forEach(i -> {
policyWarn.inc();
logManager.warn(processKey, "Potentially restricted file '{}' (file policy: {})", workDir.relativize(i.getEntity()), i.getRule());
});
result.getDeny().forEach(i -> {
policyDeny.inc();
logManager.error(processKey, "File '{}' is forbidden by the file policy {}", workDir.relativize(i.getEntity()), i.getRule());
});
if (!result.getDeny().isEmpty()) {
throw new ProcessException(processKey, "Found forbidden files");
}
}
Aggregations