mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Define Ciphers config conditionally
We only expose the `Ciphers` config parameter in versions of Python that support it (i.e., >= Python 2.7).
This commit is contained in:
parent
cdca314298
commit
c353828351
@ -140,25 +140,12 @@ class Config(object):
|
|||||||
def is_ssl(self):
|
def is_ssl(self):
|
||||||
return self.certfile or self.keyfile
|
return self.certfile or self.keyfile
|
||||||
|
|
||||||
def _load_attrs(self, attrs, version=sys.version_info):
|
|
||||||
for attr in attrs:
|
|
||||||
# suppress_ragged_eofs/do_handshake_on_connect are booleans that can
|
|
||||||
# be False hence we use hasattr instead of getattr(self, attr, None).
|
|
||||||
if hasattr(self, attr) and version >= sys.version_info:
|
|
||||||
yield (attr, getattr(self, attr))
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ssl_options(self):
|
def ssl_options(self):
|
||||||
|
|
||||||
opts = {}
|
opts = {}
|
||||||
|
for name, value in self.settings.items():
|
||||||
opts.update(self._load_attrs(('certfile', 'keyfile', 'cert_reqs', 'ssl_version',
|
if value.section == 'Ssl':
|
||||||
'ca_certs', 'suppress_ragged_eofs', 'do_handshake_on_connect')))
|
opts[name] = value.get()
|
||||||
|
|
||||||
# The `ciphers` kwarg was only available in Python 2.7, so don't make
|
|
||||||
# it available for us in older versions on Python.
|
|
||||||
opts.update(self._load_attrs(('ciphers'), version=(2, 7)))
|
|
||||||
|
|
||||||
return opts
|
return opts
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -1557,14 +1544,13 @@ class DoHandshakeOnConnect(Setting):
|
|||||||
Whether to perform SSL handshake on socket connect (see stdlib ssl module's)
|
Whether to perform SSL handshake on socket connect (see stdlib ssl module's)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
class Ciphers(Setting):
|
if sys.version_info >= (2, 7):
|
||||||
name = "ciphers"
|
class Ciphers(Setting):
|
||||||
section = "Ssl"
|
name = "ciphers"
|
||||||
cli = ["--ciphers"]
|
section = "Ssl"
|
||||||
validator = validate_string
|
cli = ["--ciphers"]
|
||||||
default = 'TLSv1'
|
validator = validate_string
|
||||||
desc = """\
|
default = 'TLSv1'
|
||||||
Ciphers to use (see stdlib ssl module's)
|
desc = """\
|
||||||
|
Ciphers to use (see stdlib ssl module's)
|
||||||
Note, this value is only available in Python 2.7+ and is ignored in older versions of Python.
|
"""
|
||||||
"""
|
|
||||||
|
|||||||
@ -8,13 +8,17 @@
|
|||||||
# stdlib
|
# stdlib
|
||||||
import inspect
|
import inspect
|
||||||
import ssl
|
import ssl
|
||||||
|
import sys
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
# gunicorn
|
# gunicorn
|
||||||
from gunicorn.config import KeyFile, CertFile, SSLVersion, CACerts, \
|
from gunicorn.config import KeyFile, CertFile, SSLVersion, CACerts, \
|
||||||
SuppressRaggedEOFs, DoHandshakeOnConnect, Ciphers, Setting, validate_bool, validate_string, \
|
SuppressRaggedEOFs, DoHandshakeOnConnect, Setting, validate_bool, validate_string, \
|
||||||
validate_pos_int
|
validate_pos_int
|
||||||
|
|
||||||
|
if sys.version_info >= (2, 7):
|
||||||
|
from gunicorn.config import Ciphers
|
||||||
|
|
||||||
class SSLTestCase(TestCase):
|
class SSLTestCase(TestCase):
|
||||||
def test_settings_classes(self):
|
def test_settings_classes(self):
|
||||||
""" Tests all settings options and their defaults.
|
""" Tests all settings options and their defaults.
|
||||||
@ -59,8 +63,10 @@ class SSLTestCase(TestCase):
|
|||||||
self.assertEquals(DoHandshakeOnConnect.action, 'store_true')
|
self.assertEquals(DoHandshakeOnConnect.action, 'store_true')
|
||||||
self.assertEquals(DoHandshakeOnConnect.default, False)
|
self.assertEquals(DoHandshakeOnConnect.default, False)
|
||||||
|
|
||||||
self.assertTrue(issubclass(Ciphers, Setting))
|
|
||||||
self.assertEquals(Ciphers.name, 'ciphers')
|
if sys.version_info >= (2, 7):
|
||||||
self.assertEquals(Ciphers.section, 'Ssl')
|
self.assertTrue(issubclass(Ciphers, Setting))
|
||||||
self.assertEquals(Ciphers.cli, ['--ciphers'])
|
self.assertEquals(Ciphers.name, 'ciphers')
|
||||||
self.assertEquals(Ciphers.default, 'TLSv1')
|
self.assertEquals(Ciphers.section, 'Ssl')
|
||||||
|
self.assertEquals(Ciphers.cli, ['--ciphers'])
|
||||||
|
self.assertEquals(Ciphers.default, 'TLSv1')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user