You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "ferencerdei (via GitHub)" <gi...@apache.org> on 2023/04/06 08:19:47 UTC

[GitHub] [nifi] ferencerdei commented on a diff in pull request #7125: NIFI-11366 Proxy aware C2 communication

ferencerdei commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1159409215


##########
c2/c2-client-bundle/c2-client-base/src/main/java/org/apache/nifi/c2/client/C2ClientConfig.java:
##########
@@ -23,6 +23,9 @@ public class C2ClientConfig {
 
     private final String c2Url;
     private final String c2AckUrl;
+    private final String c2RestApi;

Review Comment:
   This naming is misleading in my opinion. It's the c2RestBasePath right? Or if we follow the below convention c2RestPathBase :)



##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/ProxyAwareC2UrlProvider.java:
##########
@@ -0,0 +1,66 @@
+/*
+ * 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.nifi.c2.client.http.url;
+
+import static org.apache.commons.lang3.StringUtils.isNotBlank;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class ProxyAwareC2UrlProvider implements C2UrlProvider {
+
+    private final String c2RestApi;
+    private final String c2RestPathHeartbeat;
+    private final String c2RestPathAcknowledge;
+
+    ProxyAwareC2UrlProvider(String c2RestApi, String c2RestPathHeartbeat, String c2RestPathAcknowledge) {
+        this.c2RestApi = c2RestApi;
+        this.c2RestPathHeartbeat = c2RestPathHeartbeat;
+        this.c2RestPathAcknowledge = c2RestPathAcknowledge;
+    }
+
+    @Override
+    public String getHeartbeatUrl() {
+        return toAbsoluteUrl(c2RestPathHeartbeat);

Review Comment:
   We could calculate the absolute path during instantiation, right? So we won't need to calculate it for every heartbeat/ack.



##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/LegacyC2UrlProvider.java:
##########
@@ -0,0 +1,48 @@
+/*
+ * 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.nifi.c2.client.http.url;
+
+import static org.apache.commons.lang3.StringUtils.isBlank;
+
+public class LegacyC2UrlProvider implements C2UrlProvider {
+
+    private final String c2Url;
+    private final String c2AckUrl;
+
+    LegacyC2UrlProvider(String c2Url, String c2AckUrl) {
+        this.c2Url = c2Url;
+        this.c2AckUrl = c2AckUrl;
+    }
+
+    @Override
+    public String getHeartbeatUrl() {
+        return c2Url;
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return c2AckUrl;
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {
+        if (isBlank(absoluteUrl)) {
+            throw new Exception("Provided absolute url was empty or null. Relative urls are not supported with this configuration");

Review Comment:
   Would be better to throw a dedicated exception instead of generic.



##########
c2/c2-client-bundle/c2-client-api/src/main/java/org/apache/nifi/c2/client/api/C2Client.java:
##########
@@ -57,4 +57,14 @@ public interface C2Client {
      * @return optional error message if any issues occurred
      */
     Optional<String> uploadBundle(String callbackUrl, byte[] bundle);
+
+    /**
+     * Creates a callback URL according to proxy aware C2 settings
+     *
+     * @param absoluteUrl absolute url sent by C2 server
+     * @param relativeUrl relative url sent by C2 server
+     * @return finalised callback url
+     * @throws Exception when the callback url can not be created as per the current configuration and parameters
+     */
+    String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception;

Review Comment:
   Agree with @bejancsaba's proposal, but If we need to keep the exception, I would throw IllegalArgumentException or something more meaningful exception instead.



##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-resources/src/main/resources/conf/bootstrap.conf:
##########
@@ -134,8 +134,13 @@ java.arg.14=-Djava.awt.headless=true
 # Enabling C2 Uncomment each of the following options
 #c2.enable=true
 ## define protocol parameters
+# legacy properties
 #c2.rest.url=

Review Comment:
   We should add a deprecation note instead (maybe mention it in the readme/docs as well) what do you think? So we can remove it in the future.



-- 
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: issues-unsubscribe@nifi.apache.org

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