use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method loadByNameOrId.
@Override
public ToolGroup loadByNameOrId(String identifier) {
if (NumberUtils.isDigits(identifier)) {
return load(Long.parseLong(identifier));
} else {
Pair<String, String> registryAndGroupName = getPrefixAndName(identifier);
List<ToolGroup> groups = toolGroupDao.loadToolGroupsByNameAndRegistryName(registryAndGroupName.getRight(), registryAndGroupName.getLeft());
Assert.isTrue(groups.size() <= 1, messageHelper.getMessage(MessageConstants.ERROR_TOO_MANY_RESULTS, identifier));
Assert.isTrue(!groups.isEmpty(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_NOT_FOUND, identifier));
ToolGroup result = groups.get(0);
result.setTools(toolManager.loadToolsByGroup(result.getId()));
result.setPrivateGroup(result.getName().equalsIgnoreCase(makePrivateGroupName()));
return result;
}
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method createPrivate.
@Transactional(propagation = Propagation.REQUIRED)
public ToolGroup createPrivate(Long registryId) {
ToolGroup privateGroup = new ToolGroup();
String privateGroupName = makePrivateGroupName();
privateGroup.setName(privateGroupName);
privateGroup.setRegistryId(registryId);
privateGroup.setOwner(authManager.getAuthorizedUser());
privateGroup.setPrivateGroup(true);
DockerRegistry registry = dockerRegistryManager.load(registryId);
Assert.notNull(registry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, registryId));
Assert.isTrue(!toolGroupDao.loadToolGroup(privateGroup.getName(), privateGroup.getRegistryId()).isPresent(), messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_ALREADY_EXIST, privateGroup.getName(), registry.getName()));
privateGroup.setParent(registry);
toolGroupDao.createToolGroup(privateGroup);
makePrivate(privateGroup);
return privateGroup;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method loadWithParents.
@Override
public ToolGroup loadWithParents(final Long id) {
Optional<ToolGroup> loadResult = toolGroupDao.loadToolGroup(id);
if (loadResult.isPresent()) {
ToolGroup toolGroup = loadResult.get();
toolGroup.setParent(new DockerRegistry(toolGroup.getRegistryId()));
}
return loadResult.orElse(null);
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolManager method create.
/**
* Creates a new Tool in the requested group
* @param tool a tool to create
* @return newly created group
*/
@Transactional(propagation = Propagation.REQUIRED)
public Tool create(final Tool tool, final boolean checkExistence) {
Assert.notNull(tool.getImage(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "image", Tool.class.getSimpleName()));
Assert.notNull(tool.getCpu(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "cpu", Tool.class.getSimpleName()));
Assert.notNull(tool.getRam(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "ram", Tool.class.getSimpleName()));
Assert.notNull(tool.getToolGroupId(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_REQUIRED, "toolGroupId", Tool.class.getSimpleName()));
ToolGroup group = toolGroupManager.load(tool.getToolGroupId());
tool.setParent(group);
tool.setRegistryId(group.getRegistryId());
tool.setToolGroupId(group.getId());
if (!StringUtils.hasText(tool.getOwner())) {
tool.setOwner(authManager.getAuthorizedUser());
}
Assert.isTrue(isToolUniqueInGroup(tool.getImage(), group.getId()), messageHelper.getMessage(MessageConstants.ERROR_TOOL_ALREADY_EXIST, tool.getImage(), group.getName()));
validateInstanceType(tool);
DockerRegistry registry = dockerRegistryManager.load(group.getRegistryId());
if (checkExistence) {
try {
List<String> tags = dockerRegistryManager.loadImageTags(registry, tool.getImage());
Assert.isTrue(!CollectionUtils.isEmpty(tags), messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
} catch (DockerConnectionException e) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
}
}
toolDao.createTool(tool);
try {
List<String> tags = dockerRegistryManager.loadImageTags(registry, tool.getImage());
for (String tag : tags) {
String digest = dockerRegistryManager.getDockerClient(registry, tool.getImage()).getVersionAttributes(registry, tool.getImage(), tag).getDigest();
updateToolVersionScanStatus(tool.getId(), ToolScanStatus.NOT_SCANNED, DateUtils.now(), tag, null, digest);
}
} catch (DockerConnectionException e) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, tool.getImage()));
}
return tool;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup 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);
}
}
Aggregations