You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@eventmesh.apache.org by GitBox <gi...@apache.org> on 2022/02/23 02:32:13 UTC

[GitHub] [incubator-eventmesh] ruanwenjun commented on a change in pull request #772: [Issue #658] Eventmesh Http Support CloudEvents Webhook spec

ruanwenjun commented on a change in pull request #772:
URL: https://github.com/apache/incubator-eventmesh/pull/772#discussion_r812513188



##########
File path: eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPClientPool.java
##########
@@ -19,16 +19,40 @@
 
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.commons.lang3.RandomUtils;
+import org.apache.http.config.Registry;
+import org.apache.http.config.RegistryBuilder;
+import org.apache.http.conn.socket.ConnectionSocketFactory;
+import org.apache.http.conn.socket.PlainConnectionSocketFactory;
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
+import org.apache.http.impl.DefaultConnectionReuseStrategy;
 import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.DefaultConnectionKeepAliveStrategy;
+import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
 import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
+import org.apache.http.ssl.SSLContexts;
+import org.apache.http.ssl.TrustStrategy;
 
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.X509Certificate;
 import java.util.Iterator;
 import java.util.List;
+import java.util.concurrent.TimeUnit;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.SSLContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import com.google.common.collect.Lists;
 
 public class HTTPClientPool {
 
+    public Logger logger = LoggerFactory.getLogger(this.getClass());
+
     private List<CloseableHttpClient> clients = Lists.newArrayList();

Review comment:
       It's better to use synchronizeList to avoid concurrent problem.

##########
File path: eventmesh-common/src/main/java/org/apache/eventmesh/common/Constants.java
##########
@@ -35,7 +35,7 @@
 
     public static final String PROTOCOL_DESC = "protocoldesc";
 
-    public static final int DEFAULT_HTTP_TIME_OUT = 3000;
+    public static final int DEFAULT_HTTP_TIME_OUT = 15000;

Review comment:
       Why change this value? It's better to add comment(This is a history issue, but please add comment here)

##########
File path: eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/auth/AuthService.java
##########
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.api.auth;
+
+import org.apache.eventmesh.api.exception.AuthException;
+import org.apache.eventmesh.spi.EventMeshExtensionType;
+import org.apache.eventmesh.spi.EventMeshSPI;
+
+import java.util.Map;
+
+/**
+ * AuthService
+ */
+@EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.SECURITY)
+public interface AuthService {
+
+    void init() throws AuthException;
+
+    void start() throws AuthException;
+
+    void shutdown() throws AuthException;
+
+    Map getAuthParams() throws AuthException;

Review comment:
       It seems the return result is always `Map<String, String>`?
   It might be better to add generic type.
   ```suggestion
   Map<String, String> getAuthParams() throws AuthException;
   ```

##########
File path: eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/WebhookUtil.java
##########
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.runtime.util;
+
+import org.apache.eventmesh.api.auth.AuthService;
+import org.apache.eventmesh.spi.EventMeshExtensionFactory;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpOptions;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.message.BasicHeader;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility class for implementing CloudEvents Http Webhook spec
+ *
+ * @see <a href="https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/http-webhook.md">CloudEvents Http Webhook</a>
+ */
+public class WebhookUtil {
+
+    private static final Logger logger = LoggerFactory.getLogger(WebhookUtil.class.getName());
+
+    private static final String CONTENT_TYPE_HEADER = "Content-Type";
+    private static final String REQUEST_ORIGIN_HEADER = "WebHook-Request-Origin";
+    private static final String ALLOWED_ORIGIN_HEADER = "WebHook-Allowed-Origin";
+
+    private static final Map<String, AuthService> authServices = new ConcurrentHashMap<>();
+
+    public static boolean obtainDeliveryAgreement(CloseableHttpClient httpClient, String targetUrl, String requestOrigin) {
+        logger.info("obtain webhook delivery agreement for url: {}", targetUrl);
+        HttpOptions builder = new HttpOptions(targetUrl);
+        builder.addHeader(REQUEST_ORIGIN_HEADER, requestOrigin);
+
+        try (CloseableHttpResponse response = httpClient.execute(builder)) {
+            String allowedOrigin = response.getLastHeader(ALLOWED_ORIGIN_HEADER).getValue();
+            return allowedOrigin.equals("*") || allowedOrigin.equalsIgnoreCase(requestOrigin);

Review comment:
       Can `allowedOrigin` be null? There will throw NPE if allowedOrigin is null.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@eventmesh.apache.org
For additional commands, e-mail: dev-help@eventmesh.apache.org