Search in sources :

Example 21 with ToolGroup

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;
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) DockerAuthorizationException(com.epam.pipeline.exception.docker.DockerAuthorizationException) AclPermission(com.epam.pipeline.security.acl.AclPermission) Permission(org.springframework.security.acls.model.Permission) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Tool(com.epam.pipeline.entity.pipeline.Tool)

Example 22 with ToolGroup

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);
}
Also used : DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup)

Example 23 with 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;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with ToolGroup

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());
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) MessageConstants(com.epam.pipeline.common.MessageConstants) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionGrantVO(com.epam.pipeline.controller.vo.PermissionGrantVO) ToolGroupWithIssues(com.epam.pipeline.entity.pipeline.ToolGroupWithIssues) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) Matcher(java.util.regex.Matcher) MessageHelper(com.epam.pipeline.common.MessageHelper) Pair(org.apache.commons.lang3.tuple.Pair) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) AclPermission(com.epam.pipeline.security.acl.AclPermission) GrantPermissionManager(com.epam.pipeline.manager.security.GrantPermissionManager) Constants(com.epam.pipeline.config.Constants) SecuredEntityManager(com.epam.pipeline.manager.security.SecuredEntityManager) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) ToolGroupWithIssuesMapper(com.epam.pipeline.mapper.ToolGroupWithIssuesMapper) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) List(java.util.List) AclSync(com.epam.pipeline.manager.security.acl.AclSync) NumberUtils(org.apache.commons.lang3.math.NumberUtils) AclClass(com.epam.pipeline.entity.security.acl.AclClass) Optional(java.util.Optional) AuthManager(com.epam.pipeline.manager.security.AuthManager) Pattern(java.util.regex.Pattern) ToolGroupDao(com.epam.pipeline.dao.tool.ToolGroupDao) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry)

Example 25 with ToolGroup

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;
}
Also used : ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ToolGroup (com.epam.pipeline.entity.pipeline.ToolGroup)53 Transactional (org.springframework.transaction.annotation.Transactional)27 DockerRegistry (com.epam.pipeline.entity.pipeline.DockerRegistry)25 Test (org.junit.Test)20 Tool (com.epam.pipeline.entity.pipeline.Tool)14 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 AbstractManagerTest (com.epam.pipeline.manager.AbstractManagerTest)10 Before (org.junit.Before)10 AclPermission (com.epam.pipeline.security.acl.AclPermission)6 List (java.util.List)6 Autowired (org.springframework.beans.factory.annotation.Autowired)6 Propagation (org.springframework.transaction.annotation.Propagation)6 DockerRegistryDao (com.epam.pipeline.dao.docker.DockerRegistryDao)4 AclTestDao (com.epam.pipeline.dao.util.AclTestDao)4 AclClass (com.epam.pipeline.entity.security.acl.AclClass)4 Optional (java.util.Optional)4 Assert (org.junit.Assert)4 WithMockUser (org.springframework.security.test.context.support.WithMockUser)4 PermissionGrantVO (com.epam.pipeline.controller.vo.PermissionGrantVO)3 ToolGroupDao (com.epam.pipeline.dao.tool.ToolGroupDao)3