use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryMapperTest method shouldMapDockerRegistry.
@Test
void shouldMapDockerRegistry() throws IOException {
DockerRegistryMapper mapper = new DockerRegistryMapper();
DockerRegistry registry = new DockerRegistry();
registry.setId(1L);
registry.setDescription(TEST_DESCRIPTION);
registry.setName(TEST_NAME);
registry.setPath(TEST_PATH);
registry.setUserName(USER_NAME);
EntityContainer<DockerRegistry> container = EntityContainer.<DockerRegistry>builder().entity(registry).owner(USER).metadata(METADATA).permissions(PERMISSIONS_CONTAINER).build();
XContentBuilder contentBuilder = mapper.map(container);
verifyDockerRegistry(registry, contentBuilder);
verifyPipelineUser(USER, contentBuilder);
verifyPermissions(PERMISSIONS_CONTAINER, contentBuilder);
verifyMetadata(EXPECTED_METADATA, contentBuilder);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolDao method basicInitTool.
private static Tool basicInitTool(ResultSet rs, Tool tool) throws SQLException {
tool.setId(rs.getLong(ToolParameters.ID.name()));
tool.setImage(rs.getString(ToolParameters.IMAGE.name()));
tool.setCpu(rs.getString(ToolParameters.CPU.name()));
tool.setRam(rs.getString(ToolParameters.RAM.name()));
tool.setRegistryId(rs.getLong(ToolParameters.REGISTRY_ID.name()));
tool.setToolGroupId(rs.getLong(ToolParameters.TOOL_GROUP_ID.name()));
tool.setRegistry(rs.getString(ToolParameters.REGISTRY.name()));
tool.setSecretName(rs.getString(ToolParameters.SECRET_NAME.name()));
tool.setDescription(rs.getString(ToolParameters.DESCRIPTION.name()));
tool.setShortDescription(rs.getString(ToolParameters.SHORT_DESCRIPTION.name()));
tool.setDefaultCommand(rs.getString(ToolParameters.DEFAULT_COMMAND.name()));
tool.setOwner(rs.getString(ToolParameters.OWNER.name()));
tool.setDisk(rs.getInt(ToolParameters.DISK.name()));
tool.setInstanceType(rs.getString(ToolParameters.INSTANCE_TYPE.name()));
long longVal = rs.getLong(ToolParameters.ICON_ID.name());
tool.setHasIcon(!rs.wasNull());
tool.setIconId(longVal);
Array labelsSqlArray = rs.getArray(ToolParameters.LABELS.name());
if (labelsSqlArray != null) {
List<String> labels = Arrays.asList((String[]) labelsSqlArray.getArray());
tool.setLabels(labels);
}
Array endpointsSqlArray = rs.getArray(ToolParameters.ENDPOINTS.name());
if (endpointsSqlArray != null) {
List<String> endpoints = Arrays.asList((String[]) endpointsSqlArray.getArray());
tool.setEndpoints(endpoints);
}
// restore parent hierarchy
if (tool.getToolGroupId() != null) {
tool.setParent(new ToolGroup(tool.getToolGroupId()));
if (tool.getRegistryId() != null) {
tool.getParent().setParent(new DockerRegistry(tool.getRegistryId()));
}
}
return tool;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class AggregatingToolScanManager method fetchLayers.
private List<String> fetchLayers(Tool tool, String tag, DockerRegistry registry) throws ToolScanExternalServiceException {
DockerClient dockerClient = getDockerClient(tool.getImage(), registry);
ManifestV2 manifest = dockerClient.getManifest(registry, tool.getImage(), tag).orElseThrow(() -> new ToolScanExternalServiceException(tool, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_COULD_NOT_GET_MANIFEST, tool.getImage())));
return manifest.getLayers().stream().map(c -> c.getDigest()).collect(Collectors.toList());
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class AggregatingToolScanManager method scanTool.
public ToolVersionScanResult scanTool(Tool tool, String tag, Boolean rescan) throws ToolScanExternalServiceException {
DockerRegistry registry = dockerRegistryManager.load(tool.getRegistryId());
Optional<ToolVersionScanResult> actualScan = rescan ? Optional.empty() : getActualScan(tool, tag, registry);
return actualScan.isPresent() ? actualScan.get() : doScan(tool, tag, registry);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class ToolScanScheduler method scheduledToolScan.
/**
* A scheduled scan, that runs for all the registries, all tools and all tool versions, sends them to Tool Scanning
* System and stores scanning results to the database.
*/
public void scheduledToolScan() {
if (!preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_SCAN_ENABLED)) {
LOGGER.info(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_DISABLED));
return;
} else {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_SCHEDULED_STARTED));
}
boolean scanAllRegistries = preferenceManager.getPreference(SystemPreferences.DOCKER_SECURITY_TOOL_SCAN_ALL_REGISTRIES);
List<DockerRegistry> registries = scanAllRegistries ? dockerRegistryDao.loadAllDockerRegistry() : dockerRegistryDao.loadDockerRegistriesWithSecurityScanEnabled();
for (DockerRegistry registry : registries) {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_REGISTRY_STARTED, registry.getPath()));
for (Tool tool : registry.getTools()) {
DockerClient dockerClient = getDockerClient(registry, tool);
try {
List<String> versions = toolManager.loadTags(tool.getId());
for (String version : versions) {
try {
ToolVersionScanResult result = toolScanManager.scanTool(tool, version, false);
toolManager.updateToolVulnerabilities(result.getVulnerabilities(), tool.getId(), version);
toolManager.updateToolDependencies(result.getDependencies(), tool.getId(), version);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.COMPLETED, new Date(), version, result.getLastLayerRef(), result.getDigest());
updateToolVersion(tool, version, registry, dockerClient);
} catch (ToolScanExternalServiceException e) {
LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_FAILED, tool.getImage(), version), e);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.FAILED, new Date(), version, null, null);
}
}
} catch (Exception e) {
LOGGER.error(messageHelper.getMessage(MessageConstants.ERROR_TOOL_SCAN_FAILED, tool.getImage()), e);
toolManager.updateToolVersionScanStatus(tool.getId(), ToolScanStatus.FAILED, new Date(), "latest", null, null);
}
}
}
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_TOOL_SCAN_SCHEDULED_DONE));
}
Aggregations