Updated Database health_check

This commit is contained in:
Francesco Mangiacrapa 2024-10-23 15:57:33 +02:00
parent faffb42483
commit 4d0df2de07
2 changed files with 8 additions and 2 deletions

View File

@ -108,7 +108,7 @@ public class GeoportalHealth {
public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException { public Response databaseCheck(@QueryParam("context") String context) throws JsonProcessingException {
log.debug("databaseCheck called in the context {}", context); log.debug("databaseCheck called in the context {}", context);
if (context == null) { if (context == null) {
HealthCheckResponse response = HealthCheckResponse.named(MongoHealthCheck.SERVICE_NAME) HealthCheckResponse response = HealthCheckResponse.named(DatabaseHealthCheck.SERVICE_NAME)
.withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build(); .withData("context", "is required parameter (e.g. context=/gcube/devsec/devVRE)").down().build();
String json = healthCheckSerializer(response); String json = healthCheckSerializer(response);
log.info("databaseCheck error response is {}", json); log.info("databaseCheck error response is {}", json);

View File

@ -114,7 +114,13 @@ public class DatabaseHealthCheck implements HealthCheck {
private HealthCheckResponseBuilder appendDBInfo(HealthCheckResponseBuilder buildHCRBuilder, private HealthCheckResponseBuilder appendDBInfo(HealthCheckResponseBuilder buildHCRBuilder,
DatabaseConnection connection) { DatabaseConnection connection) {
buildHCRBuilder.withData("host", connection.getUrl() + ""); buildHCRBuilder.withData("host", connection.getUrl() + "");
buildHCRBuilder.withData("user ", connection.getUser());
// anonymize the DB username
String userNotClear = "***";
if (connection.getUser() != null && connection.getUser().length() > 3) {
userNotClear = connection.getUser().substring(0, 3) + userNotClear;
}
buildHCRBuilder.withData("user ", userNotClear);
buildHCRBuilder.withData("pwd ", "****"); buildHCRBuilder.withData("pwd ", "****");
return buildHCRBuilder; return buildHCRBuilder;
} }