Search in sources :

Example 1 with OrganizationEntry

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

the class AuditLogResource method getEffectiveOrgId.

private UUID getEffectiveOrgId(Map<String, String> details) {
    UUID orgId = getUUID(details, "orgId");
    String orgName = details.get("orgName");
    if (orgId != null || orgName != null) {
        OrganizationEntry org = orgManager.assertAccess(orgId, orgName, true);
        return org.getId();
    }
    return null;
}
Also used : UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 2 with OrganizationEntry

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

the class ProjectManager method update.

private void update(DSLContext tx, UUID projectId, ProjectEntry entry) {
    ProjectEntry e = projectDao.get(projectId);
    if (e == null) {
        throw new ValidationErrorsException("Project not found: " + projectId);
    }
    UserEntry owner = getOwner(entry.getOwner(), null);
    policyManager.checkEntity(e.getOrgId(), projectId, EntityType.PROJECT, EntityAction.UPDATE, owner, PolicyUtils.projectToMap(e.getOrgId(), e.getOrgName(), entry));
    UUID currentOwnerId = e.getOwner() != null ? e.getOwner().id() : null;
    UUID updatedOwnerId = owner != null ? owner.getId() : null;
    ResourceAccessLevel level = ResourceAccessLevel.WRITER;
    if (updatedOwnerId != null && !updatedOwnerId.equals(currentOwnerId)) {
        level = ResourceAccessLevel.OWNER;
    }
    ProjectEntry prevEntry = accessManager.assertAccess(projectId, level, true);
    UUID orgId = prevEntry.getOrgId();
    OrganizationEntry organizationEntry = null;
    if (entry.getOrgId() != null) {
        organizationEntry = orgManager.assertAccess(entry.getOrgId(), true);
    } else if (entry.getOrgName() != null) {
        organizationEntry = orgManager.assertAccess(entry.getOrgName(), true);
    }
    UUID orgIdUpdate = organizationEntry != null ? organizationEntry.getId() : orgId;
    RawPayloadMode rawPayloadMode = entry.getRawPayloadMode();
    if (rawPayloadMode == null && entry.getAcceptsRawPayload() != null && entry.getAcceptsRawPayload()) {
        rawPayloadMode = RawPayloadMode.ORG_MEMBERS;
    }
    if (!orgIdUpdate.equals(orgId)) {
        secretDao.updateProjectScopeByProjectId(tx, orgId, projectId, null);
        repositoryDao.clearSecretMappingByProjectId(tx, projectId);
    }
    projectDao.update(tx, orgIdUpdate, projectId, entry.getVisibility(), entry.getName(), entry.getDescription(), entry.getCfg(), rawPayloadMode, updatedOwnerId, entry.getMeta(), entry.getOutVariablesMode());
    Map<String, RepositoryEntry> repos = entry.getRepositories();
    if (repos != null) {
        repositoryDao.deleteAll(tx, projectId);
        repos.forEach((k, v) -> projectRepositoryManager.insert(tx, orgId, prevEntry.getOrgName(), projectId, prevEntry.getName(), v, false));
    }
    ProjectEntry newEntry = projectDao.get(tx, projectId);
    Map<String, Object> changes = DiffUtils.compare(prevEntry, newEntry);
    addAuditLog(AuditAction.UPDATE, prevEntry.getOrgId(), prevEntry.getOrgName(), prevEntry.getId(), prevEntry.getName(), changes);
}
Also used : ResourceAccessLevel(com.walmartlabs.concord.server.org.ResourceAccessLevel) UserEntry(com.walmartlabs.concord.server.user.UserEntry) AuditObject(com.walmartlabs.concord.server.audit.AuditObject) UUID(java.util.UUID) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Example 3 with OrganizationEntry

use of com.walmartlabs.concord.server.org.OrganizationEntry 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 4 with OrganizationEntry

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

the class ProjectManager method createOrGet.

public ProjectOperationResult createOrGet(DSLContext tx, UUID orgId, ProjectEntry entry) {
    entry = normalize(entry);
    OrganizationEntry org = orgManager.assertAccess(tx, orgId, true);
    UUID projectId = projectDao.getId(tx, org.getId(), entry.getName());
    if (projectId == null) {
        projectId = insert(tx, org.getId(), org.getName(), entry);
        return ProjectOperationResult.builder().result(OperationResult.CREATED).projectId(projectId).build();
    }
    return ProjectOperationResult.builder().result(OperationResult.ALREADY_EXISTS).projectId(projectId).build();
}
Also used : UUID(java.util.UUID) OrganizationEntry(com.walmartlabs.concord.server.org.OrganizationEntry)

Example 5 with OrganizationEntry

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

OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)36 ApiOperation (io.swagger.annotations.ApiOperation)12 UUID (java.util.UUID)12 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)8 UnauthorizedException (org.apache.shiro.authz.UnauthorizedException)6 GenericOperationResult (com.walmartlabs.concord.server.GenericOperationResult)5 JsonStoreEntry (com.walmartlabs.concord.server.org.jsonstore.JsonStoreEntry)5 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)5 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)3 UserPrincipal (com.walmartlabs.concord.server.security.UserPrincipal)3 Validate (org.sonatype.siesta.Validate)3 Map (java.util.Map)2 OperationResult (com.walmartlabs.concord.server.OperationResult)1 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)1 RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 MetadataFilter (com.walmartlabs.concord.server.process.queue.ProcessFilter.MetadataFilter)1 InvalidRepositoryPathException (com.walmartlabs.concord.server.repository.InvalidRepositoryPathException)1 UserEntry (com.walmartlabs.concord.server.user.UserEntry)1