dimberman commented on a change in pull request #6773: [AIRFLOW-6038] AWS 
DataSync example_dags added
URL: https://github.com/apache/airflow/pull/6773#discussion_r356767772
 
 

 ##########
 File path: airflow/providers/amazon/aws/hooks/datasync.py
 ##########
 @@ -76,44 +80,52 @@ def create_location(self, location_uri, 
**create_location_kwargs):
         :return str: LocationArn of the created Location.
         :raises AirflowException: If location type (prefix from 
``location_uri``) is invalid.
         """
-        typ = location_uri.split(':')[0]
-        if typ == 'smb':
+        typ = location_uri.split(":")[0]
+        if typ == "smb":
             location = 
self.get_conn().create_location_smb(**create_location_kwargs)
-        elif typ == 's3':
+        elif typ == "s3":
             location = 
self.get_conn().create_location_s3(**create_location_kwargs)
-        elif typ == 'nfs':
+        elif typ == "nfs":
             location = 
self.get_conn().create_loction_nfs(**create_location_kwargs)
-        elif typ == 'efs':
+        elif typ == "efs":
             location = 
self.get_conn().create_loction_efs(**create_location_kwargs)
         else:
-            raise AirflowException('Invalid location type: {0}'.format(typ))
+            raise AirflowException("Invalid location type: {0}".format(typ))
         self._refresh_locations()
-        return location['LocationArn']
+        return location["LocationArn"]
 
-    def get_location_arns(self, location_uri, case_sensitive=True):
+    def get_location_arns(
+        self, location_uri, case_sensitive=True, ignore_trailing_slash=True
+    ):
         """
         Return all LocationArns which match a LocationUri.
 
         :param str location_uri: Location URI to search for, eg 
``s3://mybucket/mypath``
         :param bool case_sensitive: Do a case sensitive search for location 
URI.
+        :param bool ignore_trailing_slash: Ignore / at the end of URI when 
matching.
         :return: List of LocationArns.
         :rtype: list(str)
         :raises AirflowBadRequest: if ``location_uri`` is empty
         """
         if not location_uri:
-            raise AirflowBadRequest('location_uri not specified')
+            raise AirflowBadRequest("location_uri not specified")
         if not self.locations:
             self._refresh_locations()
         result = []
 
+        if not case_sensitive:
+            location_uri = location_uri.lower()
+        if ignore_trailing_slash and location_uri.endswith("/"):
+            location_uri = location_uri[:-1]
+
         for location in self.locations:
-            match = False
-            if case_sensitive:
-                match = location['LocationUri'] == location_uri
-            else:
-                match = location['LocationUri'].lower() == location_uri.lower()
-            if match:
-                result.append(location['LocationArn'])
+            location_uri2 = location["LocationUri"]
 
 Review comment:
   location_uri2 is kind o f vague. Can you give this a more descriptive name? 
Why do we need need this second location_uri etc.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to