Search in sources :

Example 1 with RawPayloadMode

use of com.walmartlabs.concord.server.jooq.enums.RawPayloadMode 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 2 with RawPayloadMode

use of com.walmartlabs.concord.server.jooq.enums.RawPayloadMode 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 RawPayloadMode

use of com.walmartlabs.concord.server.jooq.enums.RawPayloadMode in project concord by walmartlabs.

the class ProjectDao method get.

public ProjectEntry get(DSLContext tx, UUID projectId) {
    Projects p = PROJECTS.as("p");
    Users u = USERS.as("u");
    Field<String> orgNameField = select(ORGANIZATIONS.ORG_NAME).from(ORGANIZATIONS).where(ORGANIZATIONS.ORG_ID.eq(p.ORG_ID)).asField();
    Record15<UUID, String, String, UUID, String, JSONB, String, UUID, String, String, String, String, RawPayloadMode, JSONB, OutVariablesMode> r = tx.select(p.PROJECT_ID, p.PROJECT_NAME, p.DESCRIPTION, p.ORG_ID, orgNameField, p.PROJECT_CFG, p.VISIBILITY, p.OWNER_ID, u.USERNAME, u.DOMAIN, u.USER_TYPE, u.DISPLAY_NAME, p.RAW_PAYLOAD_MODE, p.META, p.OUT_VARIABLES_MODE).from(p).leftJoin(u).on(u.USER_ID.eq(p.OWNER_ID)).where(p.PROJECT_ID.eq(projectId)).fetchOne();
    if (r == null) {
        return null;
    }
    Result<Record13<UUID, UUID, String, String, String, String, String, Boolean, JSONB, UUID, String, String, Boolean>> repos = tx.select(REPOSITORIES.REPO_ID, REPOSITORIES.PROJECT_ID, REPOSITORIES.REPO_NAME, REPOSITORIES.REPO_URL, REPOSITORIES.REPO_BRANCH, REPOSITORIES.REPO_COMMIT_ID, REPOSITORIES.REPO_PATH, REPOSITORIES.IS_DISABLED, REPOSITORIES.META, SECRETS.SECRET_ID, SECRETS.SECRET_NAME, SECRETS.STORE_TYPE, REPOSITORIES.IS_TRIGGERS_DISABLED).from(REPOSITORIES).leftOuterJoin(SECRETS).on(SECRETS.SECRET_ID.eq(REPOSITORIES.SECRET_ID)).where(REPOSITORIES.PROJECT_ID.eq(projectId)).fetch();
    Map<String, RepositoryEntry> m = new HashMap<>();
    for (Record13<UUID, UUID, String, String, String, String, String, Boolean, JSONB, UUID, String, String, Boolean> repo : repos) {
        m.put(repo.get(REPOSITORIES.REPO_NAME), new RepositoryEntry(repo.get(REPOSITORIES.REPO_ID), repo.get(REPOSITORIES.PROJECT_ID), repo.get(REPOSITORIES.REPO_NAME), repo.get(REPOSITORIES.REPO_URL), repo.get(REPOSITORIES.REPO_BRANCH), repo.get(REPOSITORIES.REPO_COMMIT_ID), repo.get(REPOSITORIES.REPO_PATH), repo.get(REPOSITORIES.IS_DISABLED), repo.get(SECRETS.SECRET_ID), repo.get(SECRETS.SECRET_NAME), repo.get(SECRETS.STORE_TYPE), objectMapper.fromJSONB(repo.get(REPOSITORIES.META)), repo.get(REPOSITORIES.IS_TRIGGERS_DISABLED)));
    }
    Map<String, Object> cfg = objectMapper.fromJSONB(r.get(p.PROJECT_CFG));
    return new ProjectEntry(projectId, r.get(p.PROJECT_NAME), r.get(p.DESCRIPTION), r.get(p.ORG_ID), r.get(orgNameField), m, cfg, ProjectVisibility.valueOf(r.get(p.VISIBILITY)), toOwner(r.get(p.OWNER_ID), r.get(u.USERNAME), r.get(u.DOMAIN), r.get(u.DISPLAY_NAME), r.get(u.USER_TYPE)), r.get(p.RAW_PAYLOAD_MODE) != RawPayloadMode.DISABLED, r.get(p.RAW_PAYLOAD_MODE), objectMapper.fromJSONB(r.get(p.META)), r.get(p.OUT_VARIABLES_MODE));
}
Also used : OutVariablesMode(com.walmartlabs.concord.server.jooq.enums.OutVariablesMode) Projects(com.walmartlabs.concord.server.jooq.tables.Projects) Users(com.walmartlabs.concord.server.jooq.tables.Users) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Example 4 with RawPayloadMode

use of com.walmartlabs.concord.server.jooq.enums.RawPayloadMode in project concord by walmartlabs.

the class ProjectManager method insert.

private UUID insert(DSLContext tx, UUID orgId, String orgName, ProjectEntry entry) {
    UserEntry owner = getOwner(entry.getOwner(), UserPrincipal.assertCurrent().getUser());
    policyManager.checkEntity(orgId, null, EntityType.PROJECT, EntityAction.CREATE, owner, PolicyUtils.projectToMap(orgId, orgName, entry));
    byte[] encryptedKey = encryptedValueManager.createEncryptedSecretKey();
    RawPayloadMode rawPayloadMode = entry.getRawPayloadMode();
    if (rawPayloadMode == null && entry.getAcceptsRawPayload() != null && entry.getAcceptsRawPayload()) {
        rawPayloadMode = RawPayloadMode.ORG_MEMBERS;
    }
    UUID id = projectDao.insert(tx, orgId, entry.getName(), entry.getDescription(), owner.getId(), entry.getCfg(), entry.getVisibility(), rawPayloadMode, encryptedKey, entry.getMeta(), entry.getOutVariablesMode());
    Map<String, RepositoryEntry> repos = entry.getRepositories();
    if (repos != null) {
        repos.forEach((k, v) -> projectRepositoryManager.insert(tx, orgId, orgName, id, entry.getName(), v, false));
    }
    Map<String, Object> changes = DiffUtils.compare(null, entry);
    addAuditLog(AuditAction.CREATE, orgId, orgName, id, entry.getName(), changes);
    return id;
}
Also used : UserEntry(com.walmartlabs.concord.server.user.UserEntry) AuditObject(com.walmartlabs.concord.server.audit.AuditObject) UUID(java.util.UUID) RawPayloadMode(com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)

Aggregations

RawPayloadMode (com.walmartlabs.concord.server.jooq.enums.RawPayloadMode)4 UUID (java.util.UUID)3 AuditObject (com.walmartlabs.concord.server.audit.AuditObject)2 UserEntry (com.walmartlabs.concord.server.user.UserEntry)2 OutVariablesMode (com.walmartlabs.concord.server.jooq.enums.OutVariablesMode)1 Projects (com.walmartlabs.concord.server.jooq.tables.Projects)1 Users (com.walmartlabs.concord.server.jooq.tables.Users)1 OrganizationEntry (com.walmartlabs.concord.server.org.OrganizationEntry)1 ResourceAccessLevel (com.walmartlabs.concord.server.org.ResourceAccessLevel)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ValidationErrorsException (org.sonatype.siesta.ValidationErrorsException)1