removes elastic support from opensearch-py library
Signed-off-by: Shivam Dhar <[email protected]>
This commit is contained in:
@@ -95,8 +95,6 @@ class AIOHttpConnection(AsyncConnection):
|
||||
headers=None,
|
||||
ssl_context=None,
|
||||
http_compress=None,
|
||||
cloud_id=None,
|
||||
api_key=None,
|
||||
opaque_id=None,
|
||||
loop=None,
|
||||
**kwargs,
|
||||
@@ -130,9 +128,6 @@ class AIOHttpConnection(AsyncConnection):
|
||||
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. Convenient way to connect to cloud instances.
|
||||
Other host connection params will be ignored.
|
||||
:arg api_key: optional API Key authentication as either base64 encoded string or a tuple.
|
||||
:arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header
|
||||
For tracing all requests made by this transport.
|
||||
:arg loop: asyncio Event Loop to use with aiohttp. This is set by default to the currently running loop.
|
||||
@@ -146,8 +141,6 @@ class AIOHttpConnection(AsyncConnection):
|
||||
use_ssl=use_ssl,
|
||||
headers=headers,
|
||||
http_compress=http_compress,
|
||||
cloud_id=cloud_id,
|
||||
api_key=api_key,
|
||||
opaque_id=opaque_id,
|
||||
**kwargs,
|
||||
)
|
||||
|
||||
@@ -62,8 +62,6 @@ class AIOHttpConnection(AsyncConnection):
|
||||
headers: Optional[Mapping[str, str]] = ...,
|
||||
ssl_context: Optional[Any] = ...,
|
||||
http_compress: Optional[bool] = ...,
|
||||
cloud_id: Optional[str] = ...,
|
||||
api_key: Optional[Any] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
loop: Any = ...,
|
||||
**kwargs: Any,
|
||||
|
||||
@@ -99,10 +99,6 @@ class AsyncTransport(Transport):
|
||||
*args, hosts=[], sniff_on_start=False, **kwargs
|
||||
)
|
||||
|
||||
# Don't enable sniffing on Cloud instances.
|
||||
if kwargs.get("cloud_id", False):
|
||||
sniff_on_start = False
|
||||
|
||||
# Since we defer connections / sniffing to not occur
|
||||
# within the constructor we never want to signal to
|
||||
# our parent to 'sniff_on_start' or non-empty 'hosts'.
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import binascii
|
||||
import gzip
|
||||
import io
|
||||
import logging
|
||||
@@ -39,12 +38,7 @@ except ImportError:
|
||||
import json
|
||||
|
||||
from .. import __versionstr__
|
||||
from ..exceptions import (
|
||||
HTTP_EXCEPTIONS,
|
||||
ImproperlyConfigured,
|
||||
OpenSearchWarning,
|
||||
TransportError,
|
||||
)
|
||||
from ..exceptions import HTTP_EXCEPTIONS, OpenSearchWarning, TransportError
|
||||
|
||||
logger = logging.getLogger("opensearch")
|
||||
|
||||
@@ -72,7 +66,6 @@ class Connection(object):
|
||||
:arg url_prefix: optional url prefix for opensearch
|
||||
:arg timeout: default timeout in seconds (float, default: 10)
|
||||
:arg http_compress: Use gzip compression
|
||||
:arg cloud_id: The Cloud ID from ElasticCloud. Convenient way to connect to cloud instances.
|
||||
:arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header
|
||||
For tracing all requests made by this transport.
|
||||
"""
|
||||
@@ -86,35 +79,10 @@ class Connection(object):
|
||||
timeout=10,
|
||||
headers=None,
|
||||
http_compress=None,
|
||||
cloud_id=None,
|
||||
api_key=None,
|
||||
opaque_id=None,
|
||||
**kwargs
|
||||
):
|
||||
|
||||
if cloud_id:
|
||||
try:
|
||||
_, cloud_id = cloud_id.split(":")
|
||||
parent_dn, opensearch_uuid = (
|
||||
binascii.a2b_base64(cloud_id.encode("utf-8"))
|
||||
.decode("utf-8")
|
||||
.split("$")[:2]
|
||||
)
|
||||
if ":" in parent_dn:
|
||||
parent_dn, _, parent_port = parent_dn.rpartition(":")
|
||||
if port is None and parent_port != "443":
|
||||
port = int(parent_port)
|
||||
except (ValueError, IndexError):
|
||||
raise ImproperlyConfigured("'cloud_id' is not properly formatted")
|
||||
|
||||
host = "%s.%s" % (opensearch_uuid, parent_dn)
|
||||
use_ssl = True
|
||||
if http_compress is None:
|
||||
http_compress = True
|
||||
|
||||
# If cloud_id isn't set and port is default then use 9200.
|
||||
# Cloud should use '443' by default via the 'https' scheme.
|
||||
elif port is None:
|
||||
if port is None:
|
||||
port = 9200
|
||||
|
||||
# Work-around if the implementing class doesn't
|
||||
@@ -136,9 +104,6 @@ class Connection(object):
|
||||
self.headers.setdefault("content-type", "application/json")
|
||||
self.headers.setdefault("user-agent", self._get_default_user_agent())
|
||||
|
||||
if api_key is not None:
|
||||
self.headers["authorization"] = self._get_api_key_header_val(api_key)
|
||||
|
||||
if http_compress:
|
||||
self.headers["accept-encoding"] = "gzip,deflate"
|
||||
|
||||
@@ -338,14 +303,3 @@ class Connection(object):
|
||||
|
||||
def _get_default_user_agent(self):
|
||||
return "opensearch-py/%s (Python %s)" % (__versionstr__, python_version())
|
||||
|
||||
def _get_api_key_header_val(self, api_key):
|
||||
"""
|
||||
Check the type of the passed api_key and return the correct header value
|
||||
for the API Key authentication
|
||||
:arg api_key, either a tuple or a base64 encoded string
|
||||
"""
|
||||
if isinstance(api_key, (tuple, list)):
|
||||
s = "{0}:{1}".format(api_key[0], api_key[1]).encode("utf-8")
|
||||
return "ApiKey " + binascii.b2a_base64(s).rstrip(b"\r\n").decode("utf-8")
|
||||
return "ApiKey " + api_key
|
||||
|
||||
@@ -61,8 +61,6 @@ class Connection(object):
|
||||
timeout: Optional[Union[float, int]] = ...,
|
||||
headers: Optional[Mapping[str, str]] = ...,
|
||||
http_compress: Optional[bool] = ...,
|
||||
cloud_id: Optional[str] = ...,
|
||||
api_key: Optional[Union[Tuple[str, str], List[str], str]] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
@@ -116,4 +114,3 @@ class Connection(object):
|
||||
self, status_code: int, raw_data: str, content_type: Optional[str]
|
||||
) -> NoReturn: ...
|
||||
def _get_default_user_agent(self) -> str: ...
|
||||
def _get_api_key_header_val(self, api_key: Any) -> str: ...
|
||||
|
||||
@@ -61,9 +61,6 @@ class RequestsHttpConnection(Connection):
|
||||
separate cert and key files (client_cert will contain only the cert)
|
||||
: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. Convenient way to connect to cloud instances.
|
||||
Other host connection params will be ignored.
|
||||
:arg api_key: optional API Key authentication as either base64 encoded string or a tuple.
|
||||
:arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header
|
||||
For tracing all requests made by this transport.
|
||||
"""
|
||||
@@ -81,8 +78,6 @@ class RequestsHttpConnection(Connection):
|
||||
client_key=None,
|
||||
headers=None,
|
||||
http_compress=None,
|
||||
cloud_id=None,
|
||||
api_key=None,
|
||||
opaque_id=None,
|
||||
**kwargs
|
||||
):
|
||||
@@ -102,8 +97,6 @@ class RequestsHttpConnection(Connection):
|
||||
use_ssl=use_ssl,
|
||||
headers=headers,
|
||||
http_compress=http_compress,
|
||||
cloud_id=cloud_id,
|
||||
api_key=api_key,
|
||||
opaque_id=opaque_id,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@@ -45,8 +45,6 @@ class RequestsHttpConnection(Connection):
|
||||
client_key: Optional[Any] = ...,
|
||||
headers: Optional[Mapping[str, str]] = ...,
|
||||
http_compress: Optional[bool] = ...,
|
||||
cloud_id: Optional[str] = ...,
|
||||
api_key: Optional[Any] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
|
||||
@@ -100,9 +100,6 @@ class Urllib3HttpConnection(Connection):
|
||||
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. Convenient way to connect to cloud instances.
|
||||
Other host connection params will be ignored.
|
||||
:arg api_key: optional API Key authentication as either base64 encoded string or a tuple.
|
||||
:arg opaque_id: Send this value in the 'X-Opaque-Id' HTTP header
|
||||
For tracing all requests made by this transport.
|
||||
"""
|
||||
@@ -125,8 +122,6 @@ class Urllib3HttpConnection(Connection):
|
||||
headers=None,
|
||||
ssl_context=None,
|
||||
http_compress=None,
|
||||
cloud_id=None,
|
||||
api_key=None,
|
||||
opaque_id=None,
|
||||
**kwargs
|
||||
):
|
||||
@@ -139,8 +134,6 @@ class Urllib3HttpConnection(Connection):
|
||||
use_ssl=use_ssl,
|
||||
headers=headers,
|
||||
http_compress=http_compress,
|
||||
cloud_id=cloud_id,
|
||||
api_key=api_key,
|
||||
opaque_id=opaque_id,
|
||||
**kwargs
|
||||
)
|
||||
|
||||
@@ -59,8 +59,6 @@ class Urllib3HttpConnection(Connection):
|
||||
headers: Optional[Mapping[str, str]] = ...,
|
||||
ssl_context: Optional[Any] = ...,
|
||||
http_compress: Optional[bool] = ...,
|
||||
cloud_id: Optional[str] = ...,
|
||||
api_key: Optional[Any] = ...,
|
||||
opaque_id: Optional[str] = ...,
|
||||
**kwargs: Any
|
||||
) -> None: ...
|
||||
|
||||
@@ -166,11 +166,6 @@ class Transport(object):
|
||||
else:
|
||||
self.seed_connections = []
|
||||
|
||||
# Don't enable sniffing on Cloud instances.
|
||||
if kwargs.get("cloud_id", False):
|
||||
sniff_on_start = False
|
||||
sniff_on_connection_fail = False
|
||||
|
||||
# sniffing data
|
||||
self.sniffer_timeout = sniffer_timeout
|
||||
self.sniff_on_start = sniff_on_start
|
||||
|
||||
@@ -94,53 +94,6 @@ class TestAIOHttpConnection:
|
||||
con = AIOHttpConnection(opaque_id="app-1")
|
||||
assert con.headers["x-opaque-id"] == "app-1"
|
||||
|
||||
def test_http_cloud_id(self):
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng=="
|
||||
)
|
||||
assert con.use_ssl
|
||||
assert (
|
||||
con.host
|
||||
== "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
assert con.port is None
|
||||
assert con.hostname == "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
assert con.http_compress
|
||||
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
port=9243,
|
||||
)
|
||||
assert (
|
||||
con.host
|
||||
== "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io:9243"
|
||||
)
|
||||
assert con.port == 9243
|
||||
assert con.hostname == "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
|
||||
def test_api_key_auth(self):
|
||||
# test with tuple
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key=("elastic", "changeme1"),
|
||||
)
|
||||
assert con.headers["authorization"] == "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTE="
|
||||
assert (
|
||||
con.host
|
||||
== "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
# test with base64 encoded string
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key="ZWxhc3RpYzpjaGFuZ2VtZTI=",
|
||||
)
|
||||
assert con.headers["authorization"] == "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTI="
|
||||
assert (
|
||||
con.host
|
||||
== "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
async def test_no_http_compression(self):
|
||||
con = await self._get_mock_connection()
|
||||
assert not con.http_compress
|
||||
@@ -179,26 +132,6 @@ class TestAIOHttpConnection:
|
||||
assert kwargs["headers"]["accept-encoding"] == "gzip,deflate"
|
||||
assert "content-encoding" not in kwargs["headers"]
|
||||
|
||||
def test_cloud_id_http_compress_override(self):
|
||||
# 'http_compress' will be 'True' by default for connections with
|
||||
# 'cloud_id' set but should prioritize user-defined values.
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
)
|
||||
assert con.http_compress is True
|
||||
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=False,
|
||||
)
|
||||
assert con.http_compress is False
|
||||
|
||||
con = AIOHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=True,
|
||||
)
|
||||
assert con.http_compress is True
|
||||
|
||||
async def test_url_prefix(self):
|
||||
con = await self._get_mock_connection(
|
||||
connection_params={"url_prefix": "/_search/"}
|
||||
|
||||
@@ -436,23 +436,6 @@ class TestTransport:
|
||||
"port": 123,
|
||||
}
|
||||
|
||||
@patch("opensearchpy._async.transport.AsyncTransport.sniff_hosts")
|
||||
async def test_sniffing_disabled_on_cloud_instances(self, sniff_hosts):
|
||||
t = AsyncTransport(
|
||||
[{}],
|
||||
sniff_on_start=True,
|
||||
sniff_on_connection_fail=True,
|
||||
connection_class=DummyConnection,
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
)
|
||||
await t._async_call()
|
||||
|
||||
assert not t.sniff_on_connection_fail
|
||||
assert sniff_hosts.call_args is None # Assert not called.
|
||||
await t.perform_request("GET", "/", body={})
|
||||
assert 1 == len(t.get_connection().calls)
|
||||
assert ("GET", "/", None, b"{}") == t.get_connection().calls[0][0]
|
||||
|
||||
async def test_transport_close_closes_all_pool_connections(self):
|
||||
t = AsyncTransport([{}], connection_class=DummyConnection)
|
||||
await t._async_call()
|
||||
|
||||
@@ -59,11 +59,6 @@ from opensearchpy.exceptions import (
|
||||
|
||||
from .test_cases import SkipTest, TestCase
|
||||
|
||||
CLOUD_ID_PORT_443 = "cluster:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo0NDMkZTdkZTlmMTM0NWU0NDkwMjgzZDkwM2JlNWI2ZjkxOWUk"
|
||||
CLOUD_ID_KIBANA = "cluster:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbSQ4YWY3ZWUzNTQyMGY0NThlOTAzMDI2YjQwNjQwODFmMiQyMDA2MTU1NmM1NDA0OTg2YmZmOTU3ZDg0YTZlYjUxZg=="
|
||||
CLOUD_ID_PORT_AND_KIBANA = "cluster:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbTo5MjQzJGM2NjM3ZjMxMmM1MjQzY2RhN2RlZDZlOTllM2QyYzE5JA=="
|
||||
CLOUD_ID_NO_PORT_OR_KIBANA = "cluster:d2VzdGV1cm9wZS5henVyZS5lbGFzdGljLWNsb3VkLmNvbSRlN2RlOWYxMzQ1ZTQ0OTAyODNkOTAzYmU1YjZmOTE5ZSQ="
|
||||
|
||||
|
||||
def gzip_decompress(data):
|
||||
buf = gzip.GzipFile(fileobj=io.BytesIO(data), mode="rb")
|
||||
@@ -71,58 +66,6 @@ def gzip_decompress(data):
|
||||
|
||||
|
||||
class TestBaseConnection(TestCase):
|
||||
def test_parse_cloud_id(self):
|
||||
# Embedded port in cloud_id
|
||||
con = Connection(cloud_id=CLOUD_ID_PORT_AND_KIBANA)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://c6637f312c5243cda7ded6e99e3d2c19.westeurope.azure.elastic-cloud.com:9243",
|
||||
)
|
||||
self.assertEqual(con.port, 9243)
|
||||
self.assertEqual(
|
||||
con.hostname,
|
||||
"c6637f312c5243cda7ded6e99e3d2c19.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
|
||||
# Embedded port but overridden
|
||||
con = Connection(
|
||||
cloud_id=CLOUD_ID_PORT_AND_KIBANA,
|
||||
port=443,
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://c6637f312c5243cda7ded6e99e3d2c19.westeurope.azure.elastic-cloud.com:443",
|
||||
)
|
||||
self.assertEqual(con.port, 443)
|
||||
self.assertEqual(
|
||||
con.hostname,
|
||||
"c6637f312c5243cda7ded6e99e3d2c19.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
|
||||
# Port is 443, removed by default.
|
||||
con = Connection(cloud_id=CLOUD_ID_PORT_443)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://e7de9f1345e4490283d903be5b6f919e.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
self.assertEqual(con.port, None)
|
||||
self.assertEqual(
|
||||
con.hostname,
|
||||
"e7de9f1345e4490283d903be5b6f919e.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
|
||||
# No port, contains Kibana UUID
|
||||
con = Connection(cloud_id=CLOUD_ID_KIBANA)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://8af7ee35420f458e903026b4064081f2.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
self.assertEqual(con.port, None)
|
||||
self.assertEqual(
|
||||
con.hostname,
|
||||
"8af7ee35420f458e903026b4064081f2.westeurope.azure.elastic-cloud.com",
|
||||
)
|
||||
|
||||
def test_empty_warnings(self):
|
||||
con = Connection()
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
@@ -245,58 +188,6 @@ class TestUrllib3Connection(TestCase):
|
||||
con = Urllib3HttpConnection(opaque_id="app-1")
|
||||
self.assertEqual(con.headers["x-opaque-id"], "app-1")
|
||||
|
||||
def test_http_cloud_id(self):
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng=="
|
||||
)
|
||||
self.assertTrue(con.use_ssl)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
self.assertEqual(con.port, None)
|
||||
self.assertEqual(
|
||||
con.hostname, "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
self.assertTrue(con.http_compress)
|
||||
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
port=9243,
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io:9243",
|
||||
)
|
||||
self.assertEqual(con.port, 9243)
|
||||
self.assertEqual(
|
||||
con.hostname, "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
def test_api_key_auth(self):
|
||||
# test with tuple
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key=("elastic", "changeme1"),
|
||||
)
|
||||
self.assertEqual(
|
||||
con.headers["authorization"], "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTE="
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
# test with base64 encoded string
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key="ZWxhc3RpYzpjaGFuZ2VtZTI=",
|
||||
)
|
||||
self.assertEqual(
|
||||
con.headers["authorization"], "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTI="
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
def test_no_http_compression(self):
|
||||
con = self._get_mock_connection()
|
||||
self.assertFalse(con.http_compress)
|
||||
@@ -335,26 +226,6 @@ class TestUrllib3Connection(TestCase):
|
||||
self.assertEqual(kwargs["headers"]["accept-encoding"], "gzip,deflate")
|
||||
self.assertNotIn("content-encoding", kwargs["headers"])
|
||||
|
||||
def test_cloud_id_http_compress_override(self):
|
||||
# 'http_compress' will be 'True' by default for connections with
|
||||
# 'cloud_id' set but should prioritize user-defined values.
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
)
|
||||
self.assertEqual(con.http_compress, True)
|
||||
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=False,
|
||||
)
|
||||
self.assertEqual(con.http_compress, False)
|
||||
|
||||
con = Urllib3HttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=True,
|
||||
)
|
||||
self.assertEqual(con.http_compress, True)
|
||||
|
||||
def test_default_user_agent(self):
|
||||
con = Urllib3HttpConnection()
|
||||
self.assertEqual(
|
||||
@@ -545,58 +416,6 @@ class TestRequestsConnection(TestCase):
|
||||
con = RequestsHttpConnection(opaque_id="app-1")
|
||||
self.assertEqual(con.headers["x-opaque-id"], "app-1")
|
||||
|
||||
def test_http_cloud_id(self):
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng=="
|
||||
)
|
||||
self.assertTrue(con.use_ssl)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
self.assertEqual(con.port, None)
|
||||
self.assertEqual(
|
||||
con.hostname, "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
self.assertTrue(con.http_compress)
|
||||
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
port=9243,
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host,
|
||||
"https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io:9243",
|
||||
)
|
||||
self.assertEqual(con.port, 9243)
|
||||
self.assertEqual(
|
||||
con.hostname, "4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
def test_api_key_auth(self):
|
||||
# test with tuple
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key=("elastic", "changeme1"),
|
||||
)
|
||||
self.assertEqual(
|
||||
con.session.headers["authorization"], "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTE="
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
# test with base64 encoded string
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
api_key="ZWxhc3RpYzpjaGFuZ2VtZTI=",
|
||||
)
|
||||
self.assertEqual(
|
||||
con.session.headers["authorization"], "ApiKey ZWxhc3RpYzpjaGFuZ2VtZTI="
|
||||
)
|
||||
self.assertEqual(
|
||||
con.host, "https://4fa8821e75634032bed1cf22110e2f97.us-east-1.aws.found.io"
|
||||
)
|
||||
|
||||
def test_no_http_compression(self):
|
||||
con = self._get_mock_connection()
|
||||
|
||||
@@ -632,26 +451,6 @@ class TestRequestsConnection(TestCase):
|
||||
self.assertNotIn("content-encoding", req.headers)
|
||||
self.assertEqual(req.headers["accept-encoding"], "gzip,deflate")
|
||||
|
||||
def test_cloud_id_http_compress_override(self):
|
||||
# 'http_compress' will be 'True' by default for connections with
|
||||
# 'cloud_id' set but should prioritize user-defined values.
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
)
|
||||
self.assertEqual(con.http_compress, True)
|
||||
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=False,
|
||||
)
|
||||
self.assertEqual(con.http_compress, False)
|
||||
|
||||
con = RequestsHttpConnection(
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
http_compress=True,
|
||||
)
|
||||
self.assertEqual(con.http_compress, True)
|
||||
|
||||
def test_uses_https_if_verify_certs_is_off(self):
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
con = self._get_mock_connection(
|
||||
|
||||
@@ -393,15 +393,3 @@ class TestTransport(TestCase):
|
||||
t.connection_pool.connection_opts[0][1],
|
||||
{"host": "somehost.tld", "port": 123},
|
||||
)
|
||||
|
||||
@patch("opensearchpy.transport.Transport.sniff_hosts")
|
||||
def test_sniffing_disabled_on_cloud_instances(self, sniff_hosts):
|
||||
t = Transport(
|
||||
[{}],
|
||||
sniff_on_start=True,
|
||||
sniff_on_connection_fail=True,
|
||||
cloud_id="cluster:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5NyQ0ZmE4ODIxZTc1NjM0MDMyYmVkMWNmMjIxMTBlMmY5Ng==",
|
||||
)
|
||||
|
||||
self.assertFalse(t.sniff_on_connection_fail)
|
||||
self.assertIs(sniff_hosts.call_args, None) # Assert not called.
|
||||
|
||||
Reference in New Issue
Block a user