Skip to content

Not authorized when using API keys #596

@sina-rzp

Description

@sina-rzp

When using API keys (env variables below), I get an error (as below), and that is due to the fact that in the elastic client check, it is shown as empty array, and hence it goes into that if statement which blows up. How am I supposed to se the variables differently?

Environment variables set (masked):

export POSTGRES_CONNECTION_STRING="some-string"
export ELASTICSEARCH_HOST="some-host.elastic.cloud"
export ELASTICSEARCH_PORT="443"
export ELASTICSEARCH_SCHEME="https"
export ELASTICSEARCH_API_KEY="some-key-=="
export ELASTICSEARCH_API_KEY_ID="some-key-id"
export REDIS_HOST="some-redis-host"
export REDIS_PORT="6380"

Error

│ test-pgsync   File "/usr/local/lib/python3.11/site-packages/pgsync/search_client.py", line 443, in get_search_client                ││ test-pgsync     return client(                                                                                                      │
│ test-pgsync            ^^^^^^^                                                                                                      ││ test-pgsync   File "/usr/local/lib/python3.11/site-packages/elasticsearch/_sync/client/__init__.py", line 427, in __init__          │
│ test-pgsync     self._headers = resolve_auth_headers(                                                                               ││ test-pgsync                     ^^^^^^^^^^^^^^^^^^^^^                                                                               │
│ test-pgsync   File "/usr/local/lib/python3.11/site-packages/elasticsearch/_sync/client/_base.py", line 121, in resolve_auth_headers ││ test-pgsync     raise ValueError(                                                                                                   │
│ test-pgsync ValueError: Can only set one of 'api_key', 'basic_auth', and 'bearer_auth'

I tried to run this locally and log what is being passed (as below)

# pgsync/.venv/lib/python3.13/site-packages/elasticsearch/_sync/client/_base.py

    print(f"🔍 resolved_api_key     = {resolved_api_key}")
    print(f"🪪 resolved_basic_auth  = {resolved_basic_auth}")
    print(f"🎫 resolved_bearer_auth = {resolved_bearer_auth}")

    if resolved_api_key or resolved_basic_auth or resolved_bearer_auth:

And I get these logs:

🔍 resolved_api_key     = ('some-key-id', 'some-key-==')
🪪 resolved_basic_auth  = []
🎫 resolved_bearer_auth = None

Note that, since resolved_basic_auth is an empty array (i.e. []), hence it is indeed getting into this if " if resolved_api_key or resolved_basic_auth or resolved_bearer_auth:" and hence the error.

Please kindly assist. Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions