use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class TemplateFilesProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
Object s = cfg.get(Constants.Request.TEMPLATE_KEY);
if (!(s instanceof String)) {
return chain.process(payload);
}
try {
URI uri = getUri(processKey, (String) s);
Path template = dependencyManager.resolveSingle(uri).getPath();
extract(payload, template);
return chain.process(payload);
} catch (URISyntaxException | IOException e) {
logManager.error(processKey, "Template error: " + s, e);
throw new ProcessException(processKey, "Error while processing a template: " + s, e);
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class TemplateScriptProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
// process _main.js
Path scriptPath = workspace.resolve(REQUEST_DATA_TEMPLATE_FILE_NAME);
if (!Files.exists(scriptPath)) {
return chain.process(payload);
}
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> in = payload.getHeader(Payload.CONFIGURATION);
Map<String, Object> out = processScript(processKey, in, scriptPath);
Map<String, Object> merged = ConfigurationUtils.deepMerge(in, out);
CycleChecker.CheckResult result = CycleChecker.check(INPUT_REQUEST_DATA_KEY, merged);
if (result.isHasCycle()) {
throw new ProcessException(processKey, "Found cycle in " + REQUEST_DATA_TEMPLATE_FILE_NAME + ": " + result.getNode1() + " <-> " + result.getNode2());
}
payload = payload.putHeader(Payload.CONFIGURATION, merged);
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey 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");
}
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class ConfigurationStoringProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
if (cfg == null) {
return chain.process(payload);
}
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
Path dst = workspace.resolve(Constants.Files.CONFIGURATION_FILE_NAME);
try (OutputStream out = Files.newOutputStream(dst)) {
ObjectMapper om = new ObjectMapper();
om.writeValue(out, cfg);
} catch (IOException e) {
logManager.error(processKey, "Error while saving a metadata file: " + dst, e);
throw new ProcessException(processKey, "Error while saving a metadata file: " + dst, e);
}
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.
the class DependenciesProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
// get a list of dependencies from the cfg data
Collection<String> deps = deps(processKey, cfg);
if (deps == null) {
return chain.process(payload);
}
boolean failed = false;
for (String d : deps) {
try {
new URI(d);
} catch (URISyntaxException e) {
logManager.error(processKey, "Invalid dependency URL: " + d);
failed = true;
}
}
if (failed) {
throw new ProcessException(processKey, "Invalid dependency list");
}
cfg.put(Constants.Request.DEPENDENCIES_KEY, deps);
payload = payload.putHeader(Payload.CONFIGURATION, cfg);
return chain.process(payload);
}
Aggregations