Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use requests-gssapi for Jira stats
  • Loading branch information
psss committed Nov 23, 2018
1 parent bf2dd35 commit b61d50b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
2 changes: 1 addition & 1 deletion did.spec
Expand Up @@ -10,7 +10,7 @@ Source: https://github.com/psss/did/releases/download/%{version}/did-%{version}.

BuildArch: noarch
BuildRequires: python-devel
Requires: python-gssapi python-nitrate python-dateutil python-urllib2-gssapi python-bugzilla
Requires: python-gssapi python-nitrate python-dateutil python2-requests-gssapi python-bugzilla
%{?el6:Requires: python-argparse}

%description
Expand Down
35 changes: 14 additions & 21 deletions did/plugins/jira.py
Expand Up @@ -34,12 +34,11 @@
from __future__ import absolute_import, unicode_literals

import re
import json
import urllib
import urllib2
import cookielib
import requests
import dateutil.parser
import urllib_gssapi
from requests_gssapi import HTTPSPNEGOAuth, DISABLED

from did.utils import log, pretty, listed
from did.base import Config, ReportError
Expand Down Expand Up @@ -88,14 +87,14 @@ def search(query, stats):
issues = []
# Fetch data from the server in batches of MAX_RESULTS issues
for batch in range(MAX_BATCHES):
result = stats.parent.session.open(
response = stats.parent.session.get(
"{0}/rest/api/latest/search?{1}".format(
stats.parent.url, urllib.urlencode({
"jql": query,
"fields": "summary,comment",
"maxResults": MAX_RESULTS,
"startAt": batch * MAX_RESULTS})))
data = json.loads(result.read())
data = response.json()
log.debug("Batch {0} result: {1} fetched".format(
batch, listed(data["issues"], "issue")))
log.data(pretty(data))
Expand Down Expand Up @@ -244,23 +243,17 @@ def __init__(self, option, name=None, parent=None, user=None):
def session(self):
""" Initialize the session """
if self._session is None:
# http://stackoverflow.com/questions/8811269/
# http://www.techchorus.net/using-cookie-jar-urllib2
cookie = cookielib.CookieJar()
self._session = urllib2.build_opener(
urllib2.HTTPSHandler(debuglevel=0),
urllib2.HTTPRedirectHandler,
urllib2.HTTPCookieProcessor(cookie),
urllib_gssapi.HTTPSPNEGOAuthHandler)

self._session = requests.Session()
log.debug("Connecting to {0}".format(self.auth_url))
if self.auth_type == 'basic':
req = urllib2.Request(self.auth_url)
req.add_data('{ "username" : "%s", "password" : "%s" }'
% (self.auth_username, self.auth_password))
req.add_header("Content-type", "application/json")
req.add_header("Accept", "application/json")
self._session.open(req)
data = {
"username" : self.auth_username,
"password" : self.auth_password }
headers = {
"Content-type": "application/json",
"Accept": "application/json"}
self._session.get(self.auth_url, headers=headers, data=data)
else:
self._session.open(self.auth_url)
gssapi_auth = HTTPSPNEGOAuth(mutual_authentication=DISABLED)
self._session.get(self.auth_url, auth=gssapi_auth)
return self._session
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -38,7 +38,7 @@ class Mock(MagicMock):
def __getattr__(cls, name):
return Mock()

MOCK_MODULES = ['gssapi', 'urllib_gssapi', 'bitly_api']
MOCK_MODULES = ['gssapi', 'requests_gssapi', 'bitly_api']
sys.modules.update((mod_name, Mock()) for mod_name in MOCK_MODULES)

# If extensions (or modules to document with autodoc) are in another directory,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -45,7 +45,7 @@
],
'gssapi': [
'gssapi',
'urllib_gssapi',
'requests_gssapi',
],
'google': [
'google-api-python-client',
Expand Down

0 comments on commit b61d50b

Please sign in to comment.