3 ²˜‚]›%ã @sÎddlZddlZddlZddlmZmZddlmZddl Z ddl Z ddl m Z dZ dZyddlZejƒZWnek r€YnXddlmZddlmZmZmZmZdd lmZd d „ZGd d „d eƒZdS)éN)ÚReadTimeoutErrorÚSSLError)ÚRetry)Ú decodestringé)Ú Connectioné)ÚConnectionErrorÚImproperlyConfiguredÚConnectionTimeoutr)Ú urlencodecKstjf|Ž}|S)z¿ A helper function around creating an SSL context https://docs.python.org/3/library/ssl.html#context-creation Accepts kwargs in the same manner as `create_default_context`. )ÚsslÚcreate_default_context)ÚkwargsÚctx©rúN/tmp/pip-build-z81i1n8o/elasticsearch/elasticsearch/connection/http_urllib3.pyÚcreate_ssl_context"s rcs`eZdZdZddddeddddddddddddf‡fdd „ Zdddfdfd d „Zd d „Z‡ZS)ÚUrllib3HttpConnectionaY Default connection class using the `urllib3` library and the http protocol. :arg host: hostname of the node (default: localhost) :arg port: port to use (integer, default: 9200) :arg url_prefix: optional url prefix for elasticsearch :arg timeout: default timeout in seconds (float, default: 10) :arg http_auth: optional http auth information as either ':' separated string or a tuple :arg use_ssl: use ssl for the connection if `True` :arg verify_certs: whether to verify SSL certificates :arg ssl_show_warn: show warning when verify certs is disabled :arg ca_certs: optional path to CA bundle. See https://urllib3.readthedocs.io/en/latest/security.html#using-certifi-with-urllib3 for instructions how to get default set :arg client_cert: path to the file containing the private key and the certificate, or cert only if using client_key :arg client_key: path to the file containing the private key if using separate cert and key files (client_cert will contain only the cert) :arg ssl_version: version of the SSL protocol to use. Choices are: SSLv23 (default) SSLv2 SSLv3 TLSv1 (see ``PROTOCOL_*`` constants in the ``ssl`` module for exact options for your environment). :arg ssl_assert_hostname: use hostname verification if not `False` :arg ssl_assert_fingerprint: verify the supplied certificate fingerprint if not `None` :arg maxsize: the number of connections which will be kept open to this host. See https://urllib3.readthedocs.io/en/1.4/pools.html#api for more information. :arg headers: any custom http headers to be add to requests :arg http_compress: Use gzip compression :arg cloud_id: The Cloud ID from ElasticCloud. Convient way to connect to cloud instances. Other host connection params will be ignored. Ú localhostið#NFTé c s|rF|jdƒ\}}t|jdƒƒjdƒjdƒ\}}}d||f}d}d}tt|ƒjf|||dœ|—Ž||_tj dd�|_ |dk r¬t |t t fƒr˜dj|ƒ}|j jtj |d �ƒ|rÐx|D]}|||j |jƒ<q¶W|jdkrþ|j jtj dd �ƒ|j jd d iƒ|j jd dƒ|j jd|jƒƒtj}i}|�rZ|tk �sP|�sP|�sP| �sP| �rZtjdƒ|�r€|j�r€tj}|j| |dœƒn~|j�rþtj}|j| | | dœƒ|tk�r®d}|dk�r¼tn|}|�rê|�sÔtdƒ‚|jd||| dœƒn|�rþtjd|ƒ||f||j| dœ|—Ž|_dS)Nú:zutf-8ú$z%s.%sZ9243T)ÚhostÚportÚuse_ssl)Ú keep_alive)Ú basic_auth)Úaccept_encodingzcontent-encodingÚgzipz content-typezapplication/jsonz user-agentzBWhen using `ssl_context`, all other SSL related kwargs are ignored)Úassert_fingerprintÚ ssl_context)Ú ssl_versionÚassert_hostnamer z–Root certificates are missing for certificate validation. Either pass them in using the ca_certs parameter or install certifi to use it automatically.Ú CERT_REQUIRED)Ú cert_reqsÚca_certsÚ cert_fileÚkey_filez?Connecting to %s using SSL with verify_certs=False is insecure.)rÚtimeoutÚmaxsize)ÚsplitrÚencodeÚdecodeÚsuperrÚ__init__Ú http_compressÚurllib3Ú make_headersÚheadersÚ isinstanceÚtupleÚlistÚjoinÚupdateÚlowerÚ setdefaultZ_get_default_user_agentÚHTTPConnectionPoolÚVERIFY_CERTS_DEFAULTÚwarningsÚwarnrÚHTTPSConnectionPoolÚCA_CERTSr r)Úpool)ÚselfrrZ http_authrZ verify_certsZ ssl_show_warnr&Ú client_certZ client_keyr"Zssl_assert_hostnameZssl_assert_fingerprintr*r3r!r0Zcloud_idrZ cluster_nameÚurlZes_uuidZ kibana_uuidÚkZ pool_classÚkw)Ú __class__rrr/Psz           zUrllib3HttpConnection.__init__cCs|j|}|rd|t|ƒf}|j|}tjƒ} yÌi} |rB|| d<t|tƒsV|jdƒ}t|tƒsj|jdƒ}|j} |r†| jƒ} | j |ƒ|j rÀ|rÀyt j |ƒ}Wn t k r¾t jj |ƒ}YnX|jj|||ftdƒ| dœ| —Ž} tjƒ| } | jjdƒ}WnŠtk �r†}zl|j||||tjƒ| |d�t|tƒ�rJtdt|ƒ|ƒ‚t|tƒ�rftdt|ƒ|ƒ‚tdt|ƒ|ƒ‚WYdd}~XnXd | jk�ožd kn �rÚ| j|k�rÚ|j||||| | j|ƒ|j| j|ƒ|j||||| j|| ƒ| j| jƒ|fS) Nz%s?%sr)zutf-8F)Úretriesr3)Ú exceptionzN/AÚTIMEOUTéÈi,)Z url_prefixr rÚtimer4Ústrr,r3Úcopyr8r0rÚcompressÚAttributeErrorÚzlibrAÚurlopenrÚdatar-Ú ExceptionZlog_request_failÚUrllibSSLErrorrrr r ÚstatusZ _raise_errorZlog_request_successÚ getheaders)rBÚmethodrDÚparamsÚbodyr)Úignorer3Úfull_urlÚstartrFZrequest_headersÚresponseÚdurationZraw_dataÚerrrÚperform_requestÆsR           ",z%Urllib3HttpConnection.perform_requestcCs|jjƒdS)z. Explicitly closes connection N)rAÚclose)rBrrrrbszUrllib3HttpConnection.close) Ú__name__Ú __module__Ú __qualname__Ú__doc__r<r/rarbÚ __classcell__rr)rGrr.s( e=r)rLr r1Zurllib3.exceptionsrrrUZurllib3.util.retryrr=rÚbase64rr<r@ÚcertifiÚwhereÚ ImportErrorÚbaserÚ exceptionsr r r Úcompatr rrrrrrÚs&