Skip to content

Commit a4f84b2

Browse files
authored
[Python][Client] Default to system CA instead of certifi (#8108)
* Use system CA by default and remove certifi See #6506 * Use system CA by default in asyncio client * Update README_onlypackage.mustache * Result of ./bin/generate-samples.sh * Add ssl_ca_cert argument for Configuration * Result of ./bin/generate-samples.sh * Remove certifi, use system CA by default
1 parent 952cd9c commit a4f84b2

43 files changed

Lines changed: 81 additions & 156 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

modules/openapi-generator/src/main/resources/python-legacy/README_onlypackage.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@ This python library package is generated without supporting files like setup.py
2525

2626
To be able to use it, you will need these dependencies in your own package that uses this library:
2727

28-
* urllib3 >= 1.15
28+
* urllib3 >= 1.25.3
2929
* six >= 1.10
30-
* certifi
3130
* python-dateutil
3231
{{#asyncio}}
3332
* aiohttp

modules/openapi-generator/src/main/resources/python-legacy/asyncio/rest.mustache

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import re
99
import ssl
1010

1111
import aiohttp
12-
import certifi
1312
# python 2 and python 3 compatibility library
1413
from six.moves.urllib.parse import urlencode
1514

@@ -43,14 +42,7 @@ class RESTClientObject(object):
4342
if maxsize is None:
4443
maxsize = configuration.connection_pool_maxsize
4544

46-
# ca_certs
47-
if configuration.ssl_ca_cert:
48-
ca_certs = configuration.ssl_ca_cert
49-
else:
50-
# if not set certificate file, use Mozilla's root certificates.
51-
ca_certs = certifi.where()
52-
53-
ssl_context = ssl.create_default_context(cafile=ca_certs)
45+
ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert)
5446
if configuration.cert_file:
5547
ssl_context.load_cert_chain(
5648
configuration.cert_file, keyfile=configuration.key_file

modules/openapi-generator/src/main/resources/python-legacy/configuration.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ class Configuration(object):
7676
:param server_operation_variables: Mapping from operation ID to a mapping with
7777
string values to replace variables in templated server configuration.
7878
The validation of enums is performed for variables with defined enum values before.
79+
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
80+
in PEM format
7981

8082
{{#hasAuthMethods}}
8183
:Example:
@@ -174,6 +176,7 @@ conf = {{{packageName}}}.Configuration(
174176
{{/hasHttpSignatureMethods}}
175177
server_index=None, server_variables=None,
176178
server_operation_index=None, server_operation_variables=None,
179+
ssl_ca_cert=None,
177180
):
178181
"""Constructor
179182
"""
@@ -258,7 +261,7 @@ conf = {{{packageName}}}.Configuration(
258261
Set this to false to skip verifying SSL certificate when calling API
259262
from https server.
260263
"""
261-
self.ssl_ca_cert = None
264+
self.ssl_ca_cert = ssl_ca_cert
262265
"""Set this to customize the certificate file to verify the peer.
263266
"""
264267
self.cert_file = None
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
certifi >= 14.05.14
21
future; python_version<="2.7"
32
six >= 1.10
43
python_dateutil >= 2.5.3
54
setuptools >= 21.0.0
6-
urllib3 >= 1.15.1
5+
urllib3 >= 1.25.3

modules/openapi-generator/src/main/resources/python-legacy/rest.mustache

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import logging
1010
import re
1111
import ssl
1212

13-
import certifi
1413
# python 2 and python 3 compatibility library
1514
import six
1615
from six.moves.urllib.parse import urlencode
@@ -54,13 +53,6 @@ class RESTClientObject(object):
5453
else:
5554
cert_reqs = ssl.CERT_NONE
5655

57-
# ca_certs
58-
if configuration.ssl_ca_cert:
59-
ca_certs = configuration.ssl_ca_cert
60-
else:
61-
# if not set certificate file, use Mozilla's root certificates.
62-
ca_certs = certifi.where()
63-
6456
addition_pool_args = {}
6557
if configuration.assert_hostname is not None:
6658
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
@@ -83,7 +75,7 @@ class RESTClientObject(object):
8375
num_pools=pools_size,
8476
maxsize=maxsize,
8577
cert_reqs=cert_reqs,
86-
ca_certs=ca_certs,
78+
ca_certs=configuration.ssl_ca_cert,
8779
cert_file=configuration.cert_file,
8880
key_file=configuration.key_file,
8981
proxy_url=configuration.proxy,
@@ -95,7 +87,7 @@ class RESTClientObject(object):
9587
num_pools=pools_size,
9688
maxsize=maxsize,
9789
cert_reqs=cert_reqs,
98-
ca_certs=ca_certs,
90+
ca_certs=configuration.ssl_ca_cert,
9991
cert_file=configuration.cert_file,
10092
key_file=configuration.key_file,
10193
**addition_pool_args

modules/openapi-generator/src/main/resources/python-legacy/setup.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ VERSION = "{{packageVersion}}"
1616
# prerequisite: setuptools
1717
# http://pypi.python.org/pypi/setuptools
1818

19-
REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil"]
19+
REQUIRES = ["urllib3 >= 1.25.3", "six >= 1.10", "python-dateutil"]
2020
{{#asyncio}}
2121
REQUIRES.append("aiohttp >= 3.0.0")
2222
{{/asyncio}}

modules/openapi-generator/src/main/resources/python/README_onlypackage.mustache

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ This python library package is generated without supporting files like setup.py
2525

2626
To be able to use it, you will need these dependencies in your own package that uses this library:
2727

28-
* urllib3 >= 1.15
29-
* certifi
28+
* urllib3 >= 1.25.3
3029
* python-dateutil
3130
{{#asyncio}}
3231
* aiohttp

modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import re
77
import ssl
88

99
import aiohttp
10-
import certifi
1110
# python 2 and python 3 compatibility library
1211
from six.moves.urllib.parse import urlencode
1312

@@ -41,14 +40,7 @@ class RESTClientObject(object):
4140
if maxsize is None:
4241
maxsize = configuration.connection_pool_maxsize
4342

44-
# ca_certs
45-
if configuration.ssl_ca_cert:
46-
ca_certs = configuration.ssl_ca_cert
47-
else:
48-
# if not set certificate file, use Mozilla's root certificates.
49-
ca_certs = certifi.where()
50-
51-
ssl_context = ssl.create_default_context(cafile=ca_certs)
43+
ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert)
5244
if configuration.cert_file:
5345
ssl_context.load_cert_chain(
5446
configuration.cert_file, keyfile=configuration.key_file

modules/openapi-generator/src/main/resources/python/configuration.mustache

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Configuration(object):
7171
:param server_operation_variables: Mapping from operation ID to a mapping with
7272
string values to replace variables in templated server configuration.
7373
The validation of enums is performed for variables with defined enum values before.
74+
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
75+
in PEM format
7476

7577
{{#hasAuthMethods}}
7678
:Example:
@@ -169,6 +171,7 @@ conf = {{{packageName}}}.Configuration(
169171
{{/hasHttpSignatureMethods}}
170172
server_index=None, server_variables=None,
171173
server_operation_index=None, server_operation_variables=None,
174+
ssl_ca_cert=None,
172175
):
173176
"""Constructor
174177
"""
@@ -253,7 +256,7 @@ conf = {{{packageName}}}.Configuration(
253256
Set this to false to skip verifying SSL certificate when calling API
254257
from https server.
255258
"""
256-
self.ssl_ca_cert = None
259+
self.ssl_ca_cert = ssl_ca_cert
257260
"""Set this to customize the certificate file to verify the peer.
258261
"""
259262
self.cert_file = None
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
nulltype
2-
certifi >= 14.05.14
32
python_dateutil >= 2.5.3
43
setuptools >= 21.0.0
5-
urllib3 >= 1.15.1
4+
urllib3 >= 1.25.3

0 commit comments

Comments
 (0)