use of com.epam.pipeline.entity.pipeline.DockerRegistry 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.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method delete.
@Transactional(propagation = Propagation.REQUIRED)
public DockerRegistry delete(Long id, boolean force) {
DockerRegistry registry = dockerRegistryDao.loadDockerRegistry(id);
if (force) {
// remove all tools from registry to avoid DataIntegrityViolationException
// But do not delete actual tools from registry
registry.getTools().forEach(tool -> toolManager.delete(tool.getRegistry(), tool.getImage(), false));
toolGroupManager.loadByRegistryId(id).forEach(g -> toolGroupManager.delete(g.getId().toString()));
}
if (StringUtils.isNotBlank(registry.getSecretName())) {
kubernetesManager.deleteSecret(registry.getSecretName());
}
dockerRegistryDao.deleteDockerRegistry(id);
return registry;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method fetchDockerRegistry.
private DockerRegistry fetchDockerRegistry(String registry, DockerRegistryEvent registryEvent) {
String registryName = !StringUtils.isEmpty(registry) ? registry : registryEvent.getRequest().getHost();
DockerRegistry dockerRegistry = loadByNameOrId(registryName);
if (dockerRegistry == null) {
dockerRegistry = loadByExternalUrl(registryName);
}
Assert.notNull(dockerRegistry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_NOT_FOUND, registryName));
return dockerRegistry;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method changeOwner.
@Override
public AbstractSecuredEntity changeOwner(Long id, String owner) {
final DockerRegistry registry = dockerRegistryDao.loadDockerRegistry(id);
registry.setOwner(owner);
dockerRegistryDao.updateDockerRegistry(registry);
return registry;
}
use of com.epam.pipeline.entity.pipeline.DockerRegistry in project cloud-pipeline by epam.
the class DockerRegistryManager method create.
@Transactional(propagation = Propagation.REQUIRED)
public DockerRegistry create(DockerRegistryVO dockerRegistryVO) {
DockerRegistry loadedDockerRegistry = loadByNameOrId(dockerRegistryVO.getPath());
Assert.isNull(loadedDockerRegistry, messageHelper.getMessage(MessageConstants.ERROR_REGISTRY_ALREADY_EXISTS, dockerRegistryVO.getPath()));
DockerRegistry dockerRegistry = dockerRegistryVO.convertToDockerRegistry();
normalizeCert(dockerRegistry);
validateAuthentication(dockerRegistry);
if (StringUtils.isNotBlank(dockerRegistryVO.getUserName())) {
DockerRegistrySecret secret = dockerRegistryVO.convertToSecret();
dockerRegistry.setSecretName(kubernetesManager.createDockerRegistrySecret(secret));
}
dockerRegistry.setOwner(authManager.getAuthorizedUser());
dockerRegistryDao.createDockerRegistry(dockerRegistry);
LOGGER.debug("Repository '{}' was saved.", dockerRegistry.getPath());
return dockerRegistry;
}
Aggregations