| |
@@ -21,6 +21,7 @@
|
| |
|
| |
import logging
|
| |
import datetime
|
| |
+ import urllib.parse
|
| |
from typing import Optional, Any
|
| |
|
| |
import bugzilla
|
| |
@@ -39,6 +40,34 @@
|
| |
'limit': BUGZILLA_QUERY_LIMIT}
|
| |
|
| |
|
| |
+ def create_bugzilla(url: Optional[str] = None,
|
| |
+ api_key: Optional[str] = None) -> bugzilla.Bugzilla:
|
| |
+ """Create a `bugzilla.Bugzilla` instance. If function arguments are left empty, the values are
|
| |
+ loaded from the config file. If api_key is used (i.e. the query is not anonymous), Bugzilla is
|
| |
+ checked whether the key was accepted (otherwise an exception is raised).
|
| |
+ """
|
| |
+ # FIXME: xmlrpc must be used until https://pagure.io/fedora-qa/blockerbugs/issue/184 is resolved
|
| |
+ bz = bugzilla.Bugzilla(url=url or app.config['BUGZILLA_URL'],
|
| |
+ api_key=api_key or app.config['BUGZILLA_API_KEY'],
|
| |
+ use_creds=False,
|
| |
+ force_xmlrpc=True)
|
| |
+ if bz.api_key:
|
| |
+ # Verify successful authentication. This immediately raises an exception if auth fails.
|
| |
+ ok = bz.logged_in
|
| |
+ assert ok is True
|
| |
+
|
| |
+ return bz
|
| |
+
|
| |
+
|
| |
+ def get_bugzilla_url(bz: bugzilla.Bugzilla) -> str:
|
| |
+ """Get main bugzilla url (e.g. 'https://bugzilla.redhat.com') from an existing
|
| |
+ `bugzilla.Bugzilla` instance.
|
| |
+ """
|
| |
+ parsed_uri = urllib.parse.urlparse(bz.url)
|
| |
+ url = '{uri.scheme}://{uri.netloc}'.format(uri=parsed_uri)
|
| |
+ return url
|
| |
+
|
| |
+
|
| |
class BZInterfaceError(Exception):
|
| |
"""A custom wrapper for XMLRPC errors from Bugzilla"""
|
| |
|
| |
@@ -52,31 +81,14 @@
|
| |
class BlockerBugs():
|
| |
"""The main class for querying Bugzilla"""
|
| |
|
| |
- def __init__(self, user: Optional[str] = None, password: Optional[str] = None,
|
| |
- url: Optional[str] = 'https://bugzilla.redhat.com/xmlrpc.cgi',
|
| |
- bz: Optional[bugzilla.Bugzilla] = None,
|
| |
+ def __init__(self, bz: Optional[bugzilla.Bugzilla] = None,
|
| |
logger: Optional[logging.Logger] = None) -> None:
|
| |
- """:param user: Username to log in as. Use `None` for anonymous access.
|
| |
- :param password: User password. Use `None` for anonymous access.
|
| |
- :param url: Bugzilla API url.
|
| |
- :param bz: `Bugzilla` instance. Created automatically if not provided. If provided,
|
| |
- the `user`, `password` and `url` values are ignored.
|
| |
+ """:param bz: `bugzilla.Bugzilla` instance. Created automatically if not provided.
|
| |
:param logger: A custom `Logger` instance. Otherwise a default Logger is created.
|
| |
"""
|
| |
self.logger = logger or logging.getLogger('bz_interface')
|
| |
- self.bz: bugzilla.Bugzilla = bz
|
| |
- if not bz:
|
| |
- if not (user and password):
|
| |
- self.bz = bugzilla.Bugzilla(url=url,
|
| |
- cookiefile=None,
|
| |
- tokenfile=None)
|
| |
- else:
|
| |
- self.bz = bugzilla.Bugzilla(url=url,
|
| |
- user=user,
|
| |
- password=password,
|
| |
- cookiefile=None,
|
| |
- tokenfile=None)
|
| |
- self.logger.info('Using bugzilla URL: %s' % url)
|
| |
+ self.bz: bugzilla.Bugzilla = bz or create_bugzilla()
|
| |
+ self.logger.info('Using bugzilla URL: %s', get_bugzilla_url(self.bz))
|
| |
|
| |
# https://bugzilla.stage.redhat.com/buglist.cgi?bug_status=NEW&bug_status=ASSIGNED
|
| |
# &bug_status=POST&bug_status=MODIFIED&classification=Fedora&component=anaconda&f1=component
|
| |
@@ -88,7 +100,7 @@
|
| |
|
| |
:param last_update: If provided, the query is modified to ask only about bugs which have
|
| |
recent modifications; otherwise asks about all bugs.
|
| |
- :offset: offset to the query instead of just getting the first N results
|
| |
+ :param offset: offset to the query instead of just getting the first N results
|
| |
:returns: a dict which can be fed into `bugzilla.Bugzilla.query()`.
|
| |
"""
|
| |
query = {}
|
| |
@@ -171,9 +183,9 @@
|
| |
# https://bugzilla.redhat.com/buglist.cgi?bug_status=__open__&
|
| |
# f1=flagtypes.name&o1=substring&query_format=advanced&v1=fedora_prioritized_bug%2B
|
| |
query = self.bz.url_to_query(
|
| |
- "{}buglist.cgi?bug_status=__open__&f1=flagtypes.name&o1=substring"
|
| |
+ "{}/buglist.cgi?bug_status=__open__&f1=flagtypes.name&o1=substring"
|
| |
"&query_format=advanced&v1=fedora_prioritized_bug%2B".format(
|
| |
- app.config['BUGZILLA_URL']))
|
| |
+ get_bugzilla_url(self.bz)))
|
| |
buglist = self.bz.query(query)
|
| |
return buglist
|
| |
|
| |
This adds BUGZILLA_API_KEY into config, which is then used for bugzilla
authentication in each call. This replaces FAS_USER + FAS_PASSWORD (formerly
used only for proposing blockers).
This change is mandated by a recent authentication change in Bugzilla:
https://listman.redhat.com/archives/bugzilla-announce-list/2022-February/msg00000.html
This patch fixes the actual bug proposal submission process, but doesn't fix
verifying bugzilla accounts for users, yet.
Also, BUGZILLA_XMLRPC config option got dropped, because it's not needed for
python-bugzilla, we can feed it with BUGZILLA_URL.
Related: https://pagure.io/fedora-qa/blockerbugs/issue/231
This is still somewhat WIP. Reviews welcome, though.