Search in sources :

Example 26 with ToolGroup

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

Example 27 with ToolGroup

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

Example 28 with ToolGroup

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

Example 29 with ToolGroup

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

Example 30 with ToolGroup

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);
    }
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) EntityEventServiceManager(com.epam.pipeline.manager.event.EntityEventServiceManager) StringUtils(org.apache.commons.lang3.StringUtils) PermissionGrantVO(com.epam.pipeline.controller.vo.PermissionGrantVO) PipelineApiService(com.epam.pipeline.manager.pipeline.PipelineApiService) ObjectIdentity(org.springframework.security.acls.model.ObjectIdentity) PipelineRun(com.epam.pipeline.entity.pipeline.PipelineRun) ConfigurationProviderManager(com.epam.pipeline.manager.pipeline.runner.ConfigurationProviderManager) AbstractRunConfigurationEntry(com.epam.pipeline.entity.configuration.AbstractRunConfigurationEntry) AclPermission(com.epam.pipeline.security.acl.AclPermission) Map(java.util.Map) MutableAcl(org.springframework.security.acls.model.MutableAcl) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) PermissionFactory(org.springframework.security.acls.domain.PermissionFactory) DefaultRoles(com.epam.pipeline.entity.user.DefaultRoles) Set(java.util.Set) Acl(org.springframework.security.acls.model.Acl) EntityWithPermissionVO(com.epam.pipeline.controller.vo.security.EntityWithPermissionVO) Tool(com.epam.pipeline.entity.pipeline.Tool) Stream(java.util.stream.Stream) CollectionUtils(org.springframework.util.CollectionUtils) EntityVO(com.epam.pipeline.controller.vo.EntityVO) AclDataAccessException(org.springframework.security.acls.model.AclDataAccessException) MetadataEntry(com.epam.pipeline.entity.metadata.MetadataEntry) ObjectIdentityImpl(org.springframework.security.acls.domain.ObjectIdentityImpl) AbstractEntityPermissionMapper(com.epam.pipeline.mapper.AbstractEntityPermissionMapper) DataStorageAction(com.epam.pipeline.entity.datastorage.DataStorageAction) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) RunConfigurationVO(com.epam.pipeline.controller.vo.configuration.RunConfigurationVO) ArrayList(java.util.ArrayList) DockerRegistryManager(com.epam.pipeline.manager.docker.DockerRegistryManager) Service(org.springframework.stereotype.Service) SetUtils(org.apache.commons.collections4.SetUtils) EntityManager(com.epam.pipeline.manager.EntityManager) Sid(org.springframework.security.acls.model.Sid) BaseEntity(com.epam.pipeline.entity.BaseEntity) Pair(org.apache.commons.math3.util.Pair) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) TaskStatus(com.epam.pipeline.entity.pipeline.TaskStatus) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) EntityPermissionVO(com.epam.pipeline.controller.vo.EntityPermissionVO) GrantedAuthoritySid(org.springframework.security.acls.domain.GrantedAuthoritySid) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) RunConfiguration(com.epam.pipeline.entity.configuration.RunConfiguration) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) AclSecuredEntry(com.epam.pipeline.entity.security.acl.AclSecuredEntry) PipelineWithPermissions(com.epam.pipeline.entity.pipeline.PipelineWithPermissions) MetadataEntityManager(com.epam.pipeline.manager.metadata.MetadataEntityManager) AclClass(com.epam.pipeline.entity.security.acl.AclClass) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) AbstractHierarchicalEntity(com.epam.pipeline.entity.AbstractHierarchicalEntity) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LoggerFactory(org.slf4j.LoggerFactory) EntityPermission(com.epam.pipeline.entity.security.acl.EntityPermission) Folder(com.epam.pipeline.entity.pipeline.Folder) UserContext(com.epam.pipeline.security.UserContext) MessageHelper(com.epam.pipeline.common.MessageHelper) Collectors.toMap(java.util.stream.Collectors.toMap) ListUtils(org.apache.commons.collections4.ListUtils) PipelineWithPermissionsMapper(com.epam.pipeline.mapper.PipelineWithPermissionsMapper) IssueComment(com.epam.pipeline.entity.issue.IssueComment) NodesManager(com.epam.pipeline.manager.cluster.NodesManager) IssueManager(com.epam.pipeline.manager.issue.IssueManager) Collectors.toSet(java.util.stream.Collectors.toSet) Pipeline(com.epam.pipeline.entity.pipeline.Pipeline) RepositoryTool(com.epam.pipeline.entity.pipeline.RepositoryTool) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) Collection(java.util.Collection) AccessControlEntry(org.springframework.security.acls.model.AccessControlEntry) AclPermissionEntry(com.epam.pipeline.entity.security.acl.AclPermissionEntry) NodeInstance(com.epam.pipeline.entity.cluster.NodeInstance) List(java.util.List) UserManager(com.epam.pipeline.manager.user.UserManager) SidRetrievalStrategy(org.springframework.security.acls.model.SidRetrievalStrategy) Optional(java.util.Optional) Authentication(org.springframework.security.core.Authentication) AclSecuredFilter(com.epam.pipeline.entity.filter.AclSecuredFilter) JdbcMutableAclServiceImpl(com.epam.pipeline.security.acl.JdbcMutableAclServiceImpl) MessageConstants(com.epam.pipeline.common.MessageConstants) PipelineRunManager(com.epam.pipeline.manager.pipeline.PipelineRunManager) ToolManager(com.epam.pipeline.manager.pipeline.ToolManager) Permission(org.springframework.security.acls.model.Permission) HashMap(java.util.HashMap) HashSet(java.util.HashSet) Propagation(org.springframework.transaction.annotation.Propagation) Collectors.mapping(java.util.stream.Collectors.mapping) ToolGroupManager(com.epam.pipeline.manager.pipeline.ToolGroupManager) Logger(org.slf4j.Logger) AclSid(com.epam.pipeline.entity.security.acl.AclSid) Collectors.toList(java.util.stream.Collectors.toList) MetadataEntity(com.epam.pipeline.entity.metadata.MetadataEntity) PipelinesWithPermissionsVO(com.epam.pipeline.controller.vo.PipelinesWithPermissionsVO) AccessControlEntryImpl(org.springframework.security.acls.domain.AccessControlEntryImpl) Data(lombok.Data) Issue(com.epam.pipeline.entity.issue.Issue) Comparator(java.util.Comparator) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) DockerRegistry(com.epam.pipeline.entity.pipeline.DockerRegistry) ToolGroup(com.epam.pipeline.entity.pipeline.ToolGroup) Tool(com.epam.pipeline.entity.pipeline.Tool) RepositoryTool(com.epam.pipeline.entity.pipeline.RepositoryTool)

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