Title: [246082] trunk/Tools
Revision
246082
Author
[email protected]
Date
2019-06-04 14:40:00 -0700 (Tue, 04 Jun 2019)

Log Message

[ews-app] Add authentication while fetching bugs
https://bugs.webkit.org/show_bug.cgi?id=198415
<rdar://problem/51298710>

Reviewed by Jonathan Bedard.

* BuildSlaveSupport/ews-app/ews/common/bugzilla.py:
(Bugzilla._fetch_attachment_json): Use api_key if configured in environment variable.
(BugzillaBeautifulSoup.authenticate): Method to authenticate, logic copied from webkitpy/common/net/bugzilla/bugzilla.py
(BugzillaBeautifulSoup._load_query):

Modified Paths

Diff

Modified: trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py (246081 => 246082)


--- trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py	2019-06-04 21:27:33 UTC (rev 246081)
+++ trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py	2019-06-04 21:40:00 UTC (rev 246082)
@@ -25,6 +25,7 @@
 import os
 import re
 import socket
+import time
 
 from datetime import datetime, timedelta
 
@@ -61,6 +62,9 @@
             return None
 
         attachment_url = '{}rest/bug/attachment/{}'.format(config.BUG_SERVER_URL, attachment_id)
+        api_key = os.getenv('BUGZILLA_API_KEY', None)
+        if api_key:
+            attachment_url += '?api_key={}'.format(api_key)
         attachment = util.fetch_data_from_url(attachment_url)
         if not attachment:
             return None
@@ -101,6 +105,38 @@
 
     browser = property(_get_browser, _set_browser)
 
+    def authenticate(self):
+        username = os.getenv('BUGZILLA_USERNAME', None)
+        password = os.getenv('BUGZILLA_PASSWORD', None)
+        if not username or not password:
+            _log.warn('Bugzilla username/password not configured in environment variables. Skipping authentication.')
+            return
+
+        authenticated = False
+        attempts = 0
+        while not authenticated:
+            attempts += 1
+            _log.info('Logging in as {}...'.format(username))
+            self.browser.open(config.BUG_SERVER_URL + 'index.cgi?GoAheadAndLogIn=1')
+            self.browser.select_form(name="login")
+            self.browser['Bugzilla_login'] = username
+            self.browser['Bugzilla_password'] = password
+            self.browser.find_control("Bugzilla_restrictlogin").items[0].selected = False
+            response = self.browser.submit()
+
+            match = re.search("<title>(.+?)</title>", response.read())
+            # If the resulting page has a title, and it contains the word
+            # "invalid" assume it's the login failure page.
+            if match and re.search("Invalid", match.group(1), re.IGNORECASE):
+                errorMessage = 'Bugzilla login failed: {}'.format(match.group(1))
+                if attempts >= 5:
+                    # raise an exception only if this was the last attempt
+                    raise Exception(errorMessage)
+                _log.error(errorMessage)
+                time.sleep(5)
+            else:
+                authenticated = True
+
     def fetch_attachment_ids_from_review_queue(self, since=None, _only_security_bugs_=False):
         review_queue_url = 'request.cgi?action=""
         if only_security_bugs:
@@ -108,7 +144,7 @@
         return self._parse_attachment_ids_request_query(self._load_query(review_queue_url), since)
 
     def _load_query(self, query):
-        # TODO: check if we need to authenticate.
+        self.authenticate()
         full_url = '{}{}'.format(config.BUG_SERVER_URL, query)
         _log.info('Getting list of patches needing review, URL: {}'.format(full_url))
         return self.browser.open(full_url)

Modified: trunk/Tools/ChangeLog (246081 => 246082)


--- trunk/Tools/ChangeLog	2019-06-04 21:27:33 UTC (rev 246081)
+++ trunk/Tools/ChangeLog	2019-06-04 21:40:00 UTC (rev 246082)
@@ -1,5 +1,18 @@
 2019-06-04  Aakash Jain  <[email protected]>
 
+        [ews-app] Add authentication while fetching bugs
+        https://bugs.webkit.org/show_bug.cgi?id=198415
+        <rdar://problem/51298710>
+
+        Reviewed by Jonathan Bedard.
+
+        * BuildSlaveSupport/ews-app/ews/common/bugzilla.py:
+        (Bugzilla._fetch_attachment_json): Use api_key if configured in environment variable.
+        (BugzillaBeautifulSoup.authenticate): Method to authenticate, logic copied from webkitpy/common/net/bugzilla/bugzilla.py
+        (BugzillaBeautifulSoup._load_query):
+
+2019-06-04  Aakash Jain  <[email protected]>
+
         [ews-build] Do not display unnecessary steps in the Buildbot build page UI
         https://bugs.webkit.org/show_bug.cgi?id=198218
         <rdar://problem/51104544>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to