Skip to content
Open
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
30 changes: 20 additions & 10 deletions rtkit/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from urllib.parse import urlsplit, parse_qs, urlunsplit
except ImportError:
from urlparse import urlsplit, parse_qs, urlunsplit
import ssl

__all__ = [
'BasicAuthenticator',
Expand All @@ -44,14 +45,20 @@

class AbstractAuthenticator(object):
"""Abstract Base Authenticator"""
def __init__(self, username, password, url, *handlers):
def __init__(self, username, password, url, verify, *handlers):
"""
:param username: The RT Login
:param password: Plain Text Password
:param url: the url ?
:param *handlers: todo
"""
self.opener = urllib2.build_opener(*handlers)
if verify:
self.opener = urllib2.build_opener(*handlers)
else:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
self.opener = urllib2.build_opener(urllib2.HTTPSHandler(context=ctx), *handlers)
self.username = username
self.password = password
self.url = url
Expand Down Expand Up @@ -89,11 +96,11 @@ class BasicAuthenticator(AbstractAuthenticator):

resource = RTResource('http://<HOST>/REST/1.0/', '<USER>', '<PWD>', BasicAuthenticator)
"""
def __init__(self, username, password, url):
def __init__(self, username, password, url, verify=True):
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, username, password)
super(BasicAuthenticator, self).__init__(
username, password, url,
username, password, url, verify,
urllib2.HTTPBasicAuthHandler(passman)
)

Expand All @@ -114,9 +121,9 @@ class CookieAuthenticator(AbstractAuthenticator):

resource = RTResource('http://<HOST>/REST/1.0/', '<USER>', '<PWD>', CookieAuthenticator)
"""
def __init__(self, username, password, url):
def __init__(self, username, password, url, verify=True):
super(CookieAuthenticator, self).__init__(
username, password, url,
username, password, url, verify,
urllib2.HTTPCookieProcessor(cookielib.LWPCookieJar())
)
self._logged = False
Expand Down Expand Up @@ -145,8 +152,11 @@ class QueryStringAuthenticator(AbstractAuthenticator):
resource = RTResource('http://<HOST>/REST/1.0/', '<USER>', '<PWD>', QueryStringAuthenticator)
"""

def __init__(self, username, password, url):
super(QueryStringAuthenticator, self).__init__(username, password, url, QueryStringAuthHandler(username, password))
def __init__(self, username, password, url, verify=True):
super(QueryStringAuthenticator, self).__init__(
username, password, url, verify,
QueryStringAuthHandler(username, password)
)


class QueryStringAuthHandler(urllib2.BaseHandler):
Expand Down Expand Up @@ -191,13 +201,13 @@ class KerberosAuthenticator(AbstractAuthenticator):

resource = RTResource(url, None, None, KerberosAuthenticator)
"""
def __init__(self, username, password, url):
def __init__(self, username, password, url, verify=True):
try:
from urllib2_kerberos import HTTPKerberosAuthHandler
except ImportError:
raise ImportError('You need urllib2_kerberos, try: pip install urllib2_kerberos')

super(KerberosAuthenticator, self).__init__(
username, password, url,
username, password, url, verify,
HTTPKerberosAuthHandler()
)
4 changes: 2 additions & 2 deletions rtkit/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@

class RTResource(object):
"""REST Resource Object"""
def __init__(self, url, username, password, auth, **kwargs):
def __init__(self, url, username, password, auth, verify=True, **kwargs):
"""Create Connection Object

:param url: Server URL
:param username: RT Login
:param password: Password
:param auth: Instance of :py:mod:`rtkit.authenticators`
"""
self.auth = auth(username, password, url)
self.auth = auth(username, password, url, verify=verify)
self.response_cls = kwargs.get('response_class', RTResponse)
self.logger = logging.getLogger('rtkit')

Expand Down