Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Add Ability to ignore SSL Certificate Errors (redux) #13

Merged
merged 5 commits into from

2 participants

@rdodev

As per our discussion last night, I've made the changes to the code and tests needed to add a global flag so that autojenkins can be used when when jenkins is secured using default/self-signed certificates.

rdodev added some commits
@rdodev rdodev Update autojenkins/jobs.py
Added ability to ignore SSL certificate errors in case Jenkins is behind SSL with self-signed certs.
51345b2
@rdodev rdodev Update autojenkins/tests/test_unit_jobs.py
Fixing Travis fail.
c446484
@rdodev rdodev Update autojenkins/jobs.py
Adding global flag to ignore SSL certificate errors.
3ec54ce
@rdodev rdodev Update autojenkins/tests/test_unit_jobs.py
Fixed tests for new changes to global SSL Certificate Errors flag.
891eaa1
@rdodev rdodev Update docs/intro.rst
Added global flag documentation.
bf220ad
@rdodev

Just added brief usage documentation

@txels
Owner

Nice thanks.
Somehow I thought more of the requests code was centralised in a couple of methods, avoiding this much duplication. I will probably simplify this after merge. I will also be releasing a version to PyPI shortly after.

@txels txels merged commit d64eee3 into txels:master

1 check passed

Details default The Travis build passed
@txels
Owner

I have done some cleanup, added you to the contributors list, and released to PyPI as 0.9.0.

@rdodev

Excellent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2012
  1. @rdodev

    Update autojenkins/jobs.py

    rdodev authored
    Added ability to ignore SSL certificate errors in case Jenkins is behind SSL with self-signed certs.
  2. @rdodev

    Update autojenkins/tests/test_unit_jobs.py

    rdodev authored
    Fixing Travis fail.
Commits on Nov 2, 2012
  1. @rdodev

    Update autojenkins/jobs.py

    rdodev authored
    Adding global flag to ignore SSL certificate errors.
  2. @rdodev

    Update autojenkins/tests/test_unit_jobs.py

    rdodev authored
    Fixed tests for new changes to global SSL Certificate Errors flag.
  3. @rdodev

    Update docs/intro.rst

    rdodev authored
    Added global flag documentation.
This page is out of date. Refresh to see the latest.
View
24 autojenkins/jobs.py
@@ -50,9 +50,10 @@ def _validate(response):
class Jenkins(object):
"""Main class to interact with a Jenkins server."""
- def __init__(self, base_url, auth=None):
+ def __init__(self, base_url, auth=None, verify_ssl_cert=True):
self.ROOT = base_url
self.auth = auth
+ self.verify_ssl_cert = verify_ssl_cert
def _build_url(self, command, *args):
"""
@@ -68,12 +69,12 @@ def _other_url(self, root, command, *args):
def _get(self, url_pattern, *args):
response = requests.get(self._build_url(url_pattern, *args),
- auth=self.auth)
+ auth=self.auth, verify=self.verify_ssl_cert)
return _validate(response)
def _post(self, url_pattern, *args):
response = requests.post(self._build_url(url_pattern, *args),
- auth=self.auth)
+ auth=self.auth, verify=self.verify_ssl_cert)
return _validate(response)
def all_jobs(self):
@@ -131,7 +132,7 @@ def last_result(self, jobname):
Obtain results from last execution.
"""
last_result_url = self.job_info(jobname)['lastBuild']['url']
- response = requests.get(last_result_url + API, auth=self.auth)
+ response = requests.get(last_result_url + API, auth=self.auth, verify=self.verify_ssl_cert)
return eval(response.content)
def last_success(self, jobname):
@@ -155,7 +156,8 @@ def set_config_xml(self, jobname, config):
return requests.post(self._build_url(CONFIG, jobname),
data=config,
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def create(self, jobname, config_file, **context):
"""
@@ -172,7 +174,8 @@ def create(self, jobname, config_file, **context):
data=content,
params=params,
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def create_copy(self, jobname, template_job, enable=True, **context):
"""
@@ -194,7 +197,8 @@ def create_copy(self, jobname, template_job, enable=True, **context):
data=config,
params={'name': jobname},
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def transfer(self, jobname, to_server):
"""
@@ -205,7 +209,8 @@ def transfer(self, jobname, to_server):
data=config,
params={'name': jobname},
headers={'Content-Type': 'application/xml'},
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def copy(self, jobname, copy_from='template'):
"""
@@ -213,7 +218,8 @@ def copy(self, jobname, copy_from='template'):
"""
params = {'name': jobname, 'mode': 'copy', 'from': copy_from}
return requests.post(self._build_url(NEWJOB), params=params,
- auth=self.auth)
+ auth=self.auth,
+ verify=self.verify_ssl_cert)
def build(self, jobname, wait=False, grace=10):
"""
View
17 autojenkins/tests/test_unit_jobs.py
@@ -41,6 +41,7 @@ def test_all_jobs(self, requests):
requests.get.return_value = mock_response(response)
jobs = self.jenkins.all_jobs()
requests.get.assert_called_once_with('http://jenkins/api/python',
+ verify=True,
auth=None)
self.assertEqual(jobs, [('job1', 'blue')])
@@ -58,7 +59,7 @@ def test_last_result(self, requests, *args):
self.assertEqual(23, response['result'])
self.assertEqual(
(('https://builds.apache.org/job/Solr-Trunk/1783/api/python',),
- {'auth': None}),
+ {'auth': None, 'verify': True}),
requests.get.call_args_list[1]
)
@@ -75,6 +76,7 @@ def test_get_methods_with_jobname(self, case, requests):
response = getattr(self.jenkins, method)('name')
requests.get.assert_called_once_with(
'http://jenkins/' + url.format('name'),
+ verify=True,
auth=None)
getattr(self, 'checks_{0}'.format(method))(response)
@@ -84,6 +86,7 @@ def test_build_info(self, requests):
self.jenkins.build_info('name', 3)
requests.get.assert_called_once_with(
'http://jenkins/' + url,
+ verify=True,
auth=None)
def check_result(self, response, route, value):
@@ -142,7 +145,7 @@ def test_create(self, requests):
auth=None,
headers={'Content-Type': 'application/xml'},
params={'name': 'job'},
- data=CFG)
+ data=CFG, verify=True)
def test_create_copy(self, requests):
requests.get.return_value = mock_response('create_copy.txt')
@@ -154,7 +157,7 @@ def test_create_copy(self, requests):
auth=None,
headers={'Content-Type': 'application/xml'},
params={'name': 'job'},
- data=CFG)
+ data=CFG, verify= True)
def test_transfer(self, requests):
requests.get.return_value = mock_response('transfer.txt')
@@ -166,7 +169,7 @@ def test_transfer(self, requests):
auth=None,
headers={'Content-Type': 'application/xml'},
params={'name': 'job'},
- data=CFG)
+ data=CFG, verify=True)
@data(
('build', 'job/{0}/build'),
@@ -182,7 +185,7 @@ def test_post_methods_with_jobname_no_data(self, case, requests):
self.assertEqual(302, response.status_code)
requests.post.assert_called_once_with(
'http://jenkins/' + url.format('name'),
- auth=None)
+ auth=None, verify=True)
def test_set_config_xml(self, requests):
requests.post.return_value = Mock()
@@ -194,7 +197,7 @@ def test_set_config_xml(self, requests):
'http://jenkins/job/name/config.xml',
headers={'Content-Type': 'application/xml'},
data=CFG,
- auth=None)
+ auth=None, verify=True)
@patch('autojenkins.jobs.time')
@patch('autojenkins.jobs.Jenkins.last_result')
@@ -208,7 +211,7 @@ def test_build_with_wait(self, wait_for_build, last_result, time,
self.assertEqual({'result': 'HELLO'}, result)
requests.post.assert_called_once_with(
'http://jenkins/job/name/build',
- auth=None)
+ auth=None, verify=True)
last_result.assert_called_once_with('name')
time.sleep.assert_called_once_with(10)
View
3  docs/intro.rst
@@ -25,6 +25,9 @@ Sample use:
from autojenkins import Jenkins
j = Jenkins('http://jenkins.pe.local')
+ #You can now add verify_ssl_cert=False argument to the instantiation
+ #so that all requests will ignore SSL certificate errros, should you need that
+ #i.e. j = Jenkins('https://my.secure.jenkins', verify_ssl_cert=False)
# trigger a manual build and check results
j.build('warehouse-screens-us544_login')
Something went wrong with that request. Please try again.