Search in sources :

Example 6 with ConcordApplicationException

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

the class ProjectManager method get.

public ProjectEntry get(String orgName, String projectName) {
    OrganizationEntry org = orgManager.assertAccess(orgName, false);
    UUID projectId = projectDao.getId(org.getId(), projectName);
    if (projectId == null) {
        throw new ConcordApplicationException("Project not found: " + projectName, Response.Status.NOT_FOUND);
    }
    return get(projectId);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 7 with ConcordApplicationException

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

the class PolicyResource method list.

@GET
@ApiOperation(value = "List policies, optionally filtering by organization, project and/or user links", responseContainer = "list", response = PolicyEntry.class)
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public List<PolicyEntry> list(@ApiParam @QueryParam("orgName") @ConcordKey String orgName, @ApiParam @QueryParam("projectName") @ConcordKey String projectName, @ApiParam @QueryParam("userName") @ConcordKey String userName, @ApiParam @QueryParam("userDomain") String userDomain, @ApiParam @QueryParam("userType") UserType userType) {
    if (orgName == null && projectName == null && userName == null) {
        return policyManager.list();
    }
    UUID orgId = null;
    if (orgName != null) {
        orgId = orgDao.getId(orgName);
        if (orgId == null) {
            throw new ConcordApplicationException("Organization not found: " + orgName, Status.BAD_REQUEST);
        }
    }
    UUID projectId = null;
    if (projectName != null) {
        if (orgId == null) {
            throw new ConcordApplicationException("Organization name is required", Status.BAD_REQUEST);
        }
        projectId = projectDao.getId(orgId, projectName);
        if (projectId == null) {
            throw new ConcordApplicationException("Project not found: " + projectName, Status.BAD_REQUEST);
        }
    }
    UUID userId = null;
    if (userName != null) {
        if (userType == null) {
            userType = UserPrincipal.assertCurrent().getType();
        }
        userId = assertUser(userName, userDomain, userType);
    }
    PolicyEntry e = policyManager.getLinked(orgId, projectId, userId);
    if (e == null) {
        return Collections.emptyList();
    }
    // TODO consider returning multiple entries?
    return Collections.singletonList(e);
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) ApiOperation(io.swagger.annotations.ApiOperation)

Example 8 with ConcordApplicationException

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

the class PolicyResource method delete.

@DELETE
@ApiOperation("Delete an existing policy")
@Path("/{policyName}")
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult delete(@ApiParam @PathParam("policyName") @ConcordKey String policyName) {
    assertAdmin();
    UUID id = policyManager.getId(policyName);
    if (id == null) {
        throw new ConcordApplicationException("Policy not found: " + policyName, Status.NOT_FOUND);
    }
    policyManager.delete(id);
    auditLog.add(AuditObject.POLICY, AuditAction.DELETE).field("policyId", id).field("name", policyName).log();
    return new GenericOperationResult(OperationResult.DELETED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) ApiOperation(io.swagger.annotations.ApiOperation)

Example 9 with ConcordApplicationException

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

the class RepositoryResource method validateRepository.

/**
 * Validate a repository.
 */
@POST
@ApiOperation("Validate an existing repository")
@Path("/{orgName}/project/{projectName}/repository/{repositoryName}/validate")
@Produces(MediaType.APPLICATION_JSON)
public RepositoryValidationResponse validateRepository(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("projectName") @ConcordKey String projectName, @ApiParam @PathParam("repositoryName") @ConcordKey String repositoryName) {
    UUID orgId = orgManager.assertAccess(orgName, true).getId();
    UUID projectId = projectDao.getId(orgId, projectName);
    if (projectId == null) {
        throw new ConcordApplicationException("Project not found: " + projectName, Status.NOT_FOUND);
    }
    accessManager.assertAccess(projectId, ResourceAccessLevel.READER, true);
    UUID repoId = repositoryDao.getId(projectId, repositoryName);
    if (repoId == null) {
        throw new ConcordApplicationException("Repository not found: " + repositoryName, Status.NOT_FOUND);
    }
    ProjectValidator.Result result = projectRepositoryManager.validateRepository(projectId, repositoryDao.get(projectId, repoId));
    return new RepositoryValidationResponse(result.isValid(), OperationResult.VALIDATED, result.getErrors(), result.getWarnings());
}
Also used : RepositoryValidationResponse(com.walmartlabs.concord.server.repository.RepositoryValidationResponse) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with ConcordApplicationException

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

the class RepositoryResource method delete.

@DELETE
@ApiOperation("Delete an existing repository")
@Path("/{orgName}/project/{projectName}/repository/{repositoryName}")
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult delete(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("projectName") @ConcordKey String projectName, @ApiParam @PathParam("repositoryName") @ConcordKey String repositoryName) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID projectId = projectDao.getId(org.getId(), projectName);
    if (projectId == null) {
        throw new ConcordApplicationException("Project not found: " + projectName, Status.NOT_FOUND);
    }
    projectRepositoryManager.delete(projectId, repositoryName);
    return new GenericOperationResult(OperationResult.DELETED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)70 ApiOperation (io.swagger.annotations.ApiOperation)28 UUID (java.util.UUID)22 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)21 PartialProcessKey (com.walmartlabs.concord.server.sdk.PartialProcessKey)18 IOException (java.io.IOException)14 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)12 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)11 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)11 Validate (org.sonatype.siesta.Validate)11 Path (java.nio.file.Path)10 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)9 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)8 EntryPoint (com.walmartlabs.concord.server.process.PayloadManager.EntryPoint)6 ProcessStatus (com.walmartlabs.concord.server.sdk.ProcessStatus)6 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 UserEntry (com.walmartlabs.concord.server.user.UserEntry)5 InputStream (java.io.InputStream)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Form (com.walmartlabs.concord.forms.Form)3