use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolManager method delete.
/**
* Deletes a Tool from the database and from Docker Registry
* @param registry registry identifier
* @param image Tool's image
* @param hard flag determines if the real image from Docker Registry should be deleted
* @return the deleted Tool entity
*/
@Transactional(propagation = Propagation.REQUIRED)
public Tool delete(String registry, final String image, boolean hard) {
Tool tool = loadTool(registry, image);
if (hard) {
DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
List<String> tags = dockerRegistryManager.loadImageTags(dockerRegistry, image);
for (String tag : tags) {
Optional<ManifestV2> manifestOpt = dockerRegistryManager.deleteImage(dockerRegistry, tool.getImage(), tag);
manifestOpt.ifPresent(manifest -> {
dockerRegistryManager.deleteLayer(dockerRegistry, image, manifest.getConfig().getDigest());
Collections.reverse(manifest.getLayers());
for (ManifestV2.Config layer : manifest.getLayers()) {
dockerRegistryManager.deleteLayer(dockerRegistry, image, layer.getDigest());
}
});
}
}
toolVulnerabilityDao.loadAllToolVersionScans(tool.getId()).values().forEach(versionScan -> deleteToolVersionScan(tool.getId(), versionScan.getVersion()));
toolDao.deleteToolIcon(tool.getId());
toolVersionManager.deleteToolVersions(tool.getId());
toolDao.deleteTool(tool.getId());
return tool;
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolManager method changeOwner.
@Override
public AbstractSecuredEntity changeOwner(Long id, String owner) {
Tool tool = toolDao.loadTool(id);
tool.setOwner(owner);
toolDao.updateTool(tool);
return tool;
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolManager method loadByNameOrId.
/**
* Tries to parse repository and image name from a string of pattern 'repo:5000/image'
* @param identifier
* @return
*/
@Override
public Tool loadByNameOrId(String identifier) {
if (NumberUtils.isDigits(identifier)) {
Tool imageTool = toolDao.loadTool(Long.parseLong(identifier));
if (imageTool != null) {
return imageTool;
}
}
Matcher matcher = REPOSITORY_AND_IMAGE.matcher(identifier);
String repository = "";
String imageName;
String imageWithTag;
if (matcher.find()) {
repository = matcher.group(1);
imageWithTag = matcher.group(2);
imageName = getImageWithoutTag(imageWithTag);
} else {
imageWithTag = identifier;
imageName = getImageWithoutTag(identifier);
}
if (!imageAndTagAreValid(imageWithTag)) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_INVALID_IMAGE_REPOSITORY, repository));
}
Tool imageTool = fetchTool(repository, imageName);
if ((!repository.isEmpty() && !repository.equals(imageTool.getRegistry()))) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_INVALID_IMAGE_REPOSITORY, repository));
}
// return value with tag
imageTool.setImage(imageWithTag);
return imageTool;
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolManager method updateToolIcon.
/**
* Updates an icon of a Tool, specified by ID
* @param toolId an ID of a Tool, which icon to update
* @param fileName a name of an icon file
* @param image a byte content of a file
* @return an ID of a newly created icon
*/
@Transactional(propagation = Propagation.REQUIRED)
public long updateToolIcon(long toolId, String fileName, byte[] image) {
Tool tool = load(toolId);
Assert.notNull(tool, messageHelper.getMessage(MessageConstants.ERROR_TOOL_NOT_FOUND, toolId));
int allowedIconSize = preferenceManager.getPreference(SystemPreferences.MISC_MAX_TOOL_ICON_SIZE_KB) * KB_SIZE;
Assert.isTrue(image.length <= allowedIconSize, messageHelper.getMessage(MessageConstants.ERROR_TOOL_ICON_TOO_LARGE, image.length, allowedIconSize));
return toolDao.updateIcon(toolId, FilenameUtils.getName(fileName), image);
}
use of com.epam.pipeline.entity.pipeline.Tool in project cloud-pipeline by epam.
the class ToolManager method deleteToolVersion.
/**
* Deletes Tool's version (a tag) from Docker Registry
*
* @param registry registry identifier
* @param image Tool's image
* @param version tag from registry
* @return Tool entity, which version was deleted
*/
@Transactional(propagation = Propagation.REQUIRED)
public Tool deleteToolVersion(String registry, final String image, String version) {
Tool tool = loadTool(registry, image);
deleteToolVersionScan(tool.getId(), version);
toolVersionManager.deleteToolVersion(tool.getId(), version);
DockerRegistry dockerRegistry = dockerRegistryManager.load(tool.getRegistryId());
dockerRegistryManager.deleteImage(dockerRegistry, tool.getImage(), version);
return tool;
}
Aggregations