浏览代码

HUE-1960 [jb] Cannot access container logs because of encoded url

Add "urlencode" to HttpClient. This will tell it to encode paths if
set to true.
Abraham Elmahrek 11 年之前
父节点
当前提交
2e4cef3d1f

+ 1 - 1
apps/jobbrowser/src/jobbrowser/views.py

@@ -240,7 +240,7 @@ def job_attempt_logs_json(request, job, attempt_index=0, name='syslog', offset=0
   if offset and int(offset) >= 0:
     params['start'] = offset
 
-  root = Resource(get_log_client(log_link), urlparse.urlsplit(log_link)[2])
+  root = Resource(get_log_client(log_link), urlparse.urlsplit(log_link)[2], urlencode=False)
 
   try:
     response = root.get(link, params=params)

+ 1 - 1
apps/jobbrowser/src/jobbrowser/yarn_models.py

@@ -223,7 +223,7 @@ class Attempt:
 
       try:
         log_link = re.sub('job_[^/]+', self.id, log_link)
-        root = Resource(get_log_client(log_link), urlparse.urlsplit(log_link)[2])
+        root = Resource(get_log_client(log_link), urlparse.urlsplit(log_link)[2], urlencode=False)
         response = root.get(link, params=params)
         log = html.fromstring(response).xpath('/html/body/table/tbody/tr/td[2]')[0].text_content()
       except Exception, e:

+ 4 - 2
desktop/core/src/desktop/lib/rest/http_client.py

@@ -112,7 +112,7 @@ class HttpClient(object):
       self._session.headers.update(headers)
     return self._session.headers.copy()
 
-  def execute(self, http_method, path, params=None, data=None, headers=None, allow_redirects=False):
+  def execute(self, http_method, path, params=None, data=None, headers=None, allow_redirects=False, urlencode=True):
     """
     Submit an HTTP request.
     @param http_method: GET, POST, PUT, DELETE
@@ -121,11 +121,13 @@ class HttpClient(object):
     @param data: The data to attach to the body of the request.
     @param headers: The headers to set for this request.
     @param allow_redirects: requests should automatically resolve redirects.
+    @param urlencode: percent encode paths.
 
     @return: The result of urllib2.urlopen()
     """
     # Prepare URL and params
-    path = urllib.quote(smart_str(path))
+    if urlencode:
+      path = urllib.quote(smart_str(path))
     url = self._make_url(path, params)
     if http_method in ("GET", "DELETE"):
       if data is not None:

+ 5 - 2
desktop/core/src/desktop/lib/rest/resource.py

@@ -28,13 +28,15 @@ class Resource(object):
   """
   Encapsulates a resource, and provides actions to invoke on it.
   """
-  def __init__(self, client, relpath=""):
+  def __init__(self, client, relpath="", urlencode=True):
     """
     @param client: A Client object.
     @param relpath: The relative path of the resource.
+    @param urlencode: percent encode paths.
     """
     self._client = client
     self._path = relpath.strip('/')
+    self._urlencode = urlencode
 
   @property
   def base_url(self):
@@ -71,7 +73,8 @@ class Resource(object):
                                 params=params,
                                 data=data,
                                 headers=headers,
-                                allow_redirects=allow_redirects)
+                                allow_redirects=allow_redirects,
+                                urlencode=self._urlencode)
 
     self._client.logger.debug(
         "%s Got response: %s%s" %