reviewboard: use built-in mechanism to not save cookies; r=smacleod draft
authorGregory Szorc <gps@mozilla.com>
Mon, 11 Jan 2016 15:57:31 -0800
changeset 6717 c85f73a6b2af2290021cd24ea966215ef85e6f05
parent 6716 391714d97a4bd51352c1ecb5b3ab802e3437d97d
child 6718 7fd4fa6a1e1995f16658c4d7a59260ed52d0241a
push id513
push usergszorc@mozilla.com
push dateWed, 13 Jan 2016 02:13:15 +0000
reviewerssmacleod
reviewboard: use built-in mechanism to not save cookies; r=smacleod The hack around using a temporary file as a cookie manager was necessary because older versions of RBTools didn't support not saving cookies. New versions do. So remove the hack and use the built-in mechanism. This function no longer needs to be a context manager. This will be removed in a subsequent commit.
pylib/reviewboardmods/reviewboardmods/pushhooks.py
testing/vcttesting/reviewboard/__init__.py
--- a/pylib/reviewboardmods/reviewboardmods/pushhooks.py
+++ b/pylib/reviewboardmods/reviewboardmods/pushhooks.py
@@ -4,18 +4,16 @@ This module contains code for taking com
 Mercurial, etc) and adding them to Review Board.
 
 It is intended for this module to be generic and applicable to any
 Review Board install. Please abstract away Mozilla implementation
 details.
 """
 
 from contextlib import contextmanager
-import os
-import tempfile
 
 from rbtools.api.client import RBClient
 from rbtools.api.errors import APIError
 
 
 def associate_ldap_username(url, ldap_username, privileged_username,
                             privileged_password, username, apikey):
     """Associate a Review Board user with an ldap username.
@@ -80,37 +78,21 @@ def associate_ldap_username(url, ldap_us
 
     return True
 
 
 @contextmanager
 def ReviewBoardClient(url, username=None, password=None, apikey=None):
     """Obtain a RBClient instance via a context manager.
 
-    This exists as a context manager because of gross hacks necessary for
-    dealing with cookies. ``RBClient`` is coded such that it assumes it is
-    being used under a user account and storing cookies is always acceptable.
-    There is no way to disable cookie file writing or to tell it to use a file
-    object (such as BytesIO) as the cookies database.
-
-    We work around this deficiency by creating a temporary file and using it as
-    the cookies database for the lifetime of the context manager. When the
-    context manager exits, the temporary cookies file is deleted.
+    This exists as a context manager for historical reasons.
     """
-    fd, path = tempfile.mkstemp()
-    os.close(fd)
-    try:
-        if username and apikey:
-            rbc = RBClient(url, cookie_file=path, allow_caching=False)
-            login_resource = rbc.get_path(
-                'extensions/mozreview.extension.MozReviewExtension/'
-                'bugzilla-api-key-logins/')
-            login_resource.create(username=username, api_key=apikey)
-        else:
-            rbc = RBClient(url, username=username, password=password,
-                           cookie_file=path, allow_caching=False)
+    if username and apikey:
+        rbc = RBClient(url, save_cookies=False, allow_caching=False)
+        login_resource = rbc.get_path(
+            'extensions/mozreview.extension.MozReviewExtension/'
+            'bugzilla-api-key-logins/')
+        login_resource.create(username=username, api_key=apikey)
+    else:
+        rbc = RBClient(url, username=username, password=password,
+                       save_cookies=False, allow_caching=False)
 
-        yield rbc
-    finally:
-        try:
-            os.unlink(path)
-        except Exception:
-            pass
+    yield rbc
--- a/testing/vcttesting/reviewboard/__init__.py
+++ b/testing/vcttesting/reviewboard/__init__.py
@@ -1,37 +1,30 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 import json
 import logging
-import os
-import shutil
-import tempfile
 
 from contextlib import contextmanager
 
 from rbtools.api.client import RBClient
 
 
 logger = logging.getLogger(__name__)
 
 
 @contextmanager
 def ReviewBoardClient(url, username, password):
-    tempd = tempfile.mkdtemp()
-    try:
-        cookie_file = os.path.join(tempd, 'cookies')
-        rbclient = RBClient(url, cookie_file=cookie_file,
-                            allow_caching=False,
-                            username=username, password=password)
-        yield rbclient
-    finally:
-        shutil.rmtree(tempd)
+
+    rbclient = RBClient(url, save_cookies=False,
+                        allow_caching=False,
+                        username=username, password=password)
+    yield rbclient
 
 
 class MozReviewBoard(object):
     """Interact with a Mozilla-flavored Review Board install."""
 
     def __init__(self, docker, cid, url, bugzilla_url=None,
                  pulse_host=None, pulse_port=None,
                  pulse_user='guest', pulse_password='guest'):