Search in sources :

Example 1 with RepositoryEntry

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

the class RepositoryProcessor method getRepositoryEntry.

private RepositoryEntry getRepositoryEntry(Payload payload) {
    UUID projectId = payload.getHeader(Payload.PROJECT_ID);
    UUID repoId = payload.getHeader(Payload.REPOSITORY_ID);
    if (projectId == null || repoId == null) {
        return null;
    }
    RepositoryEntry repo = repositoryDao.get(projectId, repoId);
    if (repo == null) {
        return null;
    }
    Map<String, Object> cfg = payload.getHeader(Payload.CONFIGURATION);
    if (cfg != null) {
        String commitId = MapUtils.getString(cfg, Constants.Request.REPO_COMMIT_ID, repo.getCommitId());
        String branchOrTag = MapUtils.getString(cfg, Constants.Request.REPO_BRANCH_OR_TAG, commitId == null ? repo.getBranch() : null);
        repo = new RepositoryEntry(repo, branchOrTag, commitId);
    }
    return repo;
}
Also used : RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) UUID(java.util.UUID)

Example 2 with RepositoryEntry

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

the class SecretDaoTest method testOnCascade.

@Test
public void testOnCascade() {
    UUID orgId = OrganizationManager.DEFAULT_ORG_ID;
    String projectName = "project#" + System.currentTimeMillis();
    ProjectDao projectDao = new ProjectDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    UUID projectId = projectDao.insert(orgId, projectName, "test", null, null, null, null, new byte[0], null, null);
    String secretName = "secret#" + System.currentTimeMillis();
    SecretDao secretDao = new SecretDao(getConfiguration());
    UUID secretId = secretDao.insert(orgId, null, secretName, null, SecretType.KEY_PAIR, SecretEncryptedByType.SERVER_KEY, "concord", SecretVisibility.PUBLIC, INSERT);
    secretDao.updateData(secretId, new byte[] { 0, 1, 2 });
    secretDao.update(secretId, secretName, UUID.fromString("4b9d496a-c3a0-4e1b-804c-ac3fccddcb27"), null, new byte[0], null, projectId, orgId);
    String repoName = "repo#" + System.currentTimeMillis();
    RepositoryDao repositoryDao = new RepositoryDao(getConfiguration(), new ConcordObjectMapper(TestObjectMapper.INSTANCE));
    UUID repoId = repositoryDao.insert(projectId, repoName, "n/a", null, null, null, secretId, false, null, false);
    // ---
    secretDao.delete(secretId);
    // ---
    RepositoryEntry r = repositoryDao.get(projectId, repoId);
    assertNotNull(r);
    assertNull(r.getSecretName());
}
Also used : RepositoryDao(com.walmartlabs.concord.server.org.project.RepositoryDao) ConcordObjectMapper(com.walmartlabs.concord.server.ConcordObjectMapper) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) UUID(java.util.UUID) ProjectDao(com.walmartlabs.concord.server.org.project.ProjectDao) SecretDao(com.walmartlabs.concord.server.org.secret.SecretDao) Test(org.junit.jupiter.api.Test) AbstractDaoTest(com.walmartlabs.concord.server.AbstractDaoTest)

Example 3 with RepositoryEntry

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

the class ProcessManager method assertRepositoryDisabled.

private void assertRepositoryDisabled(Payload payload) {
    UUID repoId = payload.getHeader(Payload.REPOSITORY_ID);
    if (repoId == null) {
        return;
    }
    RepositoryEntry repo = repositoryDao.get(repoId);
    if (repo.isDisabled()) {
        throw new ConcordApplicationException("Repository is disabled -> " + repo.getName());
    }
}
Also used : ConcordApplicationException(com.walmartlabs.concord.server.sdk.ConcordApplicationException) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry)

Example 4 with RepositoryEntry

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

the class TriggerV2Resource method list.

/**
 * List process trigger definitions for the specified type.
 */
@GET
@ApiOperation(value = "List trigger definitions", responseContainer = "list", response = TriggerEntry.class)
@Produces(MediaType.APPLICATION_JSON)
public List<TriggerEntry> list(@ApiParam @QueryParam("type") @ConcordKey String type, @ApiParam @QueryParam("orgId") UUID orgId, @ApiParam @QueryParam("orgName") @ConcordKey String orgName, @ApiParam @QueryParam("projectId") UUID projectId, @ApiParam @QueryParam("projectName") @ConcordKey String projectName, @ApiParam @QueryParam("repoId") UUID repoId, @ApiParam @QueryParam("repoName") @ConcordKey String repoName) {
    if (type != null && (type.isEmpty() || type.length() > 128)) {
        throw new ValidationErrorsException("Invalid type value: " + type);
    }
    if (orgId == null && orgName != null) {
        orgId = orgDao.getId(orgName);
        if (orgId == null) {
            throw new ValidationErrorsException("Organization not found: " + orgName);
        }
    }
    if (projectId == null && projectName != null) {
        if (orgId == null) {
            throw new IllegalArgumentException("Organization ID or name is required");
        }
        projectId = projectDao.getId(orgId, projectName);
        if (projectId == null) {
            throw new ValidationErrorsException("Project not found: " + projectName);
        }
    }
    if (repoId == null && repoName != null) {
        ProjectEntry p = assertProject(projectId, ResourceAccessLevel.READER, false);
        if (p == null) {
            throw new IllegalArgumentException("Both organization and project IDs or names are required");
        }
        RepositoryEntry r = assertRepository(p, repoName);
        repoId = r.getId();
    }
    return triggersDao.list(orgId, projectId, repoId, type);
}
Also used : ProjectEntry(com.walmartlabs.concord.server.org.project.ProjectEntry) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) ValidationErrorsException(org.sonatype.siesta.ValidationErrorsException) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 5 with RepositoryEntry

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

the class GithubTriggerEnricher method enrichTriggerConditions.

private Map<String, Object> enrichTriggerConditions(DSLContext tx, UUID repoId, Map<String, Object> conditions) {
    if (conditions.containsKey(GITHUB_ORG_KEY) && conditions.containsKey(GITHUB_REPO_KEY) && conditions.containsKey(REPO_BRANCH_KEY)) {
        return conditions;
    }
    RepositoryEntry repo = repositoryDao.get(tx, repoId);
    GithubRepoInfo githubRepoInfo = GithubUtils.getRepositoryInfo(repo.getUrl());
    if (githubRepoInfo == null) {
        return conditions;
    }
    Map<String, Object> newParams = new HashMap<>(conditions);
    newParams.putIfAbsent(GITHUB_ORG_KEY, githubRepoInfo.owner());
    newParams.putIfAbsent(GITHUB_REPO_KEY, githubRepoInfo.name());
    Object eventType = conditions.get(TYPE_KEY);
    if ((PULL_REQUEST_EVENT.equals(eventType) || PUSH_EVENT.equals(eventType)) && (repo.getBranch() != null)) {
        newParams.putIfAbsent(REPO_BRANCH_KEY, repo.getBranch());
    }
    return newParams;
}
Also used : HashMap(java.util.HashMap) RepositoryEntry(com.walmartlabs.concord.server.org.project.RepositoryEntry) GithubRepoInfo(com.walmartlabs.concord.server.events.github.GithubRepoInfo)

Aggregations

RepositoryEntry (com.walmartlabs.concord.server.org.project.RepositoryEntry)6 UUID (java.util.UUID)3 FetchResult (com.walmartlabs.concord.repository.FetchResult)1 Repository (com.walmartlabs.concord.repository.Repository)1 Snapshot (com.walmartlabs.concord.repository.Snapshot)1 AbstractDaoTest (com.walmartlabs.concord.server.AbstractDaoTest)1 ConcordObjectMapper (com.walmartlabs.concord.server.ConcordObjectMapper)1 GithubRepoInfo (com.walmartlabs.concord.server.events.github.GithubRepoInfo)1 ProjectDao (com.walmartlabs.concord.server.org.project.ProjectDao)1 ProjectEntry (com.walmartlabs.concord.server.org.project.ProjectEntry)1 RepositoryDao (com.walmartlabs.concord.server.org.project.RepositoryDao)1 SecretDao (com.walmartlabs.concord.server.org.secret.SecretDao)1 Payload (com.walmartlabs.concord.server.process.Payload)1 ProcessException (com.walmartlabs.concord.server.process.ProcessException)1 ConcordApplicationException (com.walmartlabs.concord.server.sdk.ConcordApplicationException)1 ProcessKey (com.walmartlabs.concord.server.sdk.ProcessKey)1 WithTimer (com.walmartlabs.concord.server.sdk.metrics.WithTimer)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Path (java.nio.file.Path)1 HashMap (java.util.HashMap)1