use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryManager method parseAndValidateScope.
// expected format: repository:group/image:push
private List<DockerRegistryClaim> parseAndValidateScope(String userName, DockerRegistry registry, String scope) {
if (StringUtils.isBlank(scope)) {
// read permission for at least one child in the registry is required
if (!permissionManager.isActionAllowedForUser(registry, userName, AclPermission.READ)) {
DockerRegistry fullTree = getDockerRegistryTree(registry.getId());
permissionManager.filterTree(userName, fullTree, AclPermission.READ);
if (CollectionUtils.isEmpty(fullTree.getChildren())) {
throw new DockerAuthorizationException(registry.getPath(), messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_IS_NOT_ALLOWED, userName, registry.getPath()));
}
}
return Collections.emptyList();
}
List<DockerRegistryClaim> claims = DockerRegistryClaim.parseClaims(scope);
claims.forEach(claim -> {
AbstractSecuredEntity entity = registry;
List<Permission> permissions = claim.getRequestedPermissions();
boolean toolRequired = !permissions.contains(AclPermission.WRITE);
try {
ToolGroup toolGroup = toolGroupManager.loadToolGroupByImage(registry.getPath(), claim.getImageName());
entity = toolGroup;
Optional<Tool> tool = toolManager.loadToolInGroup(claim.getImageName(), toolGroup.getId());
entity = tool.orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, claim.getImageName())));
} catch (IllegalArgumentException e) {
LOGGER.trace(e.getMessage(), e);
if (toolRequired) {
throw new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_IMAGE_UNAVAILABLE, claim.getImageName()));
}
}
if (!permissionManager.isActionAllowedForUser(entity, userName, permissions)) {
throw new DockerAuthorizationException(registry.getPath(), messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_ACTION_IS_NOT_ALLOWED, scope, userName, registry.getPath()));
}
});
return claims;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class DockerRegistryManager method createToolFromEvent.
private Optional<Tool> createToolFromEvent(String registry, DockerRegistryEvent registryEvent) {
DockerRegistry dockerRegistry = fetchDockerRegistry(registry, registryEvent);
String fullToolName = registryEvent.getTarget().getRepository();
ImmutablePair<String, String> groupAndTool = toolGroupManager.getGroupAndTool(fullToolName);
ToolGroup toolGroup = fetchToolGroup(registryEvent, dockerRegistry, groupAndTool.getLeft());
return enableToolIfNeeded(registryEvent, dockerRegistry, fullToolName, toolGroup);
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method updateToolGroup.
/**
* Updates a {@link ToolGroup}. The fields, allowed for update are: description
* @param toolGroup
* @return
*/
@Transactional(propagation = Propagation.REQUIRED)
public ToolGroup updateToolGroup(final ToolGroup toolGroup) {
Assert.notNull(toolGroup.getId(), messageHelper.getMessage(MessageConstants.ERROR_PARAMETER_NULL_OR_EMPTY, "id"));
ToolGroup old = toolGroupDao.loadToolGroup(toolGroup.getId()).orElseThrow(() -> new IllegalArgumentException(messageHelper.getMessage(MessageConstants.ERROR_TOOL_GROUP_NOT_FOUND, toolGroup.getId())));
old.setDescription(toolGroup.getDescription());
toolGroupDao.updateToolGroup(old);
return old;
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method loadByRegistryName.
private List<ToolGroup> loadByRegistryName(String registryName) {
String currentUserName = makePrivateGroupName();
DockerRegistry registry = dockerRegistryManager.loadByNameOrId(registryName);
return toolGroupDao.loadToolGroups(registry.getId()).stream().peek(g -> g.setPrivateGroup(g.getName().equalsIgnoreCase(currentUserName))).collect(Collectors.toList());
}
use of com.epam.pipeline.entity.pipeline.ToolGroup in project cloud-pipeline by epam.
the class ToolGroupManager method delete.
@Transactional(propagation = Propagation.REQUIRED)
public ToolGroup delete(String id) {
ToolGroup group = loadByNameOrId(id);
toolGroupDao.deleteToolGroup(group.getId());
return group;
}
Aggregations