Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow disable ssl verification and specify certificate files #4

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 27 additions & 0 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ Most of the time, the API requires authentication. It can be done in 2 different
The API key can be found on users account page when logged in, on the right-hand pane of
the default layout.

SSL Cert Verification
+++++++++++++++++++++

You can verify SSL certificates for HTTPS requests, just like a web browser. To check a host's SSL certificate, you can use the ``sslverify`` argument:

.. code-block:: python

redmine = Redmine('https://demo.redmine.org', sslverify=True)

It's also possible to ignore verifying the SSL certificate if you set ``sslverify`` to False.

.. code-block:: python

redmine = Redmine('https://demo.redmine.org', sslverify=False)

By default, sslverify is set to True, Option sslverify only applies to host certs.

You can also specify a local cert to use as client side certificate, as a single file (containing the private key and the certificate) or as a tuple of both file’s path:

.. code-block:: python

redmine = Redmine('https://demo.redmine.org', sslcert=('/path/server.crt', '/path/key'))

.. code-block:: python

redmine = Redmine('https://demo.redmine.org', sslcert='/path/server.pem')

Impersonation
+++++++++++++

Expand Down
7 changes: 7 additions & 0 deletions redmine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def __init__(self, url, **kwargs):
self.impersonate = kwargs.get('impersonate', None)
self.date_format = kwargs.get('date_format', '%Y-%m-%d')
self.datetime_format = kwargs.get('datetime_format', '%Y-%m-%dT%H:%M:%SZ')
self.sslverify = kwargs.get('sslverify', None)
self.sslcert = kwargs.get('sslcert', None)

def __getattr__(self, resource):
"""Returns either ResourceSet or Resource object depending on the method used on the ResourceManager"""
Expand Down Expand Up @@ -67,6 +69,11 @@ def request(self, method, url, headers=None, params=None, data=None):
else:
kwargs['auth'] = (self.username, self.password)

if self.sslverify is not None:
kwargs['verify'] = self.sslverify
if self.sslcert is not None:
kwargs['cert'] = self.sslcert

response = getattr(requests, method)(url, **kwargs)

if response.status_code in (200, 201):
Expand Down