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

[GitHub] [nifi] briansolo1985 opened a new pull request, #7125: NIFI-11366 Proxy aware C2 communication

briansolo1985 opened a new pull request, #7125:
URL: https://github.com/apache/nifi/pull/7125

   <!-- 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. -->
   
   # Summary
   
   [NIFI-11366](https://issues.apache.org/jira/browse/NIFI-11366)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [x] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [x] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [x] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [x] Pull Request based on current revision of the `main` branch
   - [x] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [] Build completed using `mvn clean install -P contrib-check`
     - [] JDK 11
     - [ ] JDK 17
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160101077


##########
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=
 #c2.rest.url.ack=
+# new c2 properties
+#c2.rest.api=

Review Comment:
   I went with c2.rest.path.base to be consistent with the other properties



-- 
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


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

Posted by "ferencerdei (via GitHub)" <gi...@apache.org>.
ferencerdei commented on PR #7125:
URL: https://github.com/apache/nifi/pull/7125#issuecomment-1502973153

   Tested the change with the Debug and Update Configuration commands. It works properly.
   
   +1
   
   Merging...


-- 
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


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

Posted by "bejancsaba (via GitHub)" <gi...@apache.org>.
bejancsaba commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1158870015


##########
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:
   Would it be possible to retrun optional similarly to the other functions here (this way not requiring exception to be thrown) or there are downstream constraints why this approach wouldn't fit?



##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/C2UrlProvider.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+public interface C2UrlProvider {
+
+    String getHeartbeatUrl();

Review Comment:
   Could you please add short Javadoc for the functions in the interface?



##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/C2UrlProviderFactory.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.isNoneBlank;
+
+import org.apache.nifi.c2.client.C2ClientConfig;
+
+public class C2UrlProviderFactory {
+
+    private final C2ClientConfig clientConfig;
+
+    public C2UrlProviderFactory(C2ClientConfig clientConfig) {
+        this.clientConfig = clientConfig;
+    }
+
+    public C2UrlProvider create() {
+        if (isNoneBlank(clientConfig.getC2RestApi(), clientConfig.getC2RestPathHeartbeat(), clientConfig.getC2RestPathAcknowledge())) {
+            return new ProxyAwareC2UrlProvider(clientConfig.getC2RestApi(), clientConfig.getC2RestPathHeartbeat(), clientConfig.getC2RestPathAcknowledge());
+        } else if (isNoneBlank(clientConfig.getC2Url(), clientConfig.getC2AckUrl())) {
+            return new LegacyC2UrlProvider(clientConfig.getC2Url(), clientConfig.getC2AckUrl());
+        } else {
+            throw new IllegalArgumentException("Incorrect configuration. Please configure legacy or proxy aware C2 URL properties");

Review Comment:
   I think it would make sense to provide a little more information here I don't think all users would understand what legacy / proxy aware C2 URL properties means. Listing explicitly all the properties for legacy and for proxy aware would be a big help I suppose. What do you think?



##########
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=
 #c2.rest.url.ack=
+# new c2 properties
+#c2.rest.api=

Review Comment:
   Naming is very subjective (as always) just trying to provide alternates maybe they are better or owrse will leave it to you or anyone else who reviews it:
   - c2.rest.host - maybe this is misleading as it could contain not just the host
   - c2.rest.base or c2.rest.path.base
   
   What do you think?



##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {

Review Comment:
   What do you think about making the decisions below in C2HttpClient (where this is called) and introducing a "fromRelativeUrl" and a "fromAbsoluteUrl" function and the fromAbsolute could have  adefault implementation in C2UrlProvider.



##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {
+        if (isNotBlank(relativeUrl)) {
+            return toAbsoluteUrl(relativeUrl);
+        }
+        if (isNotBlank(absoluteUrl)) {
+            return absoluteUrl;
+        }
+        throw new Exception("Unable to provide callback url as both parameters were empty or null");
+    }
+
+    private String toAbsoluteUrl(String path) {
+        try {
+            URL baseUrl = new URL(c2RestApi);

Review Comment:
   You could do this in the init phase so if something is misconfigured it would be evident instantly at startup. Just an idea.



##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {
+        if (isNotBlank(relativeUrl)) {
+            return toAbsoluteUrl(relativeUrl);
+        }
+        if (isNotBlank(absoluteUrl)) {
+            return absoluteUrl;
+        }
+        throw new Exception("Unable to provide callback url as both parameters were empty or null");
+    }
+
+    private String toAbsoluteUrl(String path) {
+        try {
+            URL baseUrl = new URL(c2RestApi);
+            URL fullUrl = new URL(baseUrl, path);
+            return fullUrl.toString();
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);

Review Comment:
   Can you add a liitle text stating that the absolute url creation failed or something along those line?



-- 
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


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

Posted by "bejancsaba (via GitHub)" <gi...@apache.org>.
bejancsaba commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1162473024


##########
c2/c2-client-bundle/c2-client-http/src/test/java/org/apache/nifi/c2/client/http/url/C2UrlProviderFactoryTest.java:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
+import static org.mockito.Mockito.lenient;
+import static org.mockito.Mockito.when;
+
+import org.apache.nifi.c2.client.C2ClientConfig;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+
+@ExtendWith(MockitoExtension.class)
+public class C2UrlProviderFactoryTest {
+
+    private static final String C2_REST_BASE = "https://host:8080/c2/api";
+    private static final String HEARTBEAT_PATH = "/heartbeat";
+    private static final String ACKNOWLEDGE_PATH = "/acknowledge";
+
+    @Mock
+    private C2ClientConfig clientConfig;
+    @InjectMocks
+    private C2UrlProviderFactory testC2UrlProviderFactory;
+
+    @Test
+    public void testProxyAwareC2UrlProviderIsCreated() {
+        // given
+        when(clientConfig.getC2RestPathBase()).thenReturn(C2_REST_BASE);
+        when(clientConfig.getC2RestPathHeartbeat()).thenReturn(HEARTBEAT_PATH);
+        when(clientConfig.getC2RestPathAcknowledge()).thenReturn(ACKNOWLEDGE_PATH);
+
+        // when
+        C2UrlProvider c2UrlProvider = testC2UrlProviderFactory.create();
+
+        // then
+        assertInstanceOf(ProxyAwareC2UrlProvider.class, c2UrlProvider);
+    }
+
+    @Test
+    public void testLegacyC2UrlProviderIsCreated() {
+        // given
+        when(clientConfig.getC2Url()).thenReturn(C2_REST_BASE + HEARTBEAT_PATH);
+        when(clientConfig.getC2AckUrl()).thenReturn(C2_REST_BASE + ACKNOWLEDGE_PATH);
+
+        // when
+        C2UrlProvider c2UrlProvider = testC2UrlProviderFactory.create();
+
+        // then
+        assertInstanceOf(LegacyC2UrlProvider.class, c2UrlProvider);
+    }
+
+    @Test
+    public void testProxyAwareProviderTakesPrecedenceOverLegacy() {

Review Comment:
   I was looking for this test, thank you!



##########
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:
   Thanks looks good



##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {

Review Comment:
   Ok, it was just an idea didn't wanted to change the whole approach just elevate some logic to the C2Client. FOr me it made sense that way but I'm ok with the current approach as well.



##########
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=
 #c2.rest.url.ack=
+# new c2 properties
+#c2.rest.api=

Review Comment:
   Okay sounds good, thank you



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1159935815


##########
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:
   Moved away from using exceptions and refactored to use Optional instead



##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/C2UrlProvider.java:
##########
@@ -0,0 +1,26 @@
+/*
+ * 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;
+
+public interface C2UrlProvider {
+
+    String getHeartbeatUrl();

Review Comment:
   Sure, added



-- 
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


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

Posted by "ferencerdei (via GitHub)" <gi...@apache.org>.
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160097989


##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {
+        if (isNotBlank(relativeUrl)) {
+            return toAbsoluteUrl(relativeUrl);
+        }
+        if (isNotBlank(absoluteUrl)) {
+            return absoluteUrl;
+        }
+        throw new Exception("Unable to provide callback url as both parameters were empty or null");
+    }
+
+    private String toAbsoluteUrl(String path) {
+        try {
+            URL baseUrl = new URL(c2RestApi);

Review Comment:
   Moved it to the init phase



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160102228


##########
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:
   Added additional comments about usage and deprecation



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1159936286


##########
c2/c2-client-bundle/c2-client-http/src/main/java/org/apache/nifi/c2/client/http/url/C2UrlProviderFactory.java:
##########
@@ -0,0 +1,40 @@
+/*
+ * 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.isNoneBlank;
+
+import org.apache.nifi.c2.client.C2ClientConfig;
+
+public class C2UrlProviderFactory {
+
+    private final C2ClientConfig clientConfig;
+
+    public C2UrlProviderFactory(C2ClientConfig clientConfig) {
+        this.clientConfig = clientConfig;
+    }
+
+    public C2UrlProvider create() {
+        if (isNoneBlank(clientConfig.getC2RestApi(), clientConfig.getC2RestPathHeartbeat(), clientConfig.getC2RestPathAcknowledge())) {
+            return new ProxyAwareC2UrlProvider(clientConfig.getC2RestApi(), clientConfig.getC2RestPathHeartbeat(), clientConfig.getC2RestPathAcknowledge());
+        } else if (isNoneBlank(clientConfig.getC2Url(), clientConfig.getC2AckUrl())) {
+            return new LegacyC2UrlProvider(clientConfig.getC2Url(), clientConfig.getC2AckUrl());
+        } else {
+            throw new IllegalArgumentException("Incorrect configuration. Please configure legacy or proxy aware C2 URL properties");

Review Comment:
   Added a more detailed error message



-- 
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


[GitHub] [nifi] briansolo1985 commented on pull request #7125: NIFI-11366 Proxy aware C2 communication

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on PR #7125:
URL: https://github.com/apache/nifi/pull/7125#issuecomment-1499431650

   Thanks for checking the PR. Unfortunately I left out some files from the previous commit causing the tests to fail.
   I added these files and also incorporated the review comments.
   The build is running fine now. I still wish to add some unit test, but until that you can proceed with the code review if you wish.


-- 
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


[GitHub] [nifi] ferencerdei closed pull request #7125: NIFI-11366 Proxy aware C2 communication

Posted by "ferencerdei (via GitHub)" <gi...@apache.org>.
ferencerdei closed pull request #7125: NIFI-11366 Proxy aware C2 communication
URL: https://github.com/apache/nifi/pull/7125


-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1159937561


##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {
+        if (isNotBlank(relativeUrl)) {
+            return toAbsoluteUrl(relativeUrl);
+        }
+        if (isNotBlank(absoluteUrl)) {
+            return absoluteUrl;
+        }
+        throw new Exception("Unable to provide callback url as both parameters were empty or null");
+    }
+
+    private String toAbsoluteUrl(String path) {
+        try {
+            URL baseUrl = new URL(c2RestApi);
+            URL fullUrl = new URL(baseUrl, path);
+            return fullUrl.toString();
+        } catch (MalformedURLException e) {
+            throw new RuntimeException(e);

Review Comment:
   Now with the optional based approach there is no exception, instead the error is logged



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160100705


##########
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);
+    }
+
+    @Override
+    public String getAcknowledgeUrl() {
+        return toAbsoluteUrl(c2RestPathAcknowledge);
+    }
+
+    @Override
+    public String getCallbackUrl(String absoluteUrl, String relativeUrl) throws Exception {

Review Comment:
   With the refactor I think it became clearer. I would leave the logic as it is, as the client should be unaware how to create the callback url, that logic should be encapsulated in the UrlProvider classes.
   The reason it is exposed through C2Client, is that I didn't want the UrlProvider classes to be accessed from the OperationHandlers. Hence C2Client already contained the UrlProvider, it seemed convenient to implement this way.



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160101758


##########
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:
   Renamed as advised - went with the second option



##########
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:
   Moved the logic to the constructor



-- 
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


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

Posted by "briansolo1985 (via GitHub)" <gi...@apache.org>.
briansolo1985 commented on code in PR #7125:
URL: https://github.com/apache/nifi/pull/7125#discussion_r1160102556


##########
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:
   The exception based solution is replaced with an optional based approach



-- 
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