opensearch-project / opensearch-py

Python Client for OpenSearch
https://opensearch.org/docs/latest/clients/python/
Apache License 2.0
338 stars 170 forks source link

[FEATURE] Add support for AWSV4SignerAuth for Urllib3HttpConnection #546

Closed navneet1v closed 11 months ago

navneet1v commented 11 months ago

What is the bug?

I have a domain created with Amazon Opensearch with IAM authentication enabled. I am trying access domain using default connection class with AWSV4SignerAuth.

Opensearch-py version:

opensearch-py==2.3.2
python = 3.8

How can one reproduce the bug?

  1. Create a domain with Amazon OpenSearch.
  2. Enable IAM authentication on the domain.
  3. Try accessing the domain using default connection class(Urllib3HttpConnection) with AWSV4SignerAuth.

What is the expected behavior?

As the default connection class is better as compared to RequestsHttpConnection, as provided in the issue: https://github.com/opensearch-project/opensearch-py/pull/535

If I use RequestsHttpConnection, there is no exception.

What is your host/environment?

Amazon OpenSearch version 2.9

Do you have any screenshots?

Pasting logs:

File "main.py", line 60, in main
    client = create_os_client(host=args.endpoint, service=cmd_args.service)
  File "/Volumes/workplace/JunoKNNBenchmarks/src/JunoKNNBenchmarks/benchmarks/hybrid-search/src/opensearch/os_helper.py", line 13, in create_os_client
    client = OpenSearch(
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/opensearchpy/client/__init__.py", line 190, in __init__
    self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/opensearchpy/transport.py", line 164, in __init__
    self.set_connections(hosts)
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/opensearchpy/transport.py", line 218, in set_connections
    connections = list(zip(connections, hosts))
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/opensearchpy/transport.py", line 214, in _create_connection
    return self.connection_class(**kwargs)
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/opensearchpy/connection/http_urllib3.py", line 134, in __init__
    self.headers.update(urllib3.make_headers(basic_auth=http_auth))
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/urllib3/util/request.py", line 85, in make_headers
    headers["authorization"] = "Basic " + b64encode(b(basic_auth)).decode("utf-8")
  File "/Users/navneev/miniforge3/envs/knn-perf/lib/python3.8/site-packages/urllib3/packages/six.py", line 687, in b
    return s.encode("latin-1")
AttributeError: 'AWSV4SignerAuth' object has no attribute 'encode'

Do you have any additional context?

NA