⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 246082 in webkit


Ignore:
Timestamp:
Jun 4, 2019, 2:40:00 PM (7 years ago)
Author:
aakash_jain@apple.com
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):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/BuildSlaveSupport/ews-app/ews/common/bugzilla.py

    r238636 r246082  
    2626import re
    2727import socket
     28import time
    2829
    2930from datetime import datetime, timedelta
     
    6263
    6364        attachment_url = '{}rest/bug/attachment/{}'.format(config.BUG_SERVER_URL, attachment_id)
     65        api_key = os.getenv('BUGZILLA_API_KEY', None)
     66        if api_key:
     67            attachment_url += '?api_key={}'.format(api_key)
    6468        attachment = util.fetch_data_from_url(attachment_url)
    6569        if not attachment:
     
    102106    browser = property(_get_browser, _set_browser)
    103107
     108    def authenticate(self):
     109        username = os.getenv('BUGZILLA_USERNAME', None)
     110        password = os.getenv('BUGZILLA_PASSWORD', None)
     111        if not username or not password:
     112            _log.warn('Bugzilla username/password not configured in environment variables. Skipping authentication.')
     113            return
     114
     115        authenticated = False
     116        attempts = 0
     117        while not authenticated:
     118            attempts += 1
     119            _log.info('Logging in as {}...'.format(username))
     120            self.browser.open(config.BUG_SERVER_URL + 'index.cgi?GoAheadAndLogIn=1')
     121            self.browser.select_form(name="login")
     122            self.browser['Bugzilla_login'] = username
     123            self.browser['Bugzilla_password'] = password
     124            self.browser.find_control("Bugzilla_restrictlogin").items[0].selected = False
     125            response = self.browser.submit()
     126
     127            match = re.search("<title>(.+?)</title>", response.read())
     128            # If the resulting page has a title, and it contains the word
     129            # "invalid" assume it's the login failure page.
     130            if match and re.search("Invalid", match.group(1), re.IGNORECASE):
     131                errorMessage = 'Bugzilla login failed: {}'.format(match.group(1))
     132                if attempts >= 5:
     133                    # raise an exception only if this was the last attempt
     134                    raise Exception(errorMessage)
     135                _log.error(errorMessage)
     136                time.sleep(5)
     137            else:
     138                authenticated = True
     139
    104140    def fetch_attachment_ids_from_review_queue(self, since=None, only_security_bugs=False):
    105141        review_queue_url = 'request.cgi?action=queue&type=review&group=type'
     
    109145
    110146    def _load_query(self, query):
    111         # TODO: check if we need to authenticate.
     147        self.authenticate()
    112148        full_url = '{}{}'.format(config.BUG_SERVER_URL, query)
    113149        _log.info('Getting list of patches needing review, URL: {}'.format(full_url))
  • trunk/Tools/ChangeLog

    r246080 r246082  
     12019-06-04  Aakash Jain  <aakash_jain@apple.com>
     2
     3        [ews-app] Add authentication while fetching bugs
     4        https://bugs.webkit.org/show_bug.cgi?id=198415
     5        <rdar://problem/51298710>
     6
     7        Reviewed by Jonathan Bedard.
     8
     9        * BuildSlaveSupport/ews-app/ews/common/bugzilla.py:
     10        (Bugzilla._fetch_attachment_json): Use api_key if configured in environment variable.
     11        (BugzillaBeautifulSoup.authenticate): Method to authenticate, logic copied from webkitpy/common/net/bugzilla/bugzilla.py
     12        (BugzillaBeautifulSoup._load_query):
     13
    1142019-06-04  Aakash Jain  <aakash_jain@apple.com>
    215
Note: See TracChangeset for help on using the changeset viewer.