use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManagerTest method createRegistryShouldRegisterNonExistingRegistry.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void createRegistryShouldRegisterNonExistingRegistry() {
when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class))).thenReturn(new EmptyDockerClient());
DockerRegistryVO dockerRegistry = new DockerRegistryVO();
dockerRegistry.setPath(PATH);
dockerRegistry.setDescription(DESCRIPTION);
dockerRegistryManager.create(dockerRegistry);
Assert.assertNotNull(dockerRegistryManager.loadByNameOrId(dockerRegistry.getPath()));
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManagerTest method testLoadingImageDescription.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testLoadingImageDescription() {
DockerRegistry registry = generateRegistry();
Date date = new Date();
registryDao.createDockerRegistry(registry);
ToolGroup group = generateToolGroup(registry);
toolGroupDao.createToolGroup(group);
Tool tool = generateTool(group);
toolManager.create(tool, true);
DockerClient mockClient = Mockito.mock(DockerClient.class);
when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class), any())).thenReturn(mockClient);
ImageDescription expected = new ImageDescription(1L, TEST_IMAGE, TEST_TAG, date);
when(mockClient.getImageDescription(registry, tool.getName(), TEST_TAG)).thenReturn(expected);
Assert.assertEquals(expected, dockerRegistryManager.getImageDescription(registry, tool.getName(), TEST_TAG));
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManagerTest method createRegistryShouldThrowExceptionIfRegistryAlreadyExists.
@Test(expected = IllegalArgumentException.class)
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void createRegistryShouldThrowExceptionIfRegistryAlreadyExists() {
when(dockerClientFactoryMock.getDockerClient(any(DockerRegistry.class))).thenReturn(new EmptyDockerClient());
DockerRegistryVO dockerRegistry = new DockerRegistryVO();
dockerRegistry.setPath(PATH);
dockerRegistry.setDescription(DESCRIPTION);
dockerRegistryManager.create(dockerRegistry);
dockerRegistryManager.create(dockerRegistry);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class GrantPermissionManager method createPrivateToolGroupPermission.
/**
* To create private group in a registry user must have ay least one 'READ' permission
* in the whole tree hierarchy (since it means that registry is visible to user) and
* 'WRITE' permission shouldn't be denied for registry itself
* @param registryId to check permissions
* @return true if permission is granted
*/
public boolean createPrivateToolGroupPermission(Long registryId) {
DockerRegistry dockerRegistryTree = registryManager.getDockerRegistryTree(registryId);
filterTree(dockerRegistryTree, AclPermission.READ);
return isCreatePrivateGroupAllowed(dockerRegistryTree);
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry 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