Search in sources :

Example 61 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class FilePolicyApplier method apply.

@Override
public void apply(Payload payload, PolicyEngine policy) throws Exception {
    ProcessKey processKey = payload.getProcessKey();
    Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
    CheckResult<FileRule, Path> result = policy.getFilePolicy().check(workDir);
    result.getWarn().forEach(i -> {
        policyWarn.inc();
        logManager.warn(processKey, "Potentially restricted file '{}' (file policy: {})", workDir.relativize(i.getEntity()), i.getRule());
    });
    result.getDeny().forEach(i -> {
        policyDeny.inc();
        logManager.error(processKey, "File '{}' is forbidden by the file policy {}", workDir.relativize(i.getEntity()), i.getRule());
    });
    if (!result.getDeny().isEmpty()) {
        throw new ProcessException(processKey, "Found forbidden files");
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) FileRule(com.walmartlabs.concord.policyengine.FileRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 62 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class ProcessTimeoutPolicyApplier method apply.

@Override
public void apply(Payload payload, PolicyEngine policy) {
    ProcessKey processKey = payload.getProcessKey();
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    if (cfg == null) {
        return;
    }
    Object processTimeout = cfg.get(Constants.Request.PROCESS_TIMEOUT);
    if (processTimeout == null) {
        return;
    }
    CheckResult<ProcessTimeoutRule, Object> result = policy.getProcessTimeoutPolicy().check(processTimeout);
    result.getDeny().forEach(i -> {
        policyDeny.inc();
        String msg = i.getRule().getMsg() != null ? i.getRule().getMsg() : DEFAULT_PROCESS_TIMEOUT_MSG;
        Object actualTimeout = i.getEntity();
        String limit = i.getRule().getMax();
        logManager.error(processKey, MessageFormat.format(msg, actualTimeout, limit));
    });
    if (!result.getDeny().isEmpty()) {
        throw new ProcessException(processKey, "'processTimeout' value policy violation");
    }
}
Also used : ProcessException(com.walmartlabs.concord.server.process.ProcessException) ProcessTimeoutRule(com.walmartlabs.concord.policyengine.ProcessTimeoutRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 63 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class WorkspacePolicyApplier method apply.

@Override
public void apply(Payload payload, PolicyEngine policy) throws Exception {
    ProcessKey processKey = payload.getProcessKey();
    Path workDir = payload.getHeader(Payload.WORKSPACE_DIR);
    CheckResult<WorkspaceRule, Path> result = policy.getWorkspacePolicy().check(workDir);
    result.getWarn().forEach(i -> {
        policyWarn.inc();
        logManager.warn(processKey, appendMsg("Potential workspace policy violation (policy: {})", i.getMsg()), i.getRule());
    });
    result.getDeny().forEach(i -> {
        policyDeny.inc();
        logManager.error(processKey, appendMsg("Workspace policy violation", i.getMsg()), i.getRule());
    });
    if (!result.getDeny().isEmpty()) {
        throw new ProcessException(processKey, "Found workspace policy violations");
    }
}
Also used : Path(java.nio.file.Path) ProcessException(com.walmartlabs.concord.server.process.ProcessException) WorkspaceRule(com.walmartlabs.concord.policyengine.WorkspaceRule) ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Example 64 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class DependencyVersionsExportProcessor method process.

@Override
public Payload process(Chain chain, Payload payload) {
    ProcessKey processKey = payload.getProcessKey();
    if (cfg.getPath() == null) {
        return chain.process(payload);
    }
    logManager.info(processKey, "Storing default dependency versions...");
    Path ws = payload.getHeader(Payload.WORKSPACE_DIR);
    try {
        Path dst = Files.createDirectories(ws.resolve(Constants.Files.CONCORD_SYSTEM_DIR_NAME));
        IOUtils.copy(cfg.getPath(), dst.resolve(Constants.Files.DEPENDENCY_VERSIONS_FILE_NAME), StandardCopyOption.REPLACE_EXISTING);
    } catch (IOException e) {
        logManager.error(processKey, "Error while storing dependency versions: {}", e);
        throw new ProcessException(processKey, "Error while storing dependency versions: " + e.getMessage(), e);
    }
    return chain.process(payload);
}
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 65 with ProcessKey

use of com.walmartlabs.concord.server.sdk.ProcessKey in project concord by walmartlabs.

the class FailProcessor method process.

@Override
public void process(Payload payload, Exception e) {
    ProcessKey processKey = payload.getProcessKey();
    boolean hasQueueRecord = queueDao.exists(processKey);
    if (!hasQueueRecord) {
        // the process failed before we had a chance to create the initial queue record
        return;
    }
    logManager.error(processKey, "Process failed: {}", e.getMessage());
    if (!(e instanceof InvalidProcessStateException)) {
        queueManager.updateStatus(processKey, ProcessStatus.FAILED);
    }
}
Also used : ProcessKey(com.walmartlabs.concord.server.sdk.ProcessKey)

Aggregations

ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)69 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)28 Path (java.nio.file.Path)27 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)25 ApiOperation (io.swagger.annotations.ApiOperation)22 ProcessException (com.walmartlabs.concord.server.process.ProcessException)20 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)16 IOException (java.io.IOException)16 UUID (java.util.UUID)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)8 Inject (javax.inject.Inject)8 Named (javax.inject.Named)8 ProcessKeyCache (com.walmartlabs.concord.server.process.queue.ProcessKeyCache)7 ProcessQueueDao (com.walmartlabs.concord.server.process.queue.ProcessQueueDao)7 ProcessStateManager (com.walmartlabs.concord.server.process.state.ProcessStateManager)7 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)7 ProcessLogManager (com.walmartlabs.concord.server.process.logs.ProcessLogManager)6 HttpUtils (com.walmartlabs.concord.server.HttpUtils)5 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)5