Skip to content

Commit 0e70dd9

Browse files
author
Gauvain Pocentek
authored
Merge pull request #294 from wayfair/feature_internal_cert_configuration
Support SSL verification via internal CA bundle
2 parents 657f011 + 4af4748 commit 0e70dd9

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

docs/cli.rst

+4-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ parameters. You can override the values in each GitLab server section.
6161
- Possible values
6262
- Description
6363
* - ``ssl_verify``
64-
- ``True`` or ``False``
65-
- Verify the SSL certificate. Set to ``False`` if your SSL certificate is
66-
auto-signed.
64+
- ``True``, ``False``, or a ``str``
65+
- Verify the SSL certificate. Set to ``False`` to disable verification,
66+
though this will create warnings. Any other value is interpreted as path
67+
to a CA_BUNDLE file or directory with certificates of trusted CAs.
6768
* - ``timeout``
6869
- Integer
6970
- Number of seconds to wait for an answer before failing.

gitlab/config.py

+17
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,28 @@ def __init__(self, gitlab_id=None, config_files=None):
6161
self.ssl_verify = True
6262
try:
6363
self.ssl_verify = self._config.getboolean('global', 'ssl_verify')
64+
except ValueError:
65+
# Value Error means the option exists but isn't a boolean.
66+
# Get as a string instead as it should then be a local path to a
67+
# CA bundle.
68+
try:
69+
self.ssl_verify = self._config.get('global', 'ssl_verify')
70+
except Exception:
71+
pass
6472
except Exception:
6573
pass
6674
try:
6775
self.ssl_verify = self._config.getboolean(self.gitlab_id,
6876
'ssl_verify')
77+
except ValueError:
78+
# Value Error means the option exists but isn't a boolean.
79+
# Get as a string instead as it should then be a local path to a
80+
# CA bundle.
81+
try:
82+
self.ssl_verify = self._config.get(self.gitlab_id,
83+
'ssl_verify')
84+
except Exception:
85+
pass
6986
except Exception:
7087
pass
7188

gitlab/tests/test_config.py

+15
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
private_token = GHIJKL
4141
ssl_verify = false
4242
timeout = 10
43+
44+
[three]
45+
url = https://three.url
46+
private_token = MNOPQR
47+
ssl_verify = /path/to/CA/bundle.crt
4348
"""
4449

4550
no_default_config = u"""[global]
@@ -109,3 +114,13 @@ def test_valid_data(self, m_open):
109114
self.assertEqual("GHIJKL", cp.token)
110115
self.assertEqual(10, cp.timeout)
111116
self.assertEqual(False, cp.ssl_verify)
117+
118+
fd = six.StringIO(valid_config)
119+
fd.close = mock.Mock(return_value=None)
120+
m_open.return_value = fd
121+
cp = config.GitlabConfigParser(gitlab_id="three")
122+
self.assertEqual("three", cp.gitlab_id)
123+
self.assertEqual("https://three.url", cp.url)
124+
self.assertEqual("MNOPQR", cp.token)
125+
self.assertEqual(2, cp.timeout)
126+
self.assertEqual("/path/to/CA/bundle.crt", cp.ssl_verify)

0 commit comments

Comments
 (0)