use of com.walmartlabs.concord.server.sdk.ProcessKey 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.sdk.ProcessKey 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.sdk.ProcessKey in project concord by walmartlabs.
the class PayloadRestoreProcessor method process.
@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> headers = stateManager.get(processKey, "_initial/payload.json", inputStream -> {
Map<String, Object> result = deserialize(inputStream);
return Optional.ofNullable(result);
}).orElseThrow(() -> new ConcordApplicationException("Initial state not found", Response.Status.INTERNAL_SERVER_ERROR));
payload = payload.putHeaders(headers);
Path baseDir = payload.getHeader(Payload.BASE_DIR);
ProcessStateManager.ItemConsumer cp = ProcessStateManager.copyTo(baseDir);
Map<String, Path> attachments = new HashMap<>();
stateManager.exportDirectory(processKey, "_initial/attachments/", (name, unixMode, src) -> {
cp.accept(name, unixMode, src);
attachments.put(name, baseDir.resolve(name));
});
payload = payload.putAttachments(attachments);
return chain.process(payload);
}
use of com.walmartlabs.concord.server.sdk.ProcessKey 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.sdk.ProcessKey in project concord by walmartlabs.
the class EnqueueingProcessor method process.
@Override
@WithTimer
public Payload process(Chain chain, Payload payload) {
boolean enqueued = queueManager.enqueue(payload);
if (!enqueued) {
// (e.g. "exclusive" processes can be rejected before reaching the ENQUEUED status)
return payload;
}
ProcessKey processKey = payload.getProcessKey();
Map<String, Object> requirements = PayloadUtils.getRequirements(payload);
OffsetDateTime startAt = PayloadUtils.getStartAt(payload);
if (startAt == null) {
logManager.info(processKey, "Enqueued. Waiting for an agent (requirements={})...", requirements);
} else {
logManager.info(processKey, "Enqueued. Starting at {} (requirements={})...", startAt, requirements);
}
return chain.process(payload);
}
Aggregations