Skip to content

Commit

Permalink
Allow custom configuration for the CustomConnectivityCommandIntercept…
Browse files Browse the repository at this point in the history
…orProvider extension

Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Jul 12, 2022
1 parent 3cd249d commit 21867b5
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1196,8 +1196,10 @@ private ConnectivityCommandInterceptor getCommandValidator() {
connectionValidator,
actorSystem);

final Config dittoExtensionsConfig = ScopedConfig.dittoExtension(actorSystem.settings().config());
final var customCommandValidator =
CustomConnectivityCommandInterceptorProvider.get(actorSystem).getCommandInterceptor();
CustomConnectivityCommandInterceptorProvider.get(actorSystem, dittoExtensionsConfig)
.getCommandInterceptor();
return new CompoundConnectivityCommandInterceptor(dittoCommandValidator, customCommandValidator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

import org.eclipse.ditto.base.service.DittoExtensionIds;
import org.eclipse.ditto.base.service.DittoExtensionPoint;
import org.eclipse.ditto.connectivity.model.signals.commands.ConnectivityCommandInterceptor;

import com.typesafe.config.Config;

import akka.actor.ActorSystem;

public interface CustomConnectivityCommandInterceptorProvider extends DittoExtensionPoint {
Expand All @@ -28,21 +31,30 @@ public interface CustomConnectivityCommandInterceptorProvider extends DittoExten
* {@code ActorSystem}.
*
* @param actorSystem the actorSystem in which the {@code CustomConnectivityCommandInterceptorProvider} should be loaded.
* @param config the configuration of this extension.
* @return the {@code CustomConnectivityCommandInterceptorProvider} implementation.
* @throws NullPointerException if {@code actorSystem} is {@code null}.
*/
static CustomConnectivityCommandInterceptorProvider get(final ActorSystem actorSystem) {
static CustomConnectivityCommandInterceptorProvider get(final ActorSystem actorSystem, final Config config) {
checkNotNull(actorSystem, "actorSystem");
return ExtensionId.INSTANCE.get(actorSystem);
checkNotNull(config, "config");
final var extensionIdConfig = ExtensionId.computeConfig(config);
return DittoExtensionIds.get(actorSystem)
.computeIfAbsent(extensionIdConfig, ExtensionId::new)
.get(actorSystem);
}

final class ExtensionId extends DittoExtensionPoint.ExtensionId<CustomConnectivityCommandInterceptorProvider> {

private static final String CONFIG_PATH = "ditto.connectivity.connection.custom-command-interceptor-provider";
private static final ExtensionId INSTANCE = new ExtensionId(CustomConnectivityCommandInterceptorProvider.class);
private static final String CONFIG_KEY = "custom-connectivity-command-interceptor-provider";
private static final String CONFIG_PATH = "ditto.extensions." + CONFIG_KEY;

private ExtensionId(final ExtensionIdConfig<CustomConnectivityCommandInterceptorProvider> extensionIdConfig) {
super(extensionIdConfig);
}

private ExtensionId(final Class<CustomConnectivityCommandInterceptorProvider> parentClass) {
super(parentClass);
static ExtensionIdConfig<CustomConnectivityCommandInterceptorProvider> computeConfig(final Config config) {
return ExtensionIdConfig.of(CustomConnectivityCommandInterceptorProvider.class, config, CONFIG_KEY);
}

@Override
Expand Down
6 changes: 2 additions & 4 deletions connectivity/service/src/main/resources/connectivity.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ ditto {
}
}
connection-enforcer-actor-props-factory = org.eclipse.ditto.connectivity.service.enforcement.NoOpEnforcerActorPropsFactory
# Provider for a custom connectivity-command interceptor.
custom-connectivity-command-interceptor-provider = "org.eclipse.ditto.connectivity.service.messaging.validation.NoOpConnectivityCommandInterceptorProvider"
}

persistence.operations.delay-after-persistence-actor-shutdown = 5s
Expand Down Expand Up @@ -175,10 +177,6 @@ ditto {
double-decoding-enabled = true
double-decoding-enabled = ${?CONNECTIVITY_DOUBLE_DECODING_ENABLED}

# Provider for a custom connectivity-command interceptor.
custom-command-interceptor-provider = "org.eclipse.ditto.connectivity.service.messaging.validation.NoOpConnectivityCommandInterceptorProvider"
custom-command-interceptor-provider = ${?CONNECTIVITY_CUSTOM_COMMAND_INTERCEPTOR_PROVIDER}

acknowledgement {
# lifetime of ack forwarder. Must be bigger than the largest possible command timeout (60s)
forwarder-fallback-timeout = 65s
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public final class ConnectionPersistenceActorTest extends WithMockServers {
ConfigFactory.parseMap(Map.of(
"ditto.extensions.client-actor-props-factory",
"org.eclipse.ditto.connectivity.service.messaging.MockClientActorPropsFactory",
"ditto.connectivity.connection.custom-command-interceptor-provider",
"ditto.extensions.custom-connectivity-command-interceptor-provider",
"org.eclipse.ditto.connectivity.service.messaging.ExceptionalCommandValidator"
)).withFallback(TestConstants.CONFIG));

Expand Down
2 changes: 1 addition & 1 deletion connectivity/service/src/test/resources/test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ditto {
}
}
connection-enforcer-actor-props-factory = org.eclipse.ditto.connectivity.service.enforcement.NoOpEnforcerActorPropsFactory
custom-connectivity-command-interceptor-provider = org.eclipse.ditto.connectivity.service.messaging.validation.NoOpConnectivityCommandInterceptorProvider
}
mapping-strategy.implementation = "org.eclipse.ditto.connectivity.api.ConnectivityMappingStrategies"
pre-enforcers = [
Expand Down Expand Up @@ -58,7 +59,6 @@ ditto {
{exceptionName: "org.apache.qpid.jms.provider.exceptions.ProviderSecurityException", messagePattern: ".*"}
]
connection {
custom-command-interceptor-provider = org.eclipse.ditto.connectivity.service.messaging.validation.NoOpConnectivityCommandInterceptorProvider
// allow localhost in unit tests
blocked-hostnames = ""

Expand Down

0 comments on commit 21867b5

Please sign in to comment.