use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class InventoryProcessor method copy.
private boolean copy(Payload payload, AttachmentKey src, String dstName) {
ProcessKey processKey = payload.getProcessKey();
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
Path p = payload.getAttachment(src);
if (p == null) {
return false;
}
Path dst = workspace.resolve(dstName);
try {
Files.copy(p, dst);
} catch (IOException e) {
logManager.error(processKey, "Error while copying an inventory file: " + p, e);
throw new ProcessException(processKey, "Error while copying an inventory file: " + p, e);
}
return true;
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class PrivateKeyProcessor method process.
@Override
@SuppressWarnings("unchecked")
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
Map<String, Object> ansibleCfg = (Map<String, Object>) cfg.get(AnsibleConfigurationConstants.GROUP_KEY);
if (ansibleCfg == null) {
return chain.process(payload);
}
Collection<Map<String, Object>> keys = (Collection<Map<String, Object>>) ansibleCfg.get(AnsibleConfigurationConstants.PRIVATE_KEYS);
if (keys == null) {
return chain.process(payload);
}
deprecationWarning(processKey);
String secret = findMatchingSecret(payload, keys);
if (secret == null) {
logManager.error(processKey, "No matching secrets found");
throw new ProcessException(processKey, "No matching secrets found");
}
UUID orgId = getOrgId(payload);
KeyPair keyPair = secretManager.getKeyPair(SecretManager.AccessScope.internal(), orgId, secret, null);
if (keyPair == null) {
logManager.error(processKey, "Secret not found: " + secret);
throw new ProcessException(processKey, "Secret not found: " + secret);
}
if (keyPair.getPrivateKey() == null) {
logManager.error(processKey, "Private key not found: " + secret);
throw new ProcessException(processKey, "Private key not found: " + secret);
}
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
Path dst = workspace.resolve(PRIVATE_KEY_FILE_NAME);
try {
Files.write(dst, keyPair.getPrivateKey(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} catch (IOException e) {
logManager.error(processKey, "Error while copying a private key: " + dst, e);
throw new ProcessException(processKey, "Error while copying a private key: " + dst, e);
}
log.info("process ['{}'] -> done", processKey);
return chain.process(payload);
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class PolicyExportProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
UUID orgId = payload.getHeader(Payload.ORGANIZATION_ID);
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
UUID userId = payload.getHeader(Payload.INITIATOR_ID);
PolicyEngine policy = policyManager.get(orgId, projectId, userId);
if (policy == null) {
return chain.process(payload);
}
logManager.info(processKey, "Storing policy '{}' data", policy.policyNames());
Path ws = payload.getHeader(Payload.WORKSPACE_DIR);
try {
Path dst = Files.createDirectories(ws.resolve(Constants.Files.CONCORD_SYSTEM_DIR_NAME));
objectMapper.writeValue(dst.resolve(Constants.Files.POLICY_FILE_NAME).toFile(), policy.getRules());
} catch (IOException e) {
logManager.error(processKey, "Error while storing process policy: {}", e);
throw new ProcessException(processKey, "Storing process policy error", e);
}
payload = payload.putHeader(Payload.POLICY, policy);
return chain.process(payload);
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class AssertWorkspaceArchiveProcessor method isRawPayloadAllowed.
private boolean isRawPayloadAllowed(Payload payload) {
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
if (projectId == null) {
return true;
}
ProjectEntry p = projectDao.get(projectId);
if (p == null) {
throw new ProcessException(payload.getProcessKey(), "Project not found: " + projectId);
}
RawPayloadMode m = p.getRawPayloadMode();
switch(m) {
case DISABLED:
{
return false;
}
case OWNERS:
{
return projectAccessManager.hasAccess(p, ResourceAccessLevel.OWNER, false);
}
case TEAM_MEMBERS:
{
return projectAccessManager.isTeamMember(p.getId());
}
case ORG_MEMBERS:
{
return userManager.isInOrganization(p.getOrgId());
}
case EVERYONE:
{
return true;
}
default:
throw new IllegalArgumentException("Unsupported raw payload mode: " + m);
}
}
use of com.walmartlabs.concord.server.process.ProcessException in project concord by walmartlabs.
the class AttachmentStoringProcessor method process.
@Override
public Payload process(Chain chain, Payload payload) {
Map<String, Path> m = payload.getAttachments();
if (m == null || m.isEmpty()) {
return chain.process(payload);
}
Path workspace = payload.getHeader(Payload.WORKSPACE_DIR);
for (Map.Entry<String, Path> entry : m.entrySet()) {
String name = entry.getKey();
if (SYSTEM_ATTACHMENT_NAMES.contains(name)) {
continue;
}
UUID projectId = payload.getHeader(Payload.PROJECT_ID);
if (hasRawPayload(name) && !canAcceptRawPayload(projectId)) {
throw new ProcessException(payload.getProcessKey(), "Project is not accepting flows in attachments (" + name + "). Check the \"Allow payload archives\" setting.");
}
Path src = entry.getValue();
Path dst = workspace.resolve(name);
try {
Files.createDirectories(dst.getParent());
Files.move(src, dst, StandardCopyOption.REPLACE_EXISTING);
payload = payload.removeAttachment(name);
} catch (IOException e) {
throw new ProcessException(payload.getProcessKey(), "Error while copying an attachment: " + src, e);
}
}
return chain.process(payload);
}
Aggregations