File: ssl_certificate_verification

package info (click to toggle)
python-jenkinsapi 0.3.17-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,500 kB
  • sloc: python: 10,001; xml: 50; makefile: 31; sh: 26
file content (62 lines) | stat: -rw-r--r-- 2,183 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
SSL Certificate Verification
============================

There are times, when one would like to skip the SSL certificate verification.

For instance, the system administrator has set a different and new SSL
certificate to the Jenkins master causing `certificate verify failed` errors:

    SSLError: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Unfortunately, he's not available right now, and you have to finish your tasks
using the JenkinsAPI library by the end of today.
In these times, skipping the SSL certificate verification can be helpful.

***Note***: It's not recommended to disable SSL verifying on a regular basis.
To really fix this, please read
[this post](http://stackoverflow.com/questions/30830901/python-requests-throwing-ssl-errors/30831120#30831120)
at StackOverflow.

Disabling the SSL verify
------------------------

Before JenkinsAPI v??, if one wants to disable the SSL certificate
verification, she/he will have to pass a `Requester` instance specifying that.

It may look like this:

    from jenkinsapi.jenkins import Jenkins
    username = 'jenkins'
    password = 'changeme'
    baseurl = 'https://localhost:8443'
    jenkins = Jenkins(baseurl, username, password, requester=Requester(username, password, ssl_verify=False))

As you can see, the last line is quite long.
Not to mention that we pass the `username` and the `password` variables twice.

There must be a better way!

Disabling the SSL verify in JenkinsAPI v??
------------------------------------------

All these problems are gone thanks to `ssl_verify` argument.
You're not asked to pass a `Requester` instance anymore for just disabling
the SSL certificate verification.

This is how it looks like:

    jenkins = Jenkins(baseurl, username, password, ssl_verify=False)

Now, the code is more readable than before.

Notes
-----

If you specify both `ssl_verify` and `requester` arguments, then the
`ssl_verify` argument will be ignored.

For example:

    jenkins = jenkinsapi.Jenkins(baseurl, username, password, requester=Requester(username, password, ssl_verify=False), ssl_verify=True)

will do SSL certificate verifying.