Add internal API to manually invoke invitation manager.
This commit is contained in:
@@ -212,3 +212,8 @@ threepid:
|
||||
# resolution:
|
||||
# timer: 10
|
||||
# period: seconds # search invites every 10 seconds (by default 5 minutes)
|
||||
|
||||
|
||||
# Internal API
|
||||
#internal:
|
||||
# enabled: true # default to false
|
||||
|
@@ -58,6 +58,7 @@ import io.kamax.mxisd.http.undertow.handler.identity.v1.BulkLookupHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.identity.v1.SingleLookupHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.identity.v2.HashDetailsHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.identity.v2.HashLookupHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.internal.InternalInviteManagerHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.invite.v1.RoomInviteHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.profile.v1.InternalProfileHandler;
|
||||
import io.kamax.mxisd.http.undertow.handler.profile.v1.ProfileHandler;
|
||||
@@ -147,6 +148,11 @@ public class HttpMxisd {
|
||||
termsEndpoints(handler);
|
||||
hashEndpoints(handler);
|
||||
accountEndpoints(handler);
|
||||
|
||||
if (m.getConfig().getInternal().isEnabled()) {
|
||||
handler.get(InternalInviteManagerHandler.PATH, new InternalInviteManagerHandler(m.getInvite()));
|
||||
}
|
||||
|
||||
ServerConfig serverConfig = m.getConfig().getServer();
|
||||
httpSrv = Undertow.builder().addHttpListener(serverConfig.getPort(), serverConfig.getHostname()).setHandler(handler).build();
|
||||
|
||||
|
24
src/main/java/io/kamax/mxisd/config/InternalAPIConfig.java
Normal file
24
src/main/java/io/kamax/mxisd/config/InternalAPIConfig.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package io.kamax.mxisd.config;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class InternalAPIConfig {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(InternalAPIConfig.class);
|
||||
|
||||
private boolean enabled = false;
|
||||
|
||||
public boolean isEnabled() {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
public void build() {
|
||||
log.info("--- Internal API config ---");
|
||||
log.info("Internal API enabled: {}", isEnabled());
|
||||
}
|
||||
}
|
@@ -118,6 +118,7 @@ public class MxisdConfig {
|
||||
private PolicyConfig policy = new PolicyConfig();
|
||||
private HashingConfig hashing = new HashingConfig();
|
||||
private LoggingConfig logging = new LoggingConfig();
|
||||
private InternalAPIConfig internal = new InternalAPIConfig();
|
||||
|
||||
public AppServiceConfig getAppsvc() {
|
||||
return appsvc;
|
||||
@@ -358,6 +359,14 @@ public class MxisdConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
public InternalAPIConfig getInternal() {
|
||||
return internal;
|
||||
}
|
||||
|
||||
public void setInternal(InternalAPIConfig internal) {
|
||||
this.internal = internal;
|
||||
}
|
||||
|
||||
public MxisdConfig build() {
|
||||
getLogging().build();
|
||||
|
||||
@@ -394,6 +403,7 @@ public class MxisdConfig {
|
||||
getWordpress().build();
|
||||
getPolicy().build();
|
||||
getHashing().build(getMatrix());
|
||||
getInternal().build();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@@ -82,6 +82,7 @@ public class SaneHandler extends BasicHttpHandler {
|
||||
} catch (InvalidJsonException e) {
|
||||
respond(exchange, HttpStatus.SC_BAD_REQUEST, e.getErrorCode(), e.getError());
|
||||
} catch (InvalidCredentialsException e) {
|
||||
log.error("Unauthorized: ", e);
|
||||
respond(exchange, HttpStatus.SC_UNAUTHORIZED, "M_UNAUTHORIZED", e.getMessage());
|
||||
} catch (TermsNotSignedException e) {
|
||||
respond(exchange, HttpStatus.SC_FORBIDDEN, "M_TERMS_NOT_SIGNED", e.getMessage());
|
||||
|
@@ -0,0 +1,30 @@
|
||||
package io.kamax.mxisd.http.undertow.handler.internal;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import io.kamax.mxisd.http.undertow.handler.BasicHttpHandler;
|
||||
import io.kamax.mxisd.invitation.InvitationManager;
|
||||
import io.undertow.server.HttpServerExchange;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class InternalInviteManagerHandler extends BasicHttpHandler {
|
||||
|
||||
public static final String PATH = "/_ma1sd/internal/admin/inv_manager";
|
||||
|
||||
private final InvitationManager invitationManager;
|
||||
private final ExecutorService executors = Executors.newFixedThreadPool(1);
|
||||
|
||||
public InternalInviteManagerHandler(InvitationManager invitationManager) {
|
||||
this.invitationManager = invitationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleRequest(HttpServerExchange exchange) throws Exception {
|
||||
executors.submit(invitationManager::doMaintenance);
|
||||
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("result", "ok");
|
||||
respond(exchange, obj);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user