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);
}
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;
}
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);
}
}
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());
}
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());
}
Aggregations