This is an automated email from the ASF dual-hosted git repository. ofuks pushed a commit to branch audit in repository https://gitbox.apache.org/repos/asf/incubator-dlab.git
commit 9d9446980bd3958646a99eef97217c4264b550ea Author: Oleh Fuks <olegfuk...@gmail.com> AuthorDate: Wed Jun 10 17:30:00 2020 +0300 Added audit for endpoint --- .../dlab/backendapi/domain/AuditActionEnum.java | 1 + .../backendapi/resources/EndpointResource.java | 16 +++++---- .../dlab/backendapi/service/EndpointService.java | 6 ++-- .../service/impl/EndpointServiceImpl.java | 38 ++++++++++++++-------- 4 files changed, 38 insertions(+), 23 deletions(-) diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java index 749885f..14686d7 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/domain/AuditActionEnum.java @@ -23,5 +23,6 @@ public enum AuditActionEnum { CREATE_PROJECT, START_PROJECT, STOP_PROJECT, TERMINATE_PROJECT, UPDATE_PROJECT, CREATE_NOTEBOOK, START_NOTEBOOK, STOP_NOTEBOOK, TERMINATE_NOTEBOOK, UPDATE_CLUSTER_CONFIG, CREATE_DATA_ENGINE, CREATE_DATA_ENGINE_SERVICE, START_COMPUTATIONAL, STOP_COMPUTATIONAL, TERMINATE_COMPUTATIONAL, UPDATE_DATA_ENGINE_CONFIG, + CREATE_ENDPOINT, DELETE_ENDPOINT, FOLLOW_NOTEBOOK_LINK } diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java index 3b49b42..dcb4594 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/resources/EndpointResource.java @@ -36,7 +36,13 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import javax.annotation.security.RolesAllowed; import javax.validation.Valid; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -72,7 +78,7 @@ public class EndpointResource { @Consumes(MediaType.APPLICATION_JSON) @POST public Response createEndpoint(@Parameter(hidden = true) @Auth UserInfo userInfo, @Valid EndpointDTO endpointDTO) { - endpointService.create(userInfo, endpointDTO); + endpointService.create(userInfo, endpointDTO.getName(), endpointDTO); final URI uri = uriInfo.getRequestUriBuilder().path(endpointDTO.getName()).build(); return Response .ok() @@ -136,10 +142,8 @@ public class EndpointResource { @Path("{name}") public Response removeEndpoint(@Parameter(hidden = true) @Auth UserInfo userInfo, @Parameter(description = "Endpoint name") - @PathParam("name") String name, - @Parameter(description = "Delete endpoint only or with related resources") - @QueryParam("with-resources") @DefaultValue("false") boolean withResources) { - endpointService.remove(userInfo, name, withResources); + @PathParam("name") String name) { + endpointService.remove(userInfo, name); return Response.ok().build(); } diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EndpointService.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EndpointService.java index 58afa39..24fcddd 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EndpointService.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/EndpointService.java @@ -17,13 +17,13 @@ public interface EndpointService { EndpointDTO get(String name); - void create(UserInfo userInfo, EndpointDTO endpointDTO); + void create(UserInfo userInfo, String resourceName, EndpointDTO endpointDTO); void updateEndpointStatus(String name, EndpointDTO.EndpointStatus status); - void remove(UserInfo userInfo, String name, boolean withResources); + void remove(UserInfo userInfo, String name); void removeEndpointInAllProjects(UserInfo userInfo, String endpointName, List<ProjectDTO> projects); - CloudProvider checkUrl(UserInfo userInfo, String url); + CloudProvider checkUrl(UserInfo userInfo, String url); } diff --git a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java index fcfe789..40ed5ea 100644 --- a/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java +++ b/services/self-service/src/main/java/com/epam/dlab/backendapi/service/impl/EndpointServiceImpl.java @@ -1,6 +1,9 @@ package com.epam.dlab.backendapi.service.impl; import com.epam.dlab.auth.UserInfo; +import com.epam.dlab.backendapi.annotation.Audit; +import com.epam.dlab.backendapi.annotation.ResourceName; +import com.epam.dlab.backendapi.annotation.User; import com.epam.dlab.backendapi.dao.EndpointDAO; import com.epam.dlab.backendapi.dao.ExploratoryDAO; import com.epam.dlab.backendapi.dao.UserRoleDao; @@ -26,9 +29,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.Optional; import java.util.stream.Collectors; +import static com.epam.dlab.backendapi.domain.AuditActionEnum.CREATE_ENDPOINT; +import static com.epam.dlab.backendapi.domain.AuditActionEnum.DELETE_ENDPOINT; + @Slf4j public class EndpointServiceImpl implements EndpointService { @@ -81,16 +86,19 @@ public class EndpointServiceImpl implements EndpointService { * Create new endpoint object in the System. * The Endpoint objects should contain Unique values of the 'url' and 'name' fields, * i.e two objects with same URLs should not be created in the system. - * @param userInfo user properties - * @param endpointDTO object with endpoint fields + * + * @param userInfo user properties + * @param resourceName name of the endpoint + * @param endpointDTO object with endpoint fields */ + @Audit(action = CREATE_ENDPOINT) @Override - public void create(UserInfo userInfo, EndpointDTO endpointDTO) { + public void create(@User UserInfo userInfo, @ResourceName String resourceName, EndpointDTO endpointDTO) { if (endpointDAO.get(endpointDTO.getName()).isPresent()) { throw new ResourceConflictException("The Endpoint with this name exists in system"); } - if(endpointDAO.getEndpointWithUrl(endpointDTO.getUrl()).isPresent()) { - throw new ResourceConflictException("The Endpoint URL with this address exists in system"); + if (endpointDAO.getEndpointWithUrl(endpointDTO.getUrl()).isPresent()) { + throw new ResourceConflictException("The Endpoint URL with this address exists in system"); } CloudProvider cloudProvider = checkUrl(userInfo, endpointDTO.getUrl()); if (Objects.isNull(cloudProvider)) { @@ -107,18 +115,20 @@ public class EndpointServiceImpl implements EndpointService { } @Override - public void remove(UserInfo userInfo, String name, boolean withResources) { - Optional<EndpointDTO> endpointDTO = endpointDAO.get(name); - endpointDTO.orElseThrow(() -> new ResourceNotFoundException(String.format("Endpoint %s does not exist", name))); + public void remove(UserInfo userInfo, String name) { + EndpointDTO endpointDTO = endpointDAO.get(name).orElseThrow(() -> new ResourceNotFoundException(String.format("Endpoint %s does not exist", name))); List<ProjectDTO> projects = projectService.getProjectsByEndpoint(name); checkProjectEndpointResourcesStatuses(projects, name); + CloudProvider cloudProvider = endpointDTO.getCloudProvider(); + removeEndpoint(userInfo, name, cloudProvider, projects); + } - if (withResources) { - removeEndpointInAllProjects(userInfo, name, projects); - } - CloudProvider cloudProvider = endpointDTO.get().getCloudProvider(); + @Audit(action = DELETE_ENDPOINT) + public void removeEndpoint(@User UserInfo userInfo, @ResourceName String name, CloudProvider cloudProvider, List<ProjectDTO> projects) { + removeEndpointInAllProjects(userInfo, name, projects); endpointDAO.remove(name); - List<CloudProvider> remainingProviders = endpointDAO.getEndpoints().stream() + List<CloudProvider> remainingProviders = endpointDAO.getEndpoints() + .stream() .map(EndpointDTO::getCloudProvider) .collect(Collectors.toList()); userRoleDao.removeUnnecessaryRoles(cloudProvider, remainingProviders); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@dlab.apache.org For additional commands, e-mail: commits-h...@dlab.apache.org