Skip to content

Commit

Permalink
fix issue #68
Browse files Browse the repository at this point in the history
dixudx committed Nov 30, 2015

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent a19c1f3 commit 9937fe4
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions rtcclient/client.py
Original file line number Diff line number Diff line change
@@ -26,6 +26,10 @@ class RTCClient(RTCBase):
:param searchpath: the folder to store your templates.
If `None`, the default search path
(/your/site-packages/rtcclient/templates) will be loaded.
:param ends_with_jazz: (optional) Set to `True` (default) if
the url ends with 'jazz', otherwise to `False` if with 'ccm'
(Refer to issue #68 for details)
:type ends_with_jazz: bool
Tips: You can also customize your preferred properties to be returned
by specified `returned_properties` when the called methods have
@@ -40,7 +44,8 @@ class RTCClient(RTCBase):

log = logging.getLogger("client.RTCClient")

def __init__(self, url, username, password, searchpath=None):
def __init__(self, url, username, password, searchpath=None,
ends_with_jazz=True):
"""Initialization
See params above
@@ -49,6 +54,11 @@ def __init__(self, url, username, password, searchpath=None):
self.username = username
self.password = password
RTCBase.__init__(self, url)

if not isinstance(ends_with_jazz, bool):
raise exception.BadValue("ends_with_jazz is not boolean")

self.jazz = ends_with_jazz
self.headers = self._get_headers()
if searchpath is None:
self.searchpath = _search_path
@@ -64,10 +74,16 @@ def get_rtc_obj(self):
return self

def _get_headers(self):
if self.jazz is True:
_allow_redirects = True
else:
_allow_redirects = False

_headers = {"Content-Type": self.CONTENT_XML}
resp = self.get(self.url + "/authenticated/identity",
verify=False,
headers=_headers)
headers=_headers,
allow_redirects=_allow_redirects)

_headers["Content-Type"] = self.CONTENT_URL_ENCODED
_headers["Cookie"] = resp.headers.get("set-cookie")
@@ -77,19 +93,30 @@ def _get_headers(self):
resp = self.post(self.url + "/authenticated/j_security_check",
data=credentials,
verify=False,
headers=_headers)
headers=_headers,
allow_redirects=_allow_redirects)

# authfailed
authfailed = resp.headers.get("x-com-ibm-team-repository-web-auth-msg")
if authfailed == "authfailed":
raise exception.RTCException("Authentication Failed: "
"Invalid username or password")

# fix issue #68
if not _allow_redirects:
_headers["Cookie"] = resp.headers.get("set-cookie")

resp = self.get(self.url + "/authenticated/identity",
verify=False,
headers=_headers)
headers=_headers,
allow_redirects=self.allow_redirects)

# fix issue #68
if not _allow_redirects:
_headers["Cookie"] += "; " + resp.headers.get("set-cookie")
else:
_headers["Cookie"] = resp.headers.get("set-cookie")

_headers["Cookie"] = resp.headers.get("set-cookie")
_headers["Accept"] = self.CONTENT_XML
return _headers

0 comments on commit 9937fe4

Please sign in to comment.