Skip to content

Commit

Permalink
[ISSUE #4243] Optimize Webhook Manufacturer source Hard-coding (#4273)
Browse files Browse the repository at this point in the history
* feat: Add manufacturerDomain field and its setter

* chore: fix hard-coding in WebHookProcessor

* feat: Remove redundant cloudEventSource field which shouldn't belong to WebHookConfig
  • Loading branch information
Pil0tXia committed Jul 27, 2023
1 parent e5915f7 commit 3652000
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import org.apache.eventmesh.runtime.common.EventMeshTrace;
import org.apache.eventmesh.runtime.util.HttpResponseUtils;
import org.apache.eventmesh.webhook.api.WebHookOperationConstant;
import org.apache.eventmesh.webhook.receive.WebHookController;

import java.util.HashMap;
Expand All @@ -40,7 +41,7 @@ public class WebHookProcessor implements HttpProcessor {

@Override
public String[] paths() {
return new String[]{"/webhook"};
return new String[]{WebHookOperationConstant.CALLBACK_PATH_PREFIX};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ private WebHookConfig buildMockWebhookConfig() {
WebHookConfig config = new WebHookConfig();
config.setCallbackPath("/webhook/github/eventmesh/all");
config.setManufacturerName("github");
config.setManufacturerDomain("www.github.com");
config.setManufacturerEventName("ForkEvent");
config.setContentType("application/json");
config.setSecret("secret");
config.setCloudEventSource("github");
config.setCloudEventName("github-eventmesh");
config.setCloudEventIdGenerateMode("uuid");
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ public void testInsertWebHookConfig() {
WebHookConfig config = new WebHookConfig();
config.setCallbackPath("/webhook/github/eventmesh/all");
config.setManufacturerName("github");
config.setManufacturerDomain("www.github.com");
config.setManufacturerEventName("all");
config.setSecret("eventmesh");
config.setCloudEventName("github-eventmesh");
config.setCloudEventSource("github");

try {
FileWebHookConfigOperation fileWebHookConfigOperation = new FileWebHookConfigOperation(properties);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public class WebHookConfig {
*/
private String manufacturerName;

/**
* manufacturer domain name, like www.github.com
*/
private String manufacturerDomain;

/**
* webhook event name, like rep-push
*/
Expand Down Expand Up @@ -82,11 +87,6 @@ public class WebHookConfig {
*/
private String dataContentType = "application/json";

/**
* source of event
*/
private String cloudEventSource;

/**
* id of cloudEvent, like uuid/manufacturerEventId
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void execute(String path, Map<String, String> header, byte[] body) throws

WebhookProtocolTransportObject webhookProtocolTransportObject = WebhookProtocolTransportObject.builder()
.cloudEventId(cloudEventId).eventType(eventType).cloudEventName(webHookConfig.getCloudEventName())
.cloudEventSource("www." + webHookConfig.getManufacturerName() + ".com")
.cloudEventSource(webHookConfig.getManufacturerDomain())
.dataContentType(webHookConfig.getDataContentType()).body(body).build();

// 4. send cloudEvent
Expand Down

0 comments on commit 3652000

Please sign in to comment.