Search in sources :

Example 1 with GenericOperationResult

use of com.walmartlabs.concord.server.GenericOperationResult in project concord by walmartlabs.

the class SecretResource method updateAccessLevel.

@POST
@ApiOperation("Updates the access level for the specified secret and team")
@Path("/{orgName}/secret/{secretName}/access/bulk")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public GenericOperationResult updateAccessLevel(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("secretName") @ConcordKey String secretName, @ApiParam @Valid Collection<ResourceAccessEntry> entries) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID secretId = secretDao.getId(org.getId(), secretName);
    if (secretId == null) {
        throw new ConcordApplicationException("Secret not found: " + secretName, Status.NOT_FOUND);
    }
    if (entries == null) {
        throw new ConcordApplicationException("List of teams is null.", Status.BAD_REQUEST);
    }
    secretManager.updateAccessLevel(secretId, entries, true);
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate)

Example 2 with GenericOperationResult

use of com.walmartlabs.concord.server.GenericOperationResult in project concord by walmartlabs.

the class SecretResource method updateAccessLevel.

@POST
@ApiOperation("Updates the access level for the specified secret and team")
@Path("/{orgName}/secret/{secretName}/access")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@Validate
public GenericOperationResult updateAccessLevel(@ApiParam @PathParam("orgName") @ConcordKey String orgName, @ApiParam @PathParam("secretName") @ConcordKey String secretName, @ApiParam @Valid ResourceAccessEntry entry) {
    OrganizationEntry org = orgManager.assertAccess(orgName, true);
    UUID secretId = secretDao.getId(org.getId(), secretName);
    if (secretId == null) {
        throw new ConcordApplicationException("Secret not found: " + secretName, Status.NOT_FOUND);
    }
    UUID teamId = ResourceAccessUtils.getTeamId(orgDao, teamDao, org.getId(), entry);
    secretManager.updateAccessLevel(secretId, teamId, entry.getLevel());
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) UUID(java.util.UUID) Validate(org.sonatype.siesta.Validate)

Example 3 with GenericOperationResult

use of com.walmartlabs.concord.server.GenericOperationResult in project concord by walmartlabs.

the class PolicyResource method link.

@PUT
@ApiOperation("Link an existing policy to an organization, a project or user")
@Path("/{policyName}/link")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public GenericOperationResult link(@ApiParam @PathParam("policyName") @ConcordKey String policyName, @ApiParam @Valid PolicyLinkEntry entry) {
    assertAdmin();
    // TODO: add user type into request
    UserType userType = UserPrincipal.assertCurrent().getType();
    PolicyLink l = assertLink(policyName, entry.getOrgName(), entry.getProjectName(), entry.getUserName(), entry.getUserDomain(), userType);
    policyManager.link(l.policyId, l.orgId, l.projectId, l.userId);
    auditLog.add(AuditObject.POLICY, AuditAction.UPDATE).field("policyId", l.policyId).field("name", policyName).field("link", l).field("action", "link").log();
    return new GenericOperationResult(OperationResult.UPDATED);
}
Also used : GenericOperationResult(com.walmartlabs.concord.server.GenericOperationResult) UserType(com.walmartlabs.concord.server.user.UserType) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with GenericOperationResult

use of com.walmartlabs.concord.server.GenericOperationResult 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 5 with GenericOperationResult

use of com.walmartlabs.concord.server.GenericOperationResult 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

GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)13 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)10 ApiOperation (io.swagger.annotations.ApiOperation)10 UUID (java.util.UUID)10 Validate (org.sonatype.siesta.Validate)7 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)4 IOException (java.io.IOException)2 UserInfoProvider (com.walmartlabs.concord.server.user.UserInfoProvider)1 UserType (com.walmartlabs.concord.server.user.UserType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1