Search in sources :

Example 1 with ProcessException

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;
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException)

Example 2 with ProcessException

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);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) KeyPair(com.walmartlabs.concord.common.secret.KeyPair) Collection(java.util.Collection) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) UUID(java.util.UUID) Map(java.util.Map)

Example 3 with ProcessException

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);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) PolicyEngine(com.walmartlabs.concord.policyengine.PolicyEngine) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey) IOException(java.io.IOException) UUID(java.util.UUID)

Example 4 with ProcessException

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);
    }
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ProcessException(com.walmartlabs.concord.server.process.ProcessException) UUID(java.util.UUID) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Example 5 with ProcessException

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);
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) IOException(java.io.IOException) UUID(java.util.UUID) Map(java.util.Map)

Aggregations

ProcessException (com.walmartlabs.concord.server.process.ProcessException)31 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)20 Path (java.nio.file.Path)19 IOException (java.io.IOException)18 UUID (java.util.UUID)9 InputStream (java.io.InputStream)4 Map (java.util.Map)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)3 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)3 ProcessDefinition (com.walmartlabs.concord.process.loader.model.ProcessDefinition)2 Snapshot (com.walmartlabs.concord.repository.Snapshot)2 Payload (com.walmartlabs.concord.server.process.Payload)2 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)2 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)2 UserInfo (com.walmartlabs.concord.server.user.UserInfoProvider.UserInfo)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 ConfigurationUtils (com.walmartlabs.concord.common.ConfigurationUtils)1 CycleChecker (com.walmartlabs.concord.common.CycleChecker)1