Search in sources :

Example 51 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolManager method clearToolScan.

/**
 * Deletes all previously found tool vulnerabilities and packages
 */
@Transactional(propagation = Propagation.REQUIRED)
public void clearToolScan(final String registry, final String image, final String version) {
    Tool tool = loadTool(registry, image);
    toolVulnerabilityDao.deleteToolVersionScan(tool.getId(), version);
    toolVulnerabilityDao.deleteDependencies(tool.getId(), version);
    toolVulnerabilityDao.deleteVulnerabilities(tool.getId(), version);
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) Transactional(org.springframework.transaction.annotation.Transactional)

Example 52 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class PipelineDocumentTemplate method getOpenSourceAlgorithmsAndSoftwareTable.

@Placeholder(regex = "Open Source Algorithms and Software", processor = TableTemplateProcessor.class)
public Table getOpenSourceAlgorithmsAndSoftwareTable() {
    Table table = new Table();
    table.setContainsHeaderRow(true);
    table.addColumn("Algorithm or Software");
    table.addColumn("Version");
    Map<String, List<String>> toolsVersions = new HashMap<>();
    for (Tool tool : this.openSourceSoftware) {
        String[] parts = tool.getImage().split("-");
        String toolName = tool.getImage();
        String toolVersion = null;
        if (parts.length >= 2) {
            toolName = parts[0].trim();
            toolVersion = parts[1].trim();
        }
        if (!toolsVersions.containsKey(toolName)) {
            toolsVersions.put(toolName, new ArrayList<>());
        }
        List<String> versions = toolsVersions.get(toolName);
        if (toolVersion != null && !toolVersion.equals("") && versions.indexOf(toolVersion) == -1) {
            versions.add(toolVersion);
            toolsVersions.put(toolName, versions);
        }
    }
    for (String tool : toolsVersions.keySet()) {
        List<String> versions = toolsVersions.get(tool);
        String versionsStr = String.join(", ", versions);
        TableRow row = table.addRow(tool);
        table.setData(row.getIndex(), 0, tool);
        table.setData(row.getIndex(), 1, versionsStr);
    }
    return table;
}
Also used : Table(com.epam.pipeline.manager.pipeline.documents.templates.structure.Table) HashMap(java.util.HashMap) TableRow(com.epam.pipeline.manager.pipeline.documents.templates.structure.TableRow) ArrayList(java.util.ArrayList) List(java.util.List) Tool(com.epam.pipeline.entity.pipeline.Tool) Placeholder(com.epam.pipeline.manager.pipeline.documents.templates.processors.base.Placeholder)

Example 53 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class GrantPermissionManager method commitPermission.

/**
 * Method will check permission for a {@link Tool} if it is registered, or for {@link ToolGroup}
 * if this is a new {@link Tool}. If both {@link Tool} and {@link ToolGroup} do not exist,
 * permission for {@link DockerRegistry} will be checked. Image is expected in format 'group/image'.
 * @param registryId
 * @param image
 * @param permission
 * @return
 */
public boolean commitPermission(Long registryId, String image, String permission) {
    DockerRegistry registry = (DockerRegistry) entityManager.load(AclClass.DOCKER_REGISTRY, registryId);
    try {
        String trimmedImage = image.startsWith(registry.getPath()) ? image.substring(registry.getPath().length() + 1) : image;
        ToolGroup toolGroup = toolGroupManager.loadToolGroupByImage(registry.getPath(), trimmedImage);
        Optional<Tool> tool = toolManager.loadToolInGroup(trimmedImage, toolGroup.getId());
        return tool.map(t -> permissionsHelper.isAllowed(permission, t)).orElseGet(() -> permissionsHelper.isAllowed(permission, toolGroup));
    } catch (IllegalArgumentException e) {
        // case when tool group doesn't exist
        LOGGER.trace(e.getMessage(), e);
        return permissionsHelper.isAllowed(permission, registry);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) EntityEventServiceManager(com.epam.pipeline.manager.event.EntityEventServiceManager) StringUtils(org.apache.commons.lang3.StringUtils) PermissionGrantVO(com.epam.pipeline.controller.vo.PermissionGrantVO) PipelineApiService(com.epam.pipeline.manager.pipeline.PipelineApiService) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ConfigurationProviderManager(com.epam.pipeline.manager.pipeline.runner.ConfigurationProviderManager) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) AclPermission(com.epam.pipeline.security.acl.AclPermission) Map(java.util.Map) MutableAcl(org.springframework.security.acls.model.MutableAcl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) PermissionFactory(org.springframework.security.acls.domain.PermissionFactory) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Set(java.util.Set) Acl(org.springframework.security.acls.model.Acl) EntityWithPermissionVO(com.epam.pipeline.controller.vo.security.EntityWithPermissionVO) Tool(com.epam.pipeline.entity.pipeline.Tool) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AclDataAccessException(org.springframework.security.acls.model.AclDataAccessException) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) AbstractEntityPermissionMapper(com.epam.pipeline.mapper.AbstractEntityPermissionMapper) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RunConfigurationVO(com.epam.pipeline.controller.vo.configuration.RunConfigurationVO) ArrayList(java.util.ArrayList) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) Service(org.springframework.stereotype.Service) SetUtils(org.apache.commons.collections4.SetUtils) EntityManager(com.epam.pipeline.manager.EntityManager) Sid(org.springframework.security.acls.model.Sid) BaseEntity(com.epam.pipeline.entity.BaseEntity) Pair(org.apache.commons.math3.util.Pair) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) EntityPermissionVO(com.epam.pipeline.controller.vo.EntityPermissionVO) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) PipelineWithPermissions(com.epam.pipeline.entity.pipeline.PipelineWithPermissions) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) Folder(com.epam.pipeline.entity.pipeline.Folder) UserContext(com.epam.pipeline.security.UserContext) MessageHelper(com.epam.pipeline.common.MessageHelper) Collectors.toMap(java.util.stream.Collectors.toMap) ListUtils(org.apache.commons.collections4.ListUtils) PipelineWithPermissionsMapper(com.epam.pipeline.mapper.PipelineWithPermissionsMapper) IssueComment(com.epam.pipeline.entity.issue.IssueComment) NodesManager(com.epam.pipeline.manager.cluster.NodesManager) IssueManager(com.epam.pipeline.manager.issue.IssueManager) Collectors.toSet(java.util.stream.Collectors.toSet) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) RepositoryTool(com.epam.pipeline.entity.pipeline.RepositoryTool) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Collection(java.util.Collection) AccessControlEntry(org.springframework.security.acls.model.AccessControlEntry) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Optional(java.util.Optional) Authentication(org.springframework.security.core.Authentication) AclSecuredFilter(com.epam.pipeline.entity.filter.AclSecuredFilter) JdbcMutableAclServiceImpl(com.epam.pipeline.security.acl.JdbcMutableAclServiceImpl) MessageConstants(com.epam.pipeline.common.MessageConstants) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) ToolManager(com.epam.pipeline.manager.pipeline.ToolManager) Permission(org.springframework.security.acls.model.Permission) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Propagation(org.springframework.transaction.annotation.Propagation) Collectors.mapping(java.util.stream.Collectors.mapping) ToolGroupManager(com.epam.pipeline.manager.pipeline.ToolGroupManager) Logger(org.slf4j.Logger) AclSid(com.epam.pipeline.entity.security.acl.AclSid) Collectors.toList(java.util.stream.Collectors.toList) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipelinesWithPermissionsVO(com.epam.pipeline.controller.vo.PipelinesWithPermissionsVO) AccessControlEntryImpl(org.springframework.security.acls.domain.AccessControlEntryImpl) Data(lombok.Data) Issue(com.epam.pipeline.entity.issue.Issue) Comparator(java.util.Comparator) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) RepositoryTool(com.epam.pipeline.entity.pipeline.RepositoryTool)

Example 54 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolDaoTest method testSaveDelete.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testSaveDelete() {
    Tool tool = generateTool();
    tool.setRegistryId(firstRegistry.getId());
    tool.setToolGroupId(library1.getId());
    toolDao.createTool(tool);
    Tool loaded = toolDao.loadTool(tool.getId());
    checkLoadedTool(loaded, firstRegistry.getId(), TEST_REPO);
    List<Tool> tools = toolDao.loadAllTools();
    Assert.assertEquals(1, tools.size());
    loaded = toolDao.loadTool(firstRegistry.getId(), tool.getImage());
    checkLoadedTool(loaded, firstRegistry.getId(), TEST_REPO);
    toolDao.deleteTool(loaded.getId());
    Assert.assertTrue(toolDao.loadAllTools().isEmpty());
}
Also used : Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 55 with Tool

use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.

the class ToolDaoTest method testLoadToolsWithIssuesCount.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadToolsWithIssuesCount() {
    // create tool
    Tool tool = generateTool();
    tool.setRegistryId(firstRegistry.getId());
    tool.setToolGroupId(library1.getId());
    toolDao.createTool(tool);
    // create issues
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    EntityVO entityVO = new EntityVO(tool.getId(), AclClass.TOOL);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    issueManager.createIssue(issueVO);
    verify(notificationManager).notifyIssue(any(), any(), any());
    issueVO.setName(ISSUE_NAME2);
    issueManager.createIssue(issueVO);
    List<ToolWithIssuesCount> loaded = toolDao.loadToolsWithIssuesCountByGroup(library1.getId());
    Assert.assertEquals(1, loaded.size());
    Assert.assertEquals(2, loaded.get(0).getIssuesCount());
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) ToolWithIssuesCount(com.epam.pipeline.entity.pipeline.ToolWithIssuesCount) IssueVO(com.epam.pipeline.controller.vo.IssueVO) Tool(com.epam.pipeline.entity.pipeline.Tool) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Tool (com.epam.pipeline.entity.pipeline.Tool)72 Transactional (org.springframework.transaction.annotation.Transactional)28 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)24 Test (org.junit.Test)22 ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)14 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)9 DockerClient (com.epam.pipeline.manager.docker.DockerClient)9 List (java.util.List)9 PipelineConfiguration (com.epam.pipeline.entity.configuration.PipelineConfiguration)8 MessageHelper (com.epam.pipeline.common.MessageHelper)7 PipelineRun (com.epam.pipeline.entity.pipeline.PipelineRun)7 ToolVersionScanResult (com.epam.pipeline.entity.scan.ToolVersionScanResult)7 ToolScanExternalServiceException (com.epam.pipeline.exception.ToolScanExternalServiceException)7 DockerRegistryManager (com.epam.pipeline.manager.docker.DockerRegistryManager)7 Optional (java.util.Optional)7 MessageConstants (com.epam.pipeline.common.MessageConstants)6 ManifestV2 (com.epam.pipeline.entity.docker.ManifestV2)6 ToolScanStatus (com.epam.pipeline.entity.pipeline.ToolScanStatus)6 DockerClientFactory (com.epam.pipeline.manager.docker.DockerClientFactory)6