You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ranger.apache.org by ma...@apache.org on 2023/02/11 07:02:13 UTC

[ranger] 02/02: RANGER-4079: Python client fix to handle URLs having subpaths

This is an automated email from the ASF dual-hosted git repository.

madhan pushed a commit to branch ranger-2.4
in repository https://gitbox.apache.org/repos/asf/ranger.git

commit 4aaa1b11be3e88d69147ce947c63fb58834e0dd1
Author: Madhan Neethiraj <ma...@apache.org>
AuthorDate: Fri Feb 10 14:05:44 2023 -0800

    RANGER-4079: Python client fix to handle URLs having subpaths
    
    (cherry picked from commit 63cf6007fb5c25a8b4558ad8b0ce31322e19d853)
---
 .../python/apache_ranger/client/ranger_client.py   | 24 ++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/intg/src/main/python/apache_ranger/client/ranger_client.py b/intg/src/main/python/apache_ranger/client/ranger_client.py
index e26528013..260095b2f 100644
--- a/intg/src/main/python/apache_ranger/client/ranger_client.py
+++ b/intg/src/main/python/apache_ranger/client/ranger_client.py
@@ -40,8 +40,8 @@ QUERY_PARAM_USER_DOT_NAME = 'user.name'.encode("utf-8")
 
 
 class RangerClient:
-    def __init__(self, url, auth):
-        self.client_http = RangerClientHttp(url, auth)
+    def __init__(self, url, auth, query_params=None, headers=None):
+        self.client_http = RangerClientHttp(url, auth, query_params, headers)
         self.session     = self.client_http.session
         logging.getLogger("requests").setLevel(logging.WARNING)
 
@@ -433,8 +433,10 @@ class RESTResponse(RangerBase):
 
 
 class RangerClientHttp:
-    def __init__(self, url, auth):
-        self.url          = url.rstrip('/')
+    def __init__(self, url, auth, query_params=None, headers=None):
+        self.url          = url.rstrip('/') + '/' # ensure that self.url ends with a /
+        self.query_params = query_params
+        self.headers      = headers
         self.session      = Session()
         self.session.auth = auth
 
@@ -443,6 +445,20 @@ class RangerClientHttp:
         ret    = None
         params = { 'headers': { 'Accept': api.consumes, 'Content-type': api.produces } }
 
+        if self.headers:
+          params['headers'].update(self.headers)
+
+        if self.query_params:
+          if query_params:
+              merged_query_params = {}
+
+              merged_query_params.update(self.query_params)
+              merged_query_params.update(query_params)
+
+              query_params = merged_query_params
+          else:
+              query_params = self.query_params
+
         if query_params:
             params['params'] = query_params