You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2018/12/19 09:50:06 UTC

[GitHub] pvillard31 closed pull request #3219: NIFI-5893: AWS Endpoint Overriding now functions properly

pvillard31 closed pull request #3219: NIFI-5893: AWS Endpoint Overriding now functions properly
URL: https://github.com/apache/nifi/pull/3219
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java
index fe5ce62e60..06f4a16590 100644
--- a/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java
+++ b/nifi-nar-bundles/nifi-aws-bundle/nifi-aws-abstract-processors/src/main/java/org/apache/nifi/processors/aws/AbstractAWSProcessor.java
@@ -37,6 +37,8 @@
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import javax.net.ssl.SSLContext;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.http.conn.ssl.DefaultHostnameVerifier;
@@ -283,13 +285,43 @@ protected void initializeRegionAndEndpoint(ProcessContext context) {
         // (per Amazon docs this should only be configured at client creation)
         if (getSupportedPropertyDescriptors().contains(ENDPOINT_OVERRIDE)) {
             final String urlstr = StringUtils.trimToEmpty(context.getProperty(ENDPOINT_OVERRIDE).evaluateAttributeExpressions().getValue());
+
             if (!urlstr.isEmpty()) {
                 getLogger().info("Overriding endpoint with {}", new Object[]{urlstr});
-                this.client.setEndpoint(urlstr, this.client.getServiceName(), this.region.getName());
+
+                if (urlstr.endsWith(".vpce.amazonaws.com")) {
+                    String region = parseRegionForVPCE(urlstr);
+                    this.client.setEndpoint(urlstr, this.client.getServiceName(), region);
+                } else {
+                    this.client.setEndpoint(urlstr);
+                }
             }
         }
     }
 
+    /*
+    Note to developer(s):
+        When setting an endpoint for an AWS Client i.e. client.setEndpoint(endpointUrl),
+        AWS Java SDK fails to parse the region correctly when the provided endpoint
+        is an AWS PrivateLink so this method does the job of parsing the region name and
+        returning it.
+
+        Refer NIFI-5456 & NIFI-5893
+     */
+    private String parseRegionForVPCE(String url) {
+        int index = url.length() - ".vpce.amazonaws.com".length();
+
+        Pattern VPCE_ENDPOINT_PATTERN = Pattern.compile("^(?:.+[vpce-][a-z0-9-]+\\.)?([a-z0-9-]+)$");
+        Matcher matcher = VPCE_ENDPOINT_PATTERN.matcher(url.substring(0, index));
+
+        if (matcher.matches()) {
+            return matcher.group(1);
+        } else {
+            getLogger().warn("Unable to get a match with the VPCE endpoint pattern; defaulting the region to us-east-1...");
+            return "us-east-1";
+        }
+    }
+
     /**
      * Create client from the arguments
      * @param context process context


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services