-
Notifications
You must be signed in to change notification settings - Fork 0
Add webhooks config endpoint [ACC-2107] #144
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
Open
rschev
wants to merge
11
commits into
main
Choose a base branch
from
webhooks-endpoint
base: main
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.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c9f59a0
Add webhooks config endpoint [ACC-2107]
rschev d64a9a9
Events on db operations
rschev ea4fe27
wip setup for sending events
rschev 7eb7cb5
Fix layer dependencies so events can format as HAL [ACC-2107]
rschev e893c36
Send events over rabbitmq [ACC-2107]
rschev a2cae69
Add test for message formatting and dispatching
rschev 2c65369
Pass event handlers during runtime instead of startup
rschev 3d91593
Renaming and cleanup [ACC-2107]
rschev c72b69a
Add events for (un)linking relations [ACC-2107]
rschev 72948ff
Test events not being sent [ACC-2107]
rschev 59d42ef
Use HAL-json object mapper for event entities [ACC-2107]
rschev 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 hidden or 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
38 changes: 38 additions & 0 deletions
38
...tors/src/main/java/com/contentgrid/appserver/actuator/webhooks/WebhookConfigActuator.java
This file contains hidden or 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,38 @@ | ||
| package com.contentgrid.appserver.actuator.webhooks; | ||
|
|
||
| import java.io.FileNotFoundException; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.charset.StandardCharsets; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | ||
| import org.springframework.boot.actuate.endpoint.web.annotation.WebEndpoint; | ||
| import org.springframework.core.io.Resource; | ||
| import org.springframework.util.PropertyPlaceholderHelper; | ||
| import org.springframework.util.SystemPropertyUtils; | ||
|
|
||
| @WebEndpoint(id = "webhooks") | ||
| @RequiredArgsConstructor | ||
| public class WebhookConfigActuator { | ||
| private final Resource webhookResource; | ||
| private final WebhookVariables webhookVariables; | ||
| private static final PropertyPlaceholderHelper PROPERTY_PLACEHOLDER_HELPER = new PropertyPlaceholderHelper( | ||
| SystemPropertyUtils.PLACEHOLDER_PREFIX, | ||
| SystemPropertyUtils.PLACEHOLDER_SUFFIX | ||
| ); | ||
|
|
||
| @ReadOperation(producesFrom = WebhookConfigProducible.class) | ||
| public String getConfig() throws IOException { | ||
| if (webhookResource.exists()) { | ||
| String contents = readContents(webhookResource); | ||
| return PROPERTY_PLACEHOLDER_HELPER.replacePlaceholders(contents, webhookVariables); | ||
| } | ||
| throw new FileNotFoundException("webhook config file at " + webhookResource.getDescription() + " is not present"); | ||
| } | ||
|
|
||
| static String readContents(Resource resource) throws IOException { | ||
| try (InputStream resourceStream = resource.getInputStream()) { | ||
| return new String(resourceStream.readAllBytes(), StandardCharsets.UTF_8); | ||
| } | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...rs/src/main/java/com/contentgrid/appserver/actuator/webhooks/WebhookConfigProducible.java
This file contains hidden or 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,14 @@ | ||
| package com.contentgrid.appserver.actuator.webhooks; | ||
|
|
||
| import org.springframework.boot.actuate.endpoint.Producible; | ||
| import org.springframework.util.MimeType; | ||
|
|
||
| public enum WebhookConfigProducible implements Producible<WebhookConfigProducible> { | ||
|
|
||
| CONTENT_TYPE_WEBHOOK_CONFIG_V1 { | ||
| @Override | ||
| public MimeType getProducedMimeType() { | ||
| return MimeType.valueOf("application/vnd.contentgrid.webhooks.v1+json"); | ||
| } | ||
| } | ||
| } |
29 changes: 29 additions & 0 deletions
29
...actuators/src/main/java/com/contentgrid/appserver/actuator/webhooks/WebhookVariables.java
This file contains hidden or 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,29 @@ | ||
| package com.contentgrid.appserver.actuator.webhooks; | ||
|
|
||
| import com.contentgrid.appserver.actuator.ContentgridApplicationProperties.SystemProperties; | ||
| import java.util.Map; | ||
| import lombok.Builder; | ||
| import lombok.Value; | ||
| import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; | ||
|
|
||
| @Value | ||
| @Builder | ||
| public class WebhookVariables implements PlaceholderResolver { | ||
| SystemProperties systemProperties; | ||
| Map<String, String> userVariables; | ||
|
|
||
| @Override | ||
| public String resolvePlaceholder(String placeholderName) { | ||
| if (placeholderName.startsWith("vars.")) { | ||
| return userVariables.get(placeholderName.substring("vars.".length())); | ||
| } | ||
| switch(placeholderName) { | ||
| case "system.application.id": | ||
| return systemProperties.getApplicationId(); | ||
| case "system.deployment.id": | ||
| return systemProperties.getDeploymentId(); | ||
| default: | ||
| throw new IllegalArgumentException(String.format("Can not find a replacement for placeholder '%s'", placeholderName)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
1 change: 1 addition & 0 deletions
1
contentgrid-appserver-actuators/src/test/resources/eventhandler/webhooks.json
This file contains hidden or 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 @@ | ||
| {"webhooks":{"client":[{"filter": {"application_id": "${system.application.id}", "deployment_id": "${system.deployment.id}"}}]}} |
This file contains hidden or 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 hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
...va/com/contentgrid/appserver/autoconfigure/events/ContentGridEventsAutoConfiguration.java
This file contains hidden or 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,30 @@ | ||
| package com.contentgrid.appserver.autoconfigure.events; | ||
|
|
||
| import com.contentgrid.appserver.autoconfigure.query.engine.JOOQQueryEngineAutoConfiguration; | ||
| import com.contentgrid.appserver.domain.DomainEventDispatcher; | ||
| import com.contentgrid.appserver.domain.events.EntityFormatter; | ||
| import com.contentgrid.appserver.events.EventHandlerConfiguration; | ||
| import com.contentgrid.appserver.events.RabbitMqEventHandlers; | ||
| import org.springframework.beans.factory.ObjectProvider; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| @AutoConfiguration(before = { | ||
| JOOQQueryEngineAutoConfiguration.class, | ||
| }, after = { | ||
| RabbitAutoConfiguration.class, | ||
| }) | ||
| @ConditionalOnClass(EventHandlerConfiguration.class) | ||
| @Import(EventHandlerConfiguration.class) | ||
| public class ContentGridEventsAutoConfiguration { | ||
|
|
||
| @Bean | ||
| DomainEventDispatcher eventDispatcher(ObjectProvider<EntityFormatter> formatterProvider, ObjectProvider<RabbitMqEventHandlers> rabbitProvider) { | ||
| var formatter = formatterProvider.getIfAvailable(); | ||
| var rabbit = rabbitProvider.getIfAvailable(); | ||
| return new DomainEventDispatcher(formatter, rabbit); | ||
| } | ||
| } | ||
This file contains hidden or 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
19 changes: 19 additions & 0 deletions
19
...m/contentgrid/appserver/autoconfigure/rest/ContentGridRestFormatterAutoConfiguration.java
This file contains hidden or 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,19 @@ | ||
| package com.contentgrid.appserver.autoconfigure.rest; | ||
|
|
||
| import com.contentgrid.appserver.autoconfigure.events.ContentGridEventsAutoConfiguration; | ||
| import com.contentgrid.appserver.rest.ContentGridRestFormatterConfiguration; | ||
| import com.contentgrid.appserver.rest.EntityRestController; | ||
| import com.contentgrid.appserver.rest.assembler.EntityDataRepresentationModelAssembler; | ||
| import org.springframework.boot.autoconfigure.AutoConfiguration; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; | ||
| import org.springframework.context.annotation.Import; | ||
| import org.springframework.hateoas.RepresentationModel; | ||
|
|
||
| @AutoConfiguration(before = {ContentGridEventsAutoConfiguration.class}) | ||
| @ConditionalOnWebApplication(type = Type.SERVLET) | ||
| @ConditionalOnClass({EntityRestController.class, RepresentationModel.class, EntityDataRepresentationModelAssembler.class}) | ||
| @Import(ContentGridRestFormatterConfiguration.class) | ||
| public class ContentGridRestFormatterAutoConfiguration { | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
This does not have any conditional annotations that depend on
RabbitAutoConfigurationhaving run, so that dependency is not necessary.And the
beforeordering should probably be anafterordering onJOOQQueryEngineAutoConfiguration, because that is the configuration that has a dependency on this. Inverting the ordering like this is a bit confusingThere 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.
Without
after = RabbitAutoConfiguration, the ObjectProvider will always be empty.With
after = JOOQinstead of before, it will have a duplicate bean with the noopEventHandlers.