Use use ssl_context or don't but don't mix (#714)

* Use original SSL process and add SSLContext

Not going to deprecate and replace with SSLContext.
But instead give option for using SSLContext next to the original way of
handling SSL.
This commit is contained in:
Nick Lang
2018-03-04 15:09:40 -08:00
committed by GitHub
parent 4438ea75a1
commit 058d38f0ae
5 changed files with 71 additions and 63 deletions
+7 -10
View File
@@ -45,23 +45,20 @@ Connection Selector
Urllib3HttpConnection (default connection_class)
------------------------------------------------
Deprecation Notice: `use_ssl`, `verify_certs`, `ca_certs` and `ssl_version` are being
deprecated in favor of using a `SSLContext` (https://docs.python.org/3/library/ssl.html#ssl.SSLContext) object.
You can continue to use the deprecated parameters and an `SSLContext` will be created for you.
If you want to create your own `SSLContext` object you can create one natively using the
python SSL library with the `create_default_context` (https://docs.python.org/3/library/ssl.html#ssl.create_default_context) method
or you can use the wrapper function :function:`~elasticsearch.connection.http_urllib3.create_ssl_context`.
If you have complex SSL logic for connecting to Elasticsearch using an `SSLContext` object
might be more helpful. You can create one natively using the python SSL library with the
`create_default_context` (https://docs.python.org/3/library/ssl.html#ssl.create_default_context) method.
To create an `SSLContext` object you only need to use one of cafile, capath or cadata::
>>> from elasticsearch.connection import create_ssl_context
>>> context = create_ssl_context(cafile=None, capath=None, cadata=None)
>>> from ssl import create_default_context
>>> context = create_default_context(cafile=None, capath=None, cadata=None)
* `cafile` is the path to your CA File
* `capath` is the directory of a collection of CA's
* `cadata` is either an ASCII string of one or more PEM-encoded certificates or a bytes-like object of DER-encoded certificates.
Please note that the use of SSLContext is only available for Urllib3.
.. autoclass:: Urllib3HttpConnection
:members:
+2 -2
View File
@@ -200,9 +200,9 @@ elasticsearch cluster, including certificate verification and http auth::
# SSL client authentication using client_cert and client_key
from elasticsearch.connection import create_ssl_context
from ssl import create_default_context
context = create_ssl_context(cafile="path/to/cert.pem")
context = create_default_context(cafile="path/to/cert.pem")
es = Elasticsearch(
['localhost', 'otherhost'],
http_auth=('user', 'secret'),