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;
}
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);
}
}
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;
}
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());
}
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());
}
}
Aggregations