Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed idgen and encryption endpoints and health check #268

Merged
merged 3 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ services:
- connectionInfo_username=postgres
- connectionInfo_password=postgres
- encryption_enabled=${ENCRYPTION_ENABLED-false}
- encryption_health_check_url=http://encryption-service:8013/health
- encryption_uri=http://encryption-service:8013/crypto/v1/_encrypt
- encryption_batch_uri=http://encryption-service:8013/crypto/v1/_encrypt
- event_enabled=${EVENT_ENABLED-false}
- event_topic=events
- event_providerName=dev.sunbirdrc.registry.service.impl.KafkaEventService
Expand All @@ -63,6 +66,10 @@ services:
- oauth2_resource_uri=${oauth2_resource_uri-http://keycloak:8080/auth/realms/sunbird-rc}
- oauth2_resource_roles_path=${oauth2_resource_roles_path-realm_access.roles}
- identity_provider=${identity_provider-dev.sunbirdrc.auth.keycloak.KeycloakProviderImpl}
- idgen_enabled=${IDGEN_ENABLED-false}
- idgen_health_check_url=http://id-gen-service:8088/egov-idgen/health
- idgen_generate_url=http://id-gen-service:8088/egov-idgen/id/_generate
- idgen_id_format_url=http://id-gen-service:8088/egov-idgen/id/_format/add
- sunbird_sso_admin_client_id=${KEYCLOAK_ADMIN_CLIENT_ID-admin-api}
- sunbird_sso_client_id=${KEYCLOAK_CLIENT_ID-registry-frontend}
- sunbird_sso_admin_client_secret=${KEYCLOAK_SECRET}
Expand Down Expand Up @@ -381,6 +388,7 @@ services:
spring.flyway.url: jdbc:postgresql://db:5432/registry
egov.mdms.provider: org.egov.enc.masterdata.provider.DBMasterDataProvider
spring.flyway.baseline-on-migrate: "true"
management.endpoints.web.base-path: /
depends_on:
db:
condition: service_healthy
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,13 @@ private JsonNode getUserInfoFromRegistry(HttpServletRequest request, String enti
watch.start("RegistryController.searchEntity");
JsonNode result = searchEntity(payload);
watch.stop("RegistryController.searchEntity");
if(result != null && result.get(entityName) != null && !result.get(entityName).isEmpty()) {
String uuid = result.get(entityName).get(0).get(uuidPropertyName).asText();
JsonNode user = readEntity(userId, entityName, uuid, true, null, false);
ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
arrayNode.add(user.get(entityName));
((ObjectNode) result).set(entityName, arrayNode);
}
return result;
}
throw new Exception("Forbidden");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import dev.sunbirdrc.pojos.ComponentHealthInfo;
import dev.sunbirdrc.pojos.SunbirdRCInstrumentation;
import dev.sunbirdrc.registry.exception.EncryptionException;
import dev.sunbirdrc.registry.middleware.util.JSONUtil;
import dev.sunbirdrc.registry.service.EncryptionService;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger;
Expand All @@ -23,6 +24,7 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;

import java.io.IOException;
import java.util.*;

import static dev.sunbirdrc.registry.middleware.util.Constants.CONNECTION_FAILURE;
Expand Down Expand Up @@ -165,13 +167,13 @@ public ComponentHealthInfo getHealthInfo() {
if (encryptionEnabled) {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(encryptionServiceHealthCheckUri);
if (!StringUtils.isEmpty(response.getBody()) && response.getBody().equalsIgnoreCase("UP")) {
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
logger.debug("Encryption service running !");
return new ComponentHealthInfo(getServiceName(), true);
} else {
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, response.getBody());
}
} catch (RestClientException ex) {
} catch (RestClientException | IOException ex) {
logger.error("RestClientException when checking the health of the encryption service: {}", ExceptionUtils.getStackTrace(ex));
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.springframework.web.client.ResourceAccessException;
import org.springframework.web.client.RestClientException;

import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -144,13 +145,13 @@ public ComponentHealthInfo getHealthInfo() {
if (enabled) {
try {
ResponseEntity<String> response = retryRestTemplate.getForEntity(healthCheckUrl);
if (!StringUtils.isEmpty(response.getBody()) && response.getBody().equalsIgnoreCase("UP")) {
if (!StringUtils.isEmpty(response.getBody()) && JSONUtil.convertStringJsonNode(response.getBody()).get("status").asText().equalsIgnoreCase("UP")) {
logger.debug(" running !");
return new ComponentHealthInfo(getServiceName(), true);
} else {
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, response.getBody());
}
} catch (RestClientException ex) {
} catch (RestClientException | IOException ex) {
logger.error("RestClientException when checking the health of the idgen service: {}", ExceptionUtils.getStackTrace(ex));
return new ComponentHealthInfo(getServiceName(), false, CONNECTION_FAILURE, ex.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void test_decrypt_api_map_param_throwing_resource_exception() throws Exce

@Test
public void test_encryption_isup() throws Exception {
when(retryRestTemplate.getForEntity(nullable(String.class))).thenReturn(ResponseEntity.accepted().body("UP"));
when(retryRestTemplate.getForEntity(nullable(String.class))).thenReturn(ResponseEntity.accepted().body("{\"status\": \"UP\"}"));
assertTrue(encryptionServiceImpl.isEncryptionServiceUp());
}

Expand Down
Loading