Commit 92c7b2f6 authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/common-api-gateway!140
parents 32d97980 e3386096
Pipeline #1090 failed
# Common API gateway # Common API gateway
Public REST API Gateway application for TeIS common methods. Common API Gateway application provides public REST interface for TeIS common methods.
The application: ## Features
* provides API methods for Front-end appliation
* authorizes client requests
* sends requests to Microservices via Rabbit Exchange (gw_exchange) queues.
* generates unique request ID's forwarded to microservices along with the request data.
* holds client websocket connections
## Run application The project contains 2 modules:
1. **api-gateway** - is a Spring Boot application providing the following functionality:
* common API methods consumed by different front-end applications (public self-service and official user application).
* authorizes all client requests and checks the validity of client JWT access token issued by SSO (Keycloak).
* sends requests to microservices via Rabbit Exchange (gw_exchange) queues.
* generates unique request IDs forwarded to microservices along with the request data.
2. **api-gateway-lib** - Java library containing common Data Transfer Objects (DTO) exchanged in the
communication between gateway and microservices. All microservices consuming gateway messages depend on Common API Gateway library.
## Requirements
Spring Boot project can be run directly from CommonApiGateway.main() method or via executable jar file. See more info here: [Running your application](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html) * [OpenJDK 11](https://openjdk.java.net/projects/jdk/11/)
* [Rabbit MQ](https://www.rabbitmq.com/)
* [Keycloak (SSO)](https://www.keycloak.org/)
* [PostgreSQL](https://www.postgresql.org/)
* [Minio](https://min.io/)
Default URL and path: http://localhost:8080/api-common See [how to run required dependencies](../../docs/blob/master/run-requirements.md).
Swagger endpoint: http://localhost:8080/api-common/swagger-ui.html Common API Gateway depends on other TeIS libraries:
## Environment profiles * [TeIS Gradle plugin](../../teis-gradle-plugin)
* [TeIS public commons libraries](../../commons-public)
* [TeIS commons libraries](../../commons)
### dev|test|prelive|prod ## Run application
Spring Boot project can be run directly from [CommonApiGateway.main()](api-gateway/src/main/java/ee/sm/ti/teis/CommonApiGateway.java)
method or via executable jar file. More info on running Spring applications: [running your application.](https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-running-your-application.html)
Visit [how to run application](../../docs/blob/master/run-application.md).
Development test, test, prelive and production environment profiles running in different Kubernetes cluster. ## Build and configure
Visit [how to build](../../docs/blob/master/build-configure.md) for more info.
### local ## Default profiles
Visit [environment profiles](../../docs/blob/master/default-profiles.md) for more info.
For local development environment in IDE or command line. NB! Do not push your application-local.yaml file to the VCS. ## Additional profiles
### mockauth ### mockauth
The application allows to authenticate users with mocked authentication method if mockauth profile is set. Application allows authenticating users with mocked authentication method.
### no_keycloak ### no_keycloak
The application does not use Keycloak authentication mechanism if no_keycloak profile is set. Application will not use Keycloak authentication mechanism.
## Tests
Run [integration](api-gateway/src/integTest) and [unit tests](api-gateway/src/test) via IDE or with Gradle in command line:
```jshelllanguage
./gradlew test
```
...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request; ...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
public class DeleteMessageRequest extends AbstractDTO<String, ErrorDTO> { import java.util.UUID;
public class DeleteMessageRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteMessageRequest"; public static final String ROUTING_KEY = "api.DeleteMessageRequest";
......
...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request; ...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.messages.message.request;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
public class MessagesRequest extends AbstractDTO<String, ErrorDTO> { import java.util.UUID;
public class MessagesRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.MessagesRequest"; public static final String ROUTING_KEY = "api.MessagesRequest";
......
...@@ -6,7 +6,11 @@ import lombok.AllArgsConstructor; ...@@ -6,7 +6,11 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO<CreateProceedingInspectionDocumentPublicRequest.Parameters, ErrorDTO> { import java.util.UUID;
import static ee.sm.ti.teis.commongateway.proceedings.proceeding.request.CreateProceedingInspectionDocumentPublicRequest.Parameters;
public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest"; public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest";
@Override @Override
...@@ -18,7 +22,7 @@ public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO ...@@ -18,7 +22,7 @@ public class CreateProceedingInspectionDocumentPublicRequest extends AbstractDTO
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public static class Parameters { public static class Parameters {
private String proceedingId; private UUID proceedingId;
private String documentId; private String documentId;
} }
} }
...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.proceedings.proceeding.request; ...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.proceedings.proceeding.request;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
public class ProceedingInspectionDocumentsPublicRequest extends AbstractDTO<String, ErrorDTO> { import java.util.UUID;
public class ProceedingInspectionDocumentsPublicRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest"; public static final String ROUTING_KEY = "api.ProceedingInspectionDocumentsPublicRequest";
@Override @Override
......
...@@ -2,22 +2,14 @@ package ee.sm.ti.teis.commongateway.proceedings.violation; ...@@ -2,22 +2,14 @@ package ee.sm.ti.teis.commongateway.proceedings.violation;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
public class ViolationPublicRequest extends AbstractDTO<ViolationPublicRequest.Parameters, ErrorDTO> { import java.util.UUID;
public class ViolationPublicRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.ViolationPublicRequest"; public static final String ROUTING_KEY = "api.ViolationPublicRequest";
@Override @Override
public String routingKey() { public String routingKey() {
return ROUTING_KEY; return ROUTING_KEY;
} }
@Data
@AllArgsConstructor
@NoArgsConstructor
public static class Parameters {
private String violationId;
}
} }
...@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor; ...@@ -6,6 +6,8 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.UUID;
public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest.Parameters, ErrorDTO> { public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest.Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.ViolationsPublicRequest"; public static final String ROUTING_KEY = "api.ViolationsPublicRequest";
...@@ -19,7 +21,7 @@ public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest ...@@ -19,7 +21,7 @@ public class ViolationsPublicRequest extends AbstractDTO<ViolationsPublicRequest
@NoArgsConstructor @NoArgsConstructor
public static class Parameters { public static class Parameters {
private String proceduralActId; private UUID proceduralActId;
private String proceedingId; private UUID proceedingId;
} }
} }
...@@ -7,8 +7,11 @@ import lombok.Data; ...@@ -7,8 +7,11 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.util.List; import java.util.List;
import java.util.UUID;
public class CreateWebLinkRequest extends AbstractDTO<CreateWebLinkRequest.Parameters, ErrorDTO> { import static ee.sm.ti.teis.commongateway.weblink.CreateWebLinkRequest.Parameters;
public class CreateWebLinkRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.WebLinkRequest"; public static final String ROUTING_KEY = "api.WebLinkRequest";
@Override @Override
...@@ -21,6 +24,6 @@ public class CreateWebLinkRequest extends AbstractDTO<CreateWebLinkRequest.Param ...@@ -21,6 +24,6 @@ public class CreateWebLinkRequest extends AbstractDTO<CreateWebLinkRequest.Param
@NoArgsConstructor @NoArgsConstructor
public static class Parameters { public static class Parameters {
private List<String> url; private List<String> url;
private String id; private UUID id;
} }
} }
...@@ -8,7 +8,9 @@ import lombok.NoArgsConstructor; ...@@ -8,7 +8,9 @@ import lombok.NoArgsConstructor;
import java.util.UUID; import java.util.UUID;
public class DeleteWebLinkRequest extends AbstractDTO<DeleteWebLinkRequest.Parameters, ErrorDTO> { import static ee.sm.ti.teis.commongateway.weblink.DeleteWebLinkRequest.Parameters;
public class DeleteWebLinkRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteWebLinkRequest"; public static final String ROUTING_KEY = "api.DeleteWebLinkRequest";
@Override @Override
......
...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.weblink; ...@@ -3,7 +3,9 @@ package ee.sm.ti.teis.commongateway.weblink;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
public class WebLinksTestRequest extends AbstractDTO<String, ErrorDTO> { import java.util.UUID;
public class WebLinksTestRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.WebLinksTestRequest"; public static final String ROUTING_KEY = "api.WebLinksTestRequest";
@Override @Override
......
...@@ -37,4 +37,4 @@ dependencies { ...@@ -37,4 +37,4 @@ dependencies {
} }
// Define the main class for the application // Define the main class for the application
mainClassName = 'ee.sm.ti.teis.commongateway.CommonApiGateway' mainClassName = 'ee.sm.ti.teis.CommonApiGateway'
...@@ -19,9 +19,9 @@ import org.testcontainers.junit.jupiter.Testcontainers; ...@@ -19,9 +19,9 @@ import org.testcontainers.junit.jupiter.Testcontainers;
@ContextConfiguration(initializers = { CommonApiGatewayTestBase.Initializer.class }) @ContextConfiguration(initializers = { CommonApiGatewayTestBase.Initializer.class })
public abstract class CommonApiGatewayTestBase { public abstract class CommonApiGatewayTestBase {
private static GenericContainer rabbitMQContainer; private static final GenericContainer rabbitMQContainer;
// to speed up tests, lets use static container, it is used in alla test classes that are executed inside one Spring Context // to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context
static { static {
rabbitMQContainer = new GenericContainer("rabbitmq:latest").withExposedPorts(5672); rabbitMQContainer = new GenericContainer("rabbitmq:latest").withExposedPorts(5672);
rabbitMQContainer.start(); rabbitMQContainer.start();
......
...@@ -6,9 +6,8 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO; ...@@ -6,9 +6,8 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID;
import static java.util.Collections.emptyList; import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
public class AdminForTestingControllerTest extends CommonApiGatewayTestBase { public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
...@@ -16,10 +15,16 @@ public class AdminForTestingControllerTest extends CommonApiGatewayTestBase { ...@@ -16,10 +15,16 @@ public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
@Autowired @Autowired
AdminForTestingController controller; AdminForTestingController controller;
@Test
void resetMessageEmail_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.resetMessageEmail(randomUUID(), new RequestMetaDTO()));
}
@Test @Test
void getMessages_throwsException() { void getMessages_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.createFileReferences(UUID.randomUUID(), emptyList(), new RequestMetaDTO())); controller.createFileReferences(randomUUID(), emptyList(), new RequestMetaDTO()));
} }
} }
...@@ -8,8 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO; ...@@ -8,8 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import java.util.UUID; import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
public class MessageControllerTest extends CommonApiGatewayTestBase { public class MessageControllerTest extends CommonApiGatewayTestBase {
...@@ -20,13 +19,13 @@ public class MessageControllerTest extends CommonApiGatewayTestBase { ...@@ -20,13 +19,13 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test @Test
void getMessages() { void getMessages() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.getMessages("", new RequestMetaDTO())); controller.getMessages(randomUUID(), new RequestMetaDTO()));
} }
@Test @Test
void patch() { void patch() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.patch(UUID.randomUUID(), new PatchMessageDto(), new RequestMetaDTO())); controller.patch(randomUUID(), new PatchMessageDto(), new RequestMetaDTO()));
} }
@Test @Test
...@@ -38,7 +37,7 @@ public class MessageControllerTest extends CommonApiGatewayTestBase { ...@@ -38,7 +37,7 @@ public class MessageControllerTest extends CommonApiGatewayTestBase {
@Test @Test
void delete() { void delete() {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(UUID.randomUUID().toString(), new RequestMetaDTO())); controller.delete(randomUUID(), new RequestMetaDTO()));
} }
@Test @Test
......
...@@ -8,6 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO; ...@@ -8,6 +8,7 @@ import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
public class ClaimTestControllerTest extends CommonApiGatewayTestBase { public class ClaimTestControllerTest extends CommonApiGatewayTestBase {
...@@ -26,4 +27,10 @@ public class ClaimTestControllerTest extends CommonApiGatewayTestBase { ...@@ -26,4 +27,10 @@ public class ClaimTestControllerTest extends CommonApiGatewayTestBase {
assertThrows(NoResponseFromRabbitException.class, () -> assertThrows(NoResponseFromRabbitException.class, () ->
controller.patch(new PatchClaimDto(), new RequestMetaDTO())); controller.patch(new PatchClaimDto(), new RequestMetaDTO()));
} }
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(randomUUID(), randomUUID(), new RequestMetaDTO()));
}
} }
package ee.sm.ti.teis.commongateway.proceedings.proceeding.inspection.document;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ProceedingInspectionDocumentControllerTest extends CommonApiGatewayTestBase {
@Autowired
ProceedingInspectionDocumentController controller;
@Test
void deleteWebLink_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.deleteWebLink(
randomUUID(), randomUUID(), new RequestMetaDTO()));
}
@Test
void createDocument_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createDocument(
randomUUID(), new ClassifierItemLightDto(), new RequestMetaDTO()));
}
@Test
void createWebLinks_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.createWebLinks(
randomUUID(), List.of(""), new RequestMetaDTO()));
}
@Test
void getDocuments_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getDocuments(
randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.inspection.document;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class ProceedingInspectionDocumentTestControllerTest extends CommonApiGatewayTestBase {
@Autowired
ProceedingInspectionDocumentTestController controller;
@Test
void getWebLinks_throwsException() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getWebLinks(randomUUID(), new RequestMetaDTO()));
}
}
package ee.sm.ti.teis.commongateway.role;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
class RoleTestControllerTest extends CommonApiGatewayTestBase {
private static final RequestMetaDTO requestMetaDTO = RequestMetaDTO.builder().requestId(randomUUID().toString()).build();
@Autowired
RoleTestController controller;
@Test
void getPrivileges_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getPrivileges(List.of(randomUUID()), true, requestMetaDTO));
}
@Test
void getRoles_test() {
assertThrows(NoResponseFromRabbitException.class, () -> controller.getRoles("", "", "", requestMetaDTO));
}
}
package ee.sm.ti.teis.commongateway.security.auth;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.auth.UserCompanySelectionDto;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import static java.util.UUID.randomUUID;