Skip to content

Commit

Permalink
Revert pre-enforcement of live command responses
Browse files Browse the repository at this point in the history
Signed-off-by: Yannic Klem <yannic.klem@bosch.io>
  • Loading branch information
Yannic92 committed Jul 18, 2022
1 parent 988377f commit a749dce
Showing 1 changed file with 3 additions and 12 deletions.
Expand Up @@ -100,8 +100,7 @@ public Receive createReceive() {
.match(SudoCommand.class, sudoCommand -> log.withCorrelationId(sudoCommand)
.error("Received SudoCommand in enforcer which should never happen: <{}>", sudoCommand)
)
.match(CommandResponse.class, Signal::isChannelLive, r -> filterLiveResponse((R) r))
.match(CommandResponse.class, r -> filterTwinResponse((R) r))
.match(CommandResponse.class, r -> replyWithFilteredCommandResponse((R) r))
.match(Signal.class, s -> enforceSignal((S) s))
.matchAny(message ->
log.withCorrelationId(
Expand Down Expand Up @@ -193,21 +192,14 @@ private void handleAuthorizationFailure(
sender.tell(dittoRuntimeException, getSelf());
}

private void filterLiveResponse(final R liveResponse) {
Patterns.pipe(preEnforcer.apply(liveResponse)
.thenApply(preEnforced -> (R) preEnforced)
.thenCompose(this::filterResponse), getContext().dispatcher())
.to(sender());
}

/**
* Filters the response payload of the passed {@code commandResponse} using the {@code enforcement} of this actor.
* Filtered command responses are sent back to the {@code getSender()} - which is our dear parent, the Supervisor.
* Our parent is responsible for then forwarding the command response to the original sender.
*
* @param commandResponse the {@code CommandResponse} to filter based in the {@code policyEnforcer}.
*/
private void filterTwinResponse(final R commandResponse) {
private void replyWithFilteredCommandResponse(final R commandResponse) {
final ActorRef sender = getSender();
final ActorRef parent = getContext().parent();
if (enforcement.shouldFilterCommandResponse(commandResponse)) {
Expand All @@ -219,10 +211,9 @@ private void filterTwinResponse(final R commandResponse) {

/**
* Filters the response payload of the passed {@code commandResponse} using the {@code enforcement} of this actor.
* Filtered command responses are sent back to the {@code getSender()} - which is our dear parent, the Supervisor.
* Our parent is responsible for then forwarding the command response to the original sender.
*
* @param commandResponse the {@code CommandResponse} to filter based in the {@code policyEnforcer}.
* @return a completion stage holding the filtered command response.
*/
private CompletionStage<R> filterResponse(final R commandResponse) {
if (enforcement.shouldFilterCommandResponse(commandResponse)) {
Expand Down

0 comments on commit a749dce

Please sign in to comment.