use of com.walmartlabs.concord.policyengine.AttachmentsRule in project concord by walmartlabs.
the class ProcessResource method buildErrorMessage.
private String buildErrorMessage(List<CheckResult.Item<AttachmentsRule, Long>> errors) {
String defaultMessage = "Attachments too big: current {0} bytes, limit {1} bytes";
StringBuilder sb = new StringBuilder();
for (CheckResult.Item<AttachmentsRule, Long> e : errors) {
AttachmentsRule r = e.getRule();
String msg = r.getMsg() != null ? r.getMsg() : defaultMessage;
long actualSize = e.getEntity();
long limit = r.getMaxSizeInBytes();
sb.append(MessageFormat.format(msg, actualSize, limit)).append(';');
}
return sb.toString();
}
use of com.walmartlabs.concord.policyengine.AttachmentsRule in project concord by walmartlabs.
the class ProcessResource method assertAttachmentsPolicy.
private void assertAttachmentsPolicy(Path tmpDir, ProcessEntry entry) throws IOException {
PolicyEngine policy = policyManager.get(entry.orgId(), entry.projectId(), UserPrincipal.assertCurrent().getUser().getId());
if (policy == null) {
return;
}
CheckResult<AttachmentsRule, Long> checkResult = policy.getAttachmentsPolicy().check(tmpDir);
if (!checkResult.getDeny().isEmpty()) {
String errorMessage = buildErrorMessage(checkResult.getDeny());
processLogManager.error(new ProcessKey(entry.instanceId(), entry.createdAt()), errorMessage);
throw new PolicyException("Found forbidden policy: " + errorMessage);
}
}
Aggregations