Search in sources :

Example 1 with ProjectEntry

use of com.walmartlabs.concord.server.org.project.ProjectEntry in project concord by walmartlabs.

the class AuditLogResource method getEffectiveProjectId.

private UUID getEffectiveProjectId(UUID effectiveOrgId, Map<String, String> details) {
    UUID projectId = getUUID(details, "projectId");
    String projectName = details.get("projectName");
    if (effectiveOrgId == null && projectId == null && projectName != null) {
        throw new ValidationErrorsException("'orgId' or 'orgName' is required");
    }
    if (projectId != null || projectName != null) {
        ProjectEntry project = projectAccessManager.assertAccess(effectiveOrgId, projectId, projectName, ResourceAccessLevel.READER, true);
        return project.getId();
    }
    return null;
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) UUID(java.util.UUID) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException)

Example 2 with ProjectEntry

use of com.walmartlabs.concord.server.org.project.ProjectEntry 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 3 with ProjectEntry

use of com.walmartlabs.concord.server.org.project.ProjectEntry in project concord by walmartlabs.

the class ConfigurationProcessor method getProject.

private ProjectEntry getProject(Payload payload) {
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    if (projectId == null) {
        return null;
    }
    ProjectEntry e = projectDao.get(projectId);
    if (e == null) {
        throw new ProcessException(payload.getProcessKey(), "Project not found: " + projectId, Status.BAD_REQUEST);
    }
    return e;
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ProcessException(com.walmartlabs.concord.server.process.ProcessException) UUID(java.util.UUID)

Example 4 with ProjectEntry

use of com.walmartlabs.concord.server.org.project.ProjectEntry in project concord by walmartlabs.

the class ProjectDaoTest method testList.

@Test
public void testList() {
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    assertEquals(0, projectDao.list(null, null, PROJECTS.PROJECT_NAME, true, 0, -1, null).size());
    // ---
    String aName = "aProject#" + System.currentTimeMillis();
    String bName = "bProject#" + System.currentTimeMillis();
    String cName = "cProject#" + System.currentTimeMillis();
    projectDao.insert(orgId, aName, "test", null, null, null, null, new byte[0], null, null);
    projectDao.insert(orgId, bName, "test", null, null, null, null, new byte[0], null, null);
    projectDao.insert(orgId, cName, "test", null, null, null, null, new byte[0], null, null);
    // ---
    List<ProjectEntry> l = projectDao.list(null, null, PROJECTS.PROJECT_NAME, false, 0, -1, null);
    assertEquals(3, l.size());
    ProjectEntry a = l.get(2);
    assertEquals(aName, a.getName());
    ProjectEntry b = l.get(1);
    assertEquals(bName, b.getName());
    ProjectEntry c = l.get(0);
    assertEquals(cName, c.getName());
    // ---
    List<ProjectEntry> l2 = projectDao.list(null, null, PROJECTS.PROJECT_NAME, false, 1, -1, null);
    assertEquals(2, l2.size());
    ProjectEntry a2 = l2.get(1);
    assertEquals(aName, a2.getName());
    ProjectEntry b2 = l2.get(0);
    assertEquals(bName, b2.getName());
    // ---
    List<ProjectEntry> l3 = projectDao.list(null, null, PROJECTS.PROJECT_NAME, false, 0, -1, "cProject");
    assertEquals(1, l3.size());
    ProjectEntry c3 = l3.get(0);
    assertEquals(cName, c3.getName());
    // ---
    List<ProjectEntry> l4 = projectDao.list(null, null, PROJECTS.PROJECT_NAME, false, 0, 1, null);
    assertEquals(1, l4.size());
    ProjectEntry c4 = l4.get(0);
    assertEquals(cName, c4.getName());
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 5 with ProjectEntry

use of com.walmartlabs.concord.server.org.project.ProjectEntry in project concord by walmartlabs.

the class ConsoleService method testRepository.

@POST
@Path("/repository/test")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@WithTimer
public boolean testRepository(RepositoryTestRequest req) {
    OrganizationEntry org = orgManager.assertAccess(null, req.getOrgName(), false);
    ProjectEntry project = projectAccessManager.assertAccess(org.getId(), null, req.getProjectName(), ResourceAccessLevel.READER, false);
    try {
        String secretName = secretDao.getName(req.getSecretId());
        repositoryManager.testConnection(project.getOrgId(), project.getId(), req.getUrl(), req.getBranch(), req.getCommitId(), req.getPath(), secretName);
        return true;
    } catch (InvalidRepositoryPathException e) {
        Map<String, String> m = new HashMap<>();
        m.put("message", "Repository validation error");
        m.put("level", "WARN");
        m.put("details", e.getMessage());
        throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).entity(m).build());
    } catch (Exception e) {
        String msg;
        Throwable t = e;
        while (true) {
            msg = t.getMessage();
            t = t.getCause();
            if (t == null) {
                break;
            }
        }
        if (msg == null) {
            msg = "Repository test error";
        }
        throw new ConcordApplicationException(Response.status(Status.INTERNAL_SERVER_ERROR).header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN).entity(msg).build());
    }
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) InvalidRepositoryPathException(com.walmartlabs.concord.server.repository.InvalidRepositoryPathException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) UnauthorizedException(org.apache.shiro.authz.UnauthorizedException) InvalidRepositoryPathException(com.walmartlabs.concord.server.repository.InvalidRepositoryPathException) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) WithTimer(com.walmartlabs.concord.server.sdk.metrics.WithTimer)

Aggregations

ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)11 UUID (java.util.UUID)7 ProcessException (com.walmartlabs.concord.server.process.ProcessException)3 Test (org.junit.jupiter.api.Test)3 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)3 Payload (com.walmartlabs.concord.server.process.Payload)2 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)2 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 PolicyEngine (com.walmartlabs.concord.policyengine.PolicyEngine)1 PolicyEngineRules (com.walmartlabs.concord.policyengine.PolicyEngineRules)1 AbstractDaoTest (com.walmartlabs.concord.server.AbstractDaoTest)1 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 OutVariablesMode (com.walmartlabs.concord.server.jooq.enums.OutVariablesMode)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)1 RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)1 InvalidRepositoryPathException (com.walmartlabs.concord.server.repository.InvalidRepositoryPathException)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1