You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by "HoussemNasri (via GitHub)" <gi...@apache.org> on 2023/02/22 10:56:17 UTC

[GitHub] [james-project] HoussemNasri commented on a diff in pull request #1453: JAMES-2601 Implement a LDAP healthCheck

HoussemNasri commented on code in PR #1453:
URL: https://github.com/apache/james-project/pull/1453#discussion_r1114164465


##########
server/data/data-ldap/src/main/java/org/apache/james/user/ldap/LdapHealthCheck.java:
##########
@@ -0,0 +1,38 @@
+package org.apache.james.user.ldap;
+
+import javax.inject.Inject;
+
+import org.apache.james.core.Username;
+import org.apache.james.core.healthcheck.ComponentName;
+import org.apache.james.core.healthcheck.HealthCheck;
+import org.apache.james.core.healthcheck.Result;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import reactor.core.publisher.Mono;
+
+public class LdapHealthCheck implements HealthCheck {
+    public static final ComponentName COMPONENT_NAME = new ComponentName("LDAP User Server");
+    public static final Username LDAP_TEST_USER = Username.of("ldap-test");
+    private static final Logger LOGGER = LoggerFactory.getLogger(LdapHealthCheck.class);
+
+    private final ReadOnlyUsersLDAPRepository ldapUserRepository;
+
+    @Inject
+    public LdapHealthCheck(ReadOnlyUsersLDAPRepository ldapUserRepository) {
+        this.ldapUserRepository = ldapUserRepository;
+    }
+
+    @Override
+    public ComponentName componentName() {
+        return COMPONENT_NAME;
+    }
+
+    @Override
+    public Mono<Result> check() {
+        return Mono.fromCallable(() -> ldapUserRepository.getUserByName(LDAP_TEST_USER))

Review Comment:
   > Please handle the case "user not found" and return healthy in this case
   
   I think it's already handled. Since `getUserByName` returns null if the user is not found, so the final result should be healthy as long the repository method doesn't throw an exception. This is the first time I use the reactor library, so there might be a flaw in my logic.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org