-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RHCLOUD-32506] Send relevant data from incoming payloads to Kessel #2700
Open
g-duval
wants to merge
1
commit into
RedHatInsights:master
Choose a base branch
from
g-duval:kesselPoc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+495
−275
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...rc/main/java/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteria.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.redhat.cloud.notifications.processors; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.databind.PropertyNamingStrategies; | ||
import com.fasterxml.jackson.databind.annotation.JsonNaming; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.Objects; | ||
|
||
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class ExternalAuthorizationCriteria { | ||
|
||
@NotNull | ||
private String assetType; | ||
|
||
@NotNull | ||
private String assetId; | ||
|
||
@NotNull | ||
private String relation; | ||
|
||
public ExternalAuthorizationCriteria(String assetType, String assetId, String relation) { | ||
this.assetType = assetType; | ||
this.assetId = assetId; | ||
this.relation = relation; | ||
} | ||
|
||
public @NotNull String getAssetType() { | ||
return assetType; | ||
} | ||
|
||
public @NotNull String getAssetId() { | ||
return assetId; | ||
} | ||
|
||
public @NotNull String getRelation() { | ||
return relation; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (o == null || getClass() != o.getClass()) { | ||
return false; | ||
} | ||
ExternalAuthorizationCriteria that = (ExternalAuthorizationCriteria) o; | ||
return Objects.equals(assetType, that.assetType) && Objects.equals(assetId, that.assetId) && Objects.equals(relation, that.relation); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(assetType, assetId, relation); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...ava/com/redhat/cloud/notifications/processors/ExternalAuthorizationCriteriaExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.redhat.cloud.notifications.processors; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.redhat.cloud.notifications.models.EmailAggregation; | ||
import com.redhat.cloud.notifications.models.Event; | ||
import com.redhat.cloud.notifications.transformers.BaseTransformer; | ||
import io.quarkus.logging.Log; | ||
import io.vertx.core.json.JsonObject; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
@ApplicationScoped | ||
public class ExternalAuthorizationCriteriaExtractor { | ||
|
||
public static final String EXTERNAL_AUTHORIZATION_CRITERIA = "authorization"; | ||
|
||
@Inject | ||
BaseTransformer baseTransformer; | ||
|
||
@Inject | ||
ObjectMapper objectMapper; | ||
|
||
public ExternalAuthorizationCriteria extract(Event event) { | ||
return extract(baseTransformer.toJsonObject(event)); | ||
} | ||
|
||
public ExternalAuthorizationCriteria extract(EmailAggregation emailAggregation) { | ||
return extract(emailAggregation.getPayload()); | ||
} | ||
|
||
private ExternalAuthorizationCriteria extract(JsonObject data) { | ||
if (null != data.getJsonObject(BaseTransformer.CONTEXT) && null != data.getJsonObject(BaseTransformer.CONTEXT).getJsonObject(EXTERNAL_AUTHORIZATION_CRITERIA)) { | ||
try { | ||
return objectMapper.convertValue(data.getJsonObject(BaseTransformer.CONTEXT).getJsonObject(EXTERNAL_AUTHORIZATION_CRITERIA), ExternalAuthorizationCriteria.class); | ||
} catch (IllegalArgumentException e) { | ||
Log.error("Error parsing authorization criteria", e); | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,8 @@ | |
import com.redhat.cloud.notifications.models.Event; | ||
import com.redhat.cloud.notifications.models.InstantEmailTemplate; | ||
import com.redhat.cloud.notifications.processors.ConnectorSender; | ||
import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriteria; | ||
import com.redhat.cloud.notifications.processors.ExternalAuthorizationCriteriaExtractor; | ||
import com.redhat.cloud.notifications.processors.SystemEndpointTypeProcessor; | ||
import com.redhat.cloud.notifications.processors.email.connector.dto.EmailNotification; | ||
import com.redhat.cloud.notifications.processors.email.connector.dto.RecipientSettings; | ||
|
@@ -51,6 +53,9 @@ public class EmailProcessor extends SystemEndpointTypeProcessor { | |
@Inject | ||
SubscriptionRepository subscriptionRepository; | ||
|
||
@Inject | ||
ExternalAuthorizationCriteriaExtractor externalAuthorizationCriteriaExtractor; | ||
|
||
@Override | ||
public void process(final Event event, final List<Endpoint> endpoints) { | ||
// Generate an aggregation if the event supports it. | ||
|
@@ -63,6 +68,8 @@ public void process(final Event event, final List<Endpoint> endpoints) { | |
return; | ||
} | ||
|
||
ExternalAuthorizationCriteria externalAuthorizationCriteria = externalAuthorizationCriteriaExtractor.extract(event); | ||
|
||
Set<String> subscribers; | ||
Set<String> unsubscribers; | ||
if (event.getEventType().isSubscribedByDefault()) { | ||
|
@@ -111,7 +118,8 @@ public void process(final Event event, final List<Endpoint> endpoints) { | |
recipientSettings, | ||
subscribers, | ||
unsubscribers, | ||
event.getEventType().isSubscribedByDefault() | ||
event.getEventType().isSubscribedByDefault(), | ||
externalAuthorizationCriteria | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can move the |
||
); | ||
|
||
final JsonObject payload = JsonObject.mapFrom(emailNotification); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can move the
externalAuthorizationCriteriaExtractor.extract(aggregation);
to here, no? Since we are not using that criteria for anything else.