Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to set 'ssl_verify' config for jira plugin #169

Merged
merged 1 commit into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions did/plugins/jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
prefix = JIRA
project = ORG
url = https://issues.jboss.org/
ssl_verify = true

Configuration example (basic authentication)::

Expand All @@ -22,8 +23,9 @@
auth_username = username
auth_password = password

Notes:

Notes:
Use ``ssl_verify`` to enable/disable SSL verification (default: true)
* ``auth_url`` parameter is optional. If not provided,
``url + "/step-auth-gss"`` will be used for authentication.
* ``auth_type`` parameter is optional, default value is 'gss'.
Expand All @@ -37,7 +39,9 @@
import urllib
import urllib2
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
import dateutil.parser
import distutils.util
from requests_gssapi import HTTPSPNEGOAuth, DISABLED

from did.utils import log, pretty, listed
Expand All @@ -53,19 +57,23 @@
# Supported authentication types
AUTH_TYPES = ["gss", "basic"]

# Enable ssl verify
SSL_VERIFY = True

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Issue Investigator
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

class Issue(object):
""" Jira issue investigator """

def __init__(self, issue=None, prefix=None):
def __init__(self, issue=None, prefix=None, ssl_verify=SSL_VERIFY):
""" Initialize issue """
if issue is None:
return
self.issue = issue
self.key = issue["key"]
self.ssl_verify = ssl_verify
self.summary = issue["fields"]["summary"]
self.comments = issue["fields"]["comment"]["comments"]
matched = re.match(r"(\w+)-(\d+)", self.key)
Expand Down Expand Up @@ -219,6 +227,15 @@ def __init__(self, option, name=None, parent=None, user=None):
raise ReportError(
"`auth_password` is only valid for basic authentication"
+ " (section [{0}])".format(option))
# SSL verification
if "ssl_verify" in config:
try:
self.ssl_verify = distutils.util.strtobool(config["ssl_verify"])
except Exception as e:
raise ReportError("Error when parse `ssl_verify`: %s" %str(e))
else:
self.ssl_verify = SSL_VERIFY

# Make sure we have project set
if "project" not in config:
raise ReportError(
Expand All @@ -245,12 +262,15 @@ def session(self):
if self._session is None:
self._session = requests.Session()
log.debug("Connecting to {0}".format(self.auth_url))
# Disable SSL warning when ssl_verify is False
if not self.ssl_verify:
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
if self.auth_type == 'basic':
basic_auth = (self.auth_username, self.auth_password)
response = self._session.get(self.auth_url, auth=basic_auth)
response = self._session.get(self.auth_url, auth=basic_auth, verify=self.ssl_verify)
else:
gssapi_auth = HTTPSPNEGOAuth(mutual_authentication=DISABLED)
response = self._session.get(self.auth_url, auth=gssapi_auth)
response = self._session.get(self.auth_url, auth=gssapi_auth, verify=self.ssl_verify)
try:
response.raise_for_status()
except requests.exceptions.HTTPError as error:
Expand Down
1 change: 1 addition & 0 deletions examples/config
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type = jira
prefix = JIRA
project = ORG
url = https://issues.jboss.org/
ssl_verify = true

[sentry]
type = sentry
Expand Down
6 changes: 6 additions & 0 deletions tests/plugins/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def test_config_basic_auth():
auth_type = basic
auth_username = tom
auth_password = motak
ssl_verify = 0
""")
stats = JiraStats("jira")

Expand All @@ -64,6 +65,11 @@ def test_config_gss_and_password():
+ "auth_type = gss\n"
+ "auth_password = tom\n")

def test_config_invaliad_ssl_verify():
""" Test ssl_verify with wrong bool value """
assert_conf_error(CONFIG + "\n"
+ "ssl_verify = ss\n")

def assert_conf_error(config, expected_error=ReportError):
""" Test given configuration and check that given error type is raised """
did.base.Config(config)
Expand Down