import requests
+import urlparse
from jenkinsapi.exceptions import JenkinsAPIException
# import logging
VALID_STATUS_CODES = [200,]
- def __init__(self, username=None, password=None, ssl_verify=True):
+ def __init__(self, username=None, password=None, ssl_verify=True, baseurl=None):
if username:
assert password, 'Cannot set a username without a password!'
+ self.base_scheme = urlparse.urlsplit(baseurl).scheme if baseurl else None
self.username = username
self.password = password
self.ssl_verify = ssl_verify
requestKwargs['data'] = data
return requestKwargs
+ def _update_url_scheme(self, url):
+ """
+ Updates scheme of given url to the one used in Jenkins baseurl.
+ """
+ if self.base_scheme and not url.startswith("%s://" % self.base_scheme):
+ url_split = urlparse.urlsplit(url)
+ url = urlparse.urlunsplit([self.base_scheme, url_split.netloc, url_split.path, url_split.query,
+ url_split.fragment])
+ return url
+
def get_url(self, url, params=None, headers=None):
requestKwargs = self.get_request_dict(url, params, None, headers)
+ url = self._update_url_scheme(url)
return requests.get(url, **requestKwargs)
-
def post_url(self, url, params=None, data=None, headers=None):
requestKwargs = self.get_request_dict(url, params, data, headers)
+ url = self._update_url_scheme(url)
return requests.post(url, **requestKwargs)
def post_xml_and_confirm_status(self, url, params=None, data=None, valid=None):