Add hooks so spam filters can register Dropwizard commands

This commit is contained in:
Jon Chambers
2025-11-21 12:37:05 -05:00
committed by Jon Chambers
parent 4d5cc4dc22
commit 1ce1c298d3
2 changed files with 17 additions and 0 deletions

View File

@@ -355,6 +355,12 @@ public class WhisperServerService extends Application<WhisperServerConfiguration
new IdleDeviceNotificationSchedulerFactory()));
bootstrap.addCommand(new RegenerateSecondaryDynamoDbTableDataCommand());
ServiceLoader.load(SpamFilter.class)
.stream()
.map(ServiceLoader.Provider::get)
.flatMap(spamFilter -> spamFilter.getCommands().stream())
.forEach(bootstrap::addCommand);
}
@Override

View File

@@ -6,10 +6,13 @@
package org.whispersystems.textsecuregcm.spam;
import io.dropwizard.configuration.ConfigurationValidationException;
import io.dropwizard.core.cli.ConfiguredCommand;
import io.dropwizard.lifecycle.Managed;
import jakarta.validation.Validator;
import java.io.IOException;
import java.util.Collection;
import java.util.function.Function;
import org.whispersystems.textsecuregcm.WhisperServerConfiguration;
import org.whispersystems.textsecuregcm.captcha.CaptchaClient;
import org.whispersystems.textsecuregcm.storage.ReportedMessageListener;
@@ -35,6 +38,14 @@ public interface SpamFilter extends Managed {
*/
void configure(String environmentName, Validator validator) throws IOException, ConfigurationValidationException;
/**
* Returns a collection of commands provided by this spam filter. Note that this method may be called before
* {@link #configure(String, Validator)}.
*
* @return a collection of commands provided by this spam filter
*/
Collection<ConfiguredCommand<WhisperServerConfiguration>> getCommands();
/**
* Return a reported message listener controlled by the spam filter. Listeners will be registered with the
* {@link org.whispersystems.textsecuregcm.storage.ReportMessageManager}.