Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !8108

[Python][Client] Default to system CA instead of certifi

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/rparini/python-default-ca into master 4 years ago
  • Overview 0
  • Commits 7
  • Pipelines 0
  • Changes 43

Created by: rparini

Resolves #6506 (closed)

Gets the Python client to use the system Certificate Authority bundle by default for verifying ssl connections (like the Python standard library does, as described in PEP 476) instead of relying on the external certifi python package for the default. See https://github.com/OpenAPITools/openapi-generator/issues/6506 for the reasons for this change.

For the urllib3 python client this is achieved by passing configuration.ssl_ca_cert directly to urllib3.PoolManager or urllib3.ProxyManager’s ca_certs argument. Then ca_certs be None by default and in this case urllib3 (from version 1.25.3) will load the system CA certificates, as described here.

I have done the same with the asyncio python client since the ssl.create_default_context will also use the system’s default CA certificates if cafile, capath and cadata are all None, as documented here.

I have additionally:

  • Removed certifi as a dependency
  • Required urllib3 >= 1.25.3

These changes would be breaking for anyone relying on the certifi certificates, although I imagine most people’s system default CA certificates are adequate and in this case the change would not be noticed. Any user still wanting to use the certifi certificates could continue to do so by setting configuration.ssl_ca_cert=certifi.where().

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • If contributing template-only or documentation-only changes which will change sample output, build the project beforehand.
  • Run the shell script ./bin/generate-samples.shto update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • File the PR against the correct branch: master
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@taxpon @frol @mbohlool @cbornet @kenjones-cisco @tomplus @Jyhess @arun-nalla @spacether

Compare
  • master (base)

and
  • latest version
    266955a7
    7 commits, 2 years ago

43 files
+ 81
- 156

    Preferences

    File browser
    Compare changes
modules/openapi-gen‎erator/…/…/resources‎
pyt‎hon‎
asy‎ncio‎
rest.m‎ustache‎ +1 -9
README_onlypa‎ckage.mustache‎ +1 -2
configurati‎on.mustache‎ +4 -1
requiremen‎ts.mustache‎ +1 -2
rest.m‎ustache‎ +2 -10
setup.m‎ustache‎ +1 -2
python‎-legacy‎
asy‎ncio‎
rest.m‎ustache‎ +1 -9
README_onlypa‎ckage.mustache‎ +1 -2
configurati‎on.mustache‎ +4 -1
requiremen‎ts.mustache‎ +1 -2
rest.m‎ustache‎ +2 -10
setup.m‎ustache‎ +1 -1
sam‎ples‎
client/‎petstore‎
pyt‎hon‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -2
python-‎asyncio‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +1 -9
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -1
python‎-legacy‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -1
python-‎tornado‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -1
openapi‎3/client‎
extensions/x-aut‎h-id-alias/python‎
x_auth_‎id_alias‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -2
features/dynami‎c-servers/python‎
dynamic‎_servers‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -2
pets‎tore‎
pyt‎hon‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -2
python‎-legacy‎
petsto‎re_api‎
configur‎ation.py‎ +4 -1
res‎t.py‎ +2 -10
requirem‎ents.txt‎ +1 -2
setu‎p.py‎ +1 -1
modules/openapi-generator/src/main/resources/python/asyncio/rest.mustache
+ 1
- 9
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -9,7 +9,6 @@ import re
import ssl
import aiohttp
import certifi
# python 2 and python 3 compatibility library
from six.moves.urllib.parse import urlencode
@@ -43,14 +42,7 @@ class RESTClientObject(object):
if maxsize is None:
maxsize = configuration.connection_pool_maxsize
# ca_certs
if configuration.ssl_ca_cert:
ca_certs = configuration.ssl_ca_cert
else:
# if not set certificate file, use Mozilla's root certificates.
ca_certs = certifi.where()
ssl_context = ssl.create_default_context(cafile=ca_certs)
ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert)
if configuration.cert_file:
ssl_context.load_cert_chain(
configuration.cert_file, keyfile=configuration.key_file
modules/openapi-generator/src/main/resources/python/README_onlypackage.mustache
+ 1
- 2
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -25,8 +25,7 @@ This python library package is generated without supporting files like setup.py
To be able to use it, you will need these dependencies in your own package that uses this library:
* urllib3 >= 1.15
* certifi
* urllib3 >= 1.25.3
* python-dateutil
{{#asyncio}}
* aiohttp
modules/openapi-generator/src/main/resources/python/configuration.mustache
+ 4
- 1
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -73,6 +73,8 @@ class Configuration(object):
:param server_operation_variables: Mapping from operation ID to a mapping with
string values to replace variables in templated server configuration.
The validation of enums is performed for variables with defined enum values before.
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
in PEM format
{{#hasAuthMethods}}
:Example:
@@ -171,6 +173,7 @@ conf = {{{packageName}}}.Configuration(
{{/hasHttpSignatureMethods}}
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
):
"""Constructor
"""
@@ -255,7 +258,7 @@ conf = {{{packageName}}}.Configuration(
Set this to false to skip verifying SSL certificate when calling API
from https server.
"""
self.ssl_ca_cert = None
self.ssl_ca_cert = ssl_ca_cert
"""Set this to customize the certificate file to verify the peer.
"""
self.cert_file = None
modules/openapi-generator/src/main/resources/python/requirements.mustache
+ 1
- 2
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE

nulltype
certifi >= 14.05.14
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1
urllib3 >= 1.25.3
modules/openapi-generator/src/main/resources/python/rest.mustache
+ 2
- 10
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -9,7 +9,6 @@ import re
import ssl
from urllib.parse import urlencode
import certifi
import urllib3
from {{packageName}}.exceptions import ApiException, UnauthorizedException, ForbiddenException, NotFoundException, ServiceException, ApiValueError
@@ -50,13 +49,6 @@ class RESTClientObject(object):
else:
cert_reqs = ssl.CERT_NONE
# ca_certs
if configuration.ssl_ca_cert:
ca_certs = configuration.ssl_ca_cert
else:
# if not set certificate file, use Mozilla's root certificates.
ca_certs = certifi.where()
addition_pool_args = {}
if configuration.assert_hostname is not None:
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
@@ -79,7 +71,7 @@ class RESTClientObject(object):
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
ca_certs=ca_certs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
proxy_url=configuration.proxy,
@@ -91,7 +83,7 @@ class RESTClientObject(object):
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
ca_certs=ca_certs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
**addition_pool_args
modules/openapi-generator/src/main/resources/python/setup.mustache
+ 1
- 2
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -17,8 +17,7 @@ VERSION = "{{packageVersion}}"
# http://pypi.python.org/pypi/setuptools
REQUIRES = [
"urllib3 >= 1.15",
"certifi",
"urllib3 >= 1.25.3",
"python-dateutil",
"nulltype",
{{#asyncio}}
modules/openapi-generator/src/main/resources/python-legacy/asyncio/rest.mustache
+ 1
- 9
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -9,7 +9,6 @@ import re
import ssl
import aiohttp
import certifi
# python 2 and python 3 compatibility library
from six.moves.urllib.parse import urlencode
@@ -43,14 +42,7 @@ class RESTClientObject(object):
if maxsize is None:
maxsize = configuration.connection_pool_maxsize
# ca_certs
if configuration.ssl_ca_cert:
ca_certs = configuration.ssl_ca_cert
else:
# if not set certificate file, use Mozilla's root certificates.
ca_certs = certifi.where()
ssl_context = ssl.create_default_context(cafile=ca_certs)
ssl_context = ssl.create_default_context(cafile=configuration.ssl_ca_cert)
if configuration.cert_file:
ssl_context.load_cert_chain(
configuration.cert_file, keyfile=configuration.key_file
modules/openapi-generator/src/main/resources/python-legacy/README_onlypackage.mustache
+ 1
- 2
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -25,9 +25,8 @@ This python library package is generated without supporting files like setup.py
To be able to use it, you will need these dependencies in your own package that uses this library:
* urllib3 >= 1.15
* urllib3 >= 1.25.3
* six >= 1.10
* certifi
* python-dateutil
{{#asyncio}}
* aiohttp
modules/openapi-generator/src/main/resources/python-legacy/configuration.mustache
+ 4
- 1
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -76,6 +76,8 @@ class Configuration(object):
:param server_operation_variables: Mapping from operation ID to a mapping with
string values to replace variables in templated server configuration.
The validation of enums is performed for variables with defined enum values before.
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
in PEM format
{{#hasAuthMethods}}
:Example:
@@ -174,6 +176,7 @@ conf = {{{packageName}}}.Configuration(
{{/hasHttpSignatureMethods}}
server_index=None, server_variables=None,
server_operation_index=None, server_operation_variables=None,
ssl_ca_cert=None,
):
"""Constructor
"""
@@ -258,7 +261,7 @@ conf = {{{packageName}}}.Configuration(
Set this to false to skip verifying SSL certificate when calling API
from https server.
"""
self.ssl_ca_cert = None
self.ssl_ca_cert = ssl_ca_cert
"""Set this to customize the certificate file to verify the peer.
"""
self.cert_file = None
modules/openapi-generator/src/main/resources/python-legacy/requirements.mustache
+ 1
- 2
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE

certifi >= 14.05.14
future; python_version<="2.7"
six >= 1.10
python_dateutil >= 2.5.3
setuptools >= 21.0.0
urllib3 >= 1.15.1
urllib3 >= 1.25.3
modules/openapi-generator/src/main/resources/python-legacy/rest.mustache
+ 2
- 10
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -10,7 +10,6 @@ import logging
import re
import ssl
import certifi
# python 2 and python 3 compatibility library
import six
from six.moves.urllib.parse import urlencode
@@ -54,13 +53,6 @@ class RESTClientObject(object):
else:
cert_reqs = ssl.CERT_NONE
# ca_certs
if configuration.ssl_ca_cert:
ca_certs = configuration.ssl_ca_cert
else:
# if not set certificate file, use Mozilla's root certificates.
ca_certs = certifi.where()
addition_pool_args = {}
if configuration.assert_hostname is not None:
addition_pool_args['assert_hostname'] = configuration.assert_hostname # noqa: E501
@@ -83,7 +75,7 @@ class RESTClientObject(object):
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
ca_certs=ca_certs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
proxy_url=configuration.proxy,
@@ -95,7 +87,7 @@ class RESTClientObject(object):
num_pools=pools_size,
maxsize=maxsize,
cert_reqs=cert_reqs,
ca_certs=ca_certs,
ca_certs=configuration.ssl_ca_cert,
cert_file=configuration.cert_file,
key_file=configuration.key_file,
**addition_pool_args
modules/openapi-generator/src/main/resources/python-legacy/setup.mustache
+ 1
- 1
  • View file @ 266955a7

  • Edit in single-file editor

  • Open in Web IDE


@@ -16,7 +16,7 @@ VERSION = "{{packageVersion}}"
# prerequisite: setuptools
# http://pypi.python.org/pypi/setuptools
REQUIRES = ["urllib3 >= 1.15", "six >= 1.10", "certifi", "python-dateutil"]
REQUIRES = ["urllib3 >= 1.25.3", "six >= 1.10", "python-dateutil"]
{{#asyncio}}
REQUIRES.append("aiohttp >= 3.0.0")
{{/asyncio}}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
2
Breaking change (with fallback) Client: Python
2
Breaking change (with fallback) Client: Python
    Assign labels
  • Manage project labels

Milestone
5.0.0
5.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
2
2 participants
Administrator
Tomasz Prus
Reference: OpenAPITools/openapi-generator!8108
Source branch: github/fork/rparini/python-default-ca

Menu

Explore Projects Groups Snippets