opensearch-mcp-server 2.0.10__tar.gz → 2.0.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/CONTRIBUTING.md +8 -0
  2. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/PKG-INFO +64 -8
  3. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/README.md +63 -7
  4. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/pyproject.toml +1 -1
  5. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/__init__.py +2 -0
  6. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/base.py +20 -5
  7. opensearch_mcp_server-2.0.11/src/version.py +1 -0
  8. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/uv.lock +392 -392
  9. opensearch_mcp_server-2.0.10/Dockerfile +0 -30
  10. opensearch_mcp_server-2.0.10/src/version.py +0 -1
  11. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/.env.example +0 -0
  12. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/.github/workflows/pypi-publish.yaml +0 -0
  13. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/.github/workflows/release.yml +0 -0
  14. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/.gitignore +0 -0
  15. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/.python-version +0 -0
  16. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/LICENSE +0 -0
  17. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/Makefile +0 -0
  18. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/cliff.toml +0 -0
  19. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/docker-compose-elasticsearch.yml +0 -0
  20. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/docker-compose-opensearch.yml +0 -0
  21. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/python-sdk-anthropic/.gitignore +0 -0
  22. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/python-sdk-anthropic/__init__.py +0 -0
  23. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/python-sdk-anthropic/client.py +0 -0
  24. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/python-sdk-anthropic/config.py +0 -0
  25. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/README.md +0 -0
  26. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/build.gradle +0 -0
  27. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/gradle/wrapper/gradle-wrapper.jar +0 -0
  28. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/gradle/wrapper/gradle-wrapper.properties +0 -0
  29. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/gradle.properties +0 -0
  30. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/gradlew +0 -0
  31. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/gradlew.bat +0 -0
  32. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/settings.gradle +0 -0
  33. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/src/main/java/spring/ai/mcp/spring_ai_mcp/Application.java +0 -0
  34. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/src/main/resources/application.yml +0 -0
  35. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/src/main/resources/mcp-servers-config.json +0 -0
  36. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/mcp_client/spring-ai/src/test/java/spring/ai/mcp/spring_ai_mcp/SpringAiMcpApplicationTests.java +0 -0
  37. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/__init__.py +0 -0
  38. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/__init__.py +0 -0
  39. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/alias.py +0 -0
  40. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/client.py +0 -0
  41. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/cluster.py +0 -0
  42. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/document.py +0 -0
  43. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/general.py +0 -0
  44. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/common/index.py +0 -0
  45. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/clients/exceptions.py +0 -0
  46. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/server.py +0 -0
  47. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/__init__.py +0 -0
  48. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/alias.py +0 -0
  49. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/cluster.py +0 -0
  50. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/document.py +0 -0
  51. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/general.py +0 -0
  52. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/index.py +0 -0
  53. {opensearch_mcp_server-2.0.10 → opensearch_mcp_server-2.0.11}/src/tools/register.py +0 -0
@@ -73,4 +73,12 @@ If you have already created a branch and want to keep it in sync with the upstre
73
73
  git checkout <branch-name>
74
74
  git fetch upstream
75
75
  git rebase upstream/main
76
+ ```
77
+
78
+ ## Release
79
+
80
+ ```bash
81
+ uv sync
82
+ source .venv/bin/activate
83
+ make release version=<RELEASE_VERSION>
76
84
  ```
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: opensearch-mcp-server
3
- Version: 2.0.10
3
+ Version: 2.0.11
4
4
  Summary: MCP Server for interacting with Elasticsearch and OpenSearch
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -218,10 +218,10 @@ Description-Content-Type: text/markdown
218
218
 
219
219
  # Elasticsearch/OpenSearch MCP Server
220
220
 
221
- [![smithery badge](https://smithery.ai/badge/elasticsearch-mcp-server)](https://smithery.ai/server/elasticsearch-mcp-server)
222
-
223
221
  [![MseeP.ai Security Assessment Badge](https://mseep.net/pr/cr7258-elasticsearch-mcp-server-badge.png)](https://mseep.ai/app/cr7258-elasticsearch-mcp-server)
224
222
 
223
+ [![Trust Score](https://archestra.ai/mcp-catalog/api/badge/quality/cr7258/elasticsearch-mcp-server)](https://archestra.ai/mcp-catalog/cr7258__elasticsearch-mcp-server)
224
+
225
225
  ## Overview
226
226
 
227
227
  A Model Context Protocol (MCP) server implementation that provides Elasticsearch and OpenSearch interaction. This server enables searching documents, analyzing indices, and managing cluster through a set of tools.
@@ -267,7 +267,20 @@ https://github.com/user-attachments/assets/f7409e31-fac4-4321-9c94-b0ff2ea7ff15
267
267
 
268
268
  ## Configure Environment Variables
269
269
 
270
- Copy the `.env.example` file to `.env` and update the values accordingly.
270
+ The MCP server supports the following environment variables for authentication:
271
+
272
+ ### Basic Authentication (Username/Password)
273
+ - `ELASTICSEARCH_USERNAME`: Username for basic authentication
274
+ - `ELASTICSEARCH_PASSWORD`: Password for basic authentication
275
+ - `OPENSEARCH_USERNAME`: Username for OpenSearch basic authentication
276
+ - `OPENSEARCH_PASSWORD`: Password for OpenSearch basic authentication
277
+
278
+ ### API Key Authentication (Elasticsearch only) - Recommended
279
+ - `ELASTICSEARCH_API_KEY`: API key for [Elasticsearch](https://www.elastic.co/docs/deploy-manage/api-keys/elasticsearch-api-keys) or [Elastic Cloud](https://www.elastic.co/docs/deploy-manage/api-keys/elastic-cloud-api-keys) Authentication.
280
+
281
+ ### Other Configuration
282
+ - `ELASTICSEARCH_HOSTS` / `OPENSEARCH_HOSTS`: Comma-separated list of hosts (default: `https://localhost:9200`)
283
+ - `ELASTICSEARCH_VERIFY_CERTS` / `OPENSEARCH_VERIFY_CERTS`: Whether to verify SSL certificates (default: `false`)
271
284
 
272
285
  ## Start Elasticsearch/OpenSearch Cluster
273
286
 
@@ -292,7 +305,7 @@ You can access Kibana/OpenSearch Dashboards from http://localhost:5601.
292
305
  Using `uvx` will automatically install the package from PyPI, no need to clone the repository locally. Add the following configuration to 's config file `claude_desktop_config.json`.
293
306
 
294
307
  ```json
295
- // For Elasticsearch
308
+ // For Elasticsearch with username/password
296
309
  {
297
310
  "mcpServers": {
298
311
  "elasticsearch-mcp-server": {
@@ -309,6 +322,22 @@ Using `uvx` will automatically install the package from PyPI, no need to clone t
309
322
  }
310
323
  }
311
324
 
325
+ // For Elasticsearch with API key
326
+ {
327
+ "mcpServers": {
328
+ "elasticsearch-mcp-server": {
329
+ "command": "uvx",
330
+ "args": [
331
+ "elasticsearch-mcp-server"
332
+ ],
333
+ "env": {
334
+ "ELASTICSEARCH_HOSTS": "https://localhost:9200",
335
+ "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
336
+ }
337
+ }
338
+ }
339
+ }
340
+
312
341
  // For OpenSearch
313
342
  {
314
343
  "mcpServers": {
@@ -332,7 +361,7 @@ Using `uvx` will automatically install the package from PyPI, no need to clone t
332
361
  Using `uv` requires cloning the repository locally and specifying the path to the source code. Add the following configuration to Claude Desktop's config file `claude_desktop_config.json`.
333
362
 
334
363
  ```json
335
- // For Elasticsearch
364
+ // For Elasticsearch with username/password
336
365
  {
337
366
  "mcpServers": {
338
367
  "elasticsearch-mcp-server": {
@@ -352,6 +381,25 @@ Using `uv` requires cloning the repository locally and specifying the path to th
352
381
  }
353
382
  }
354
383
 
384
+ // For Elasticsearch with API key
385
+ {
386
+ "mcpServers": {
387
+ "elasticsearch-mcp-server": {
388
+ "command": "uv",
389
+ "args": [
390
+ "--directory",
391
+ "path/to/src/elasticsearch_mcp_server",
392
+ "run",
393
+ "elasticsearch-mcp-server"
394
+ ],
395
+ "env": {
396
+ "ELASTICSEARCH_HOSTS": "https://localhost:9200",
397
+ "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
398
+ }
399
+ }
400
+ }
401
+ }
402
+
355
403
  // For OpenSearch
356
404
  {
357
405
  "mcpServers": {
@@ -378,11 +426,15 @@ Using `uv` requires cloning the repository locally and specifying the path to th
378
426
  ### Option 1: Using uvx
379
427
 
380
428
  ```bash
381
- # export environment variables
429
+ # export environment variables (with username/password)
382
430
  export ELASTICSEARCH_HOSTS="https://localhost:9200"
383
431
  export ELASTICSEARCH_USERNAME="elastic"
384
432
  export ELASTICSEARCH_PASSWORD="test123"
385
433
 
434
+ # OR export environment variables (with API key)
435
+ export ELASTICSEARCH_HOSTS="https://localhost:9200"
436
+ export ELASTICSEARCH_API_KEY="<YOUR_ELASTICSEARCH_API_KEY>"
437
+
386
438
  # By default, the SSE MCP server will serve on http://127.0.0.1:8000/sse
387
439
  uvx elasticsearch-mcp-server --transport sse
388
440
 
@@ -405,11 +457,15 @@ uv run src/server.py elasticsearch-mcp-server --transport sse --host 0.0.0.0 --p
405
457
  ### Option 1: Using uvx
406
458
 
407
459
  ```bash
408
- # export environment variables
460
+ # export environment variables (with username/password)
409
461
  export ELASTICSEARCH_HOSTS="https://localhost:9200"
410
462
  export ELASTICSEARCH_USERNAME="elastic"
411
463
  export ELASTICSEARCH_PASSWORD="test123"
412
464
 
465
+ # OR export environment variables (with API key)
466
+ export ELASTICSEARCH_HOSTS="https://localhost:9200"
467
+ export ELASTICSEARCH_API_KEY="<YOUR_ELASTICSEARCH_API_KEY>"
468
+
413
469
  # By default, the Streamable HTTP MCP server will serve on http://127.0.0.1:8000/mcp
414
470
  uvx elasticsearch-mcp-server --transport streamable-http
415
471
 
@@ -1,10 +1,10 @@
1
1
 
2
2
  # Elasticsearch/OpenSearch MCP Server
3
3
 
4
- [![smithery badge](https://smithery.ai/badge/elasticsearch-mcp-server)](https://smithery.ai/server/elasticsearch-mcp-server)
5
-
6
4
  [![MseeP.ai Security Assessment Badge](https://mseep.net/pr/cr7258-elasticsearch-mcp-server-badge.png)](https://mseep.ai/app/cr7258-elasticsearch-mcp-server)
7
5
 
6
+ [![Trust Score](https://archestra.ai/mcp-catalog/api/badge/quality/cr7258/elasticsearch-mcp-server)](https://archestra.ai/mcp-catalog/cr7258__elasticsearch-mcp-server)
7
+
8
8
  ## Overview
9
9
 
10
10
  A Model Context Protocol (MCP) server implementation that provides Elasticsearch and OpenSearch interaction. This server enables searching documents, analyzing indices, and managing cluster through a set of tools.
@@ -50,7 +50,20 @@ https://github.com/user-attachments/assets/f7409e31-fac4-4321-9c94-b0ff2ea7ff15
50
50
 
51
51
  ## Configure Environment Variables
52
52
 
53
- Copy the `.env.example` file to `.env` and update the values accordingly.
53
+ The MCP server supports the following environment variables for authentication:
54
+
55
+ ### Basic Authentication (Username/Password)
56
+ - `ELASTICSEARCH_USERNAME`: Username for basic authentication
57
+ - `ELASTICSEARCH_PASSWORD`: Password for basic authentication
58
+ - `OPENSEARCH_USERNAME`: Username for OpenSearch basic authentication
59
+ - `OPENSEARCH_PASSWORD`: Password for OpenSearch basic authentication
60
+
61
+ ### API Key Authentication (Elasticsearch only) - Recommended
62
+ - `ELASTICSEARCH_API_KEY`: API key for [Elasticsearch](https://www.elastic.co/docs/deploy-manage/api-keys/elasticsearch-api-keys) or [Elastic Cloud](https://www.elastic.co/docs/deploy-manage/api-keys/elastic-cloud-api-keys) Authentication.
63
+
64
+ ### Other Configuration
65
+ - `ELASTICSEARCH_HOSTS` / `OPENSEARCH_HOSTS`: Comma-separated list of hosts (default: `https://localhost:9200`)
66
+ - `ELASTICSEARCH_VERIFY_CERTS` / `OPENSEARCH_VERIFY_CERTS`: Whether to verify SSL certificates (default: `false`)
54
67
 
55
68
  ## Start Elasticsearch/OpenSearch Cluster
56
69
 
@@ -75,7 +88,7 @@ You can access Kibana/OpenSearch Dashboards from http://localhost:5601.
75
88
  Using `uvx` will automatically install the package from PyPI, no need to clone the repository locally. Add the following configuration to 's config file `claude_desktop_config.json`.
76
89
 
77
90
  ```json
78
- // For Elasticsearch
91
+ // For Elasticsearch with username/password
79
92
  {
80
93
  "mcpServers": {
81
94
  "elasticsearch-mcp-server": {
@@ -92,6 +105,22 @@ Using `uvx` will automatically install the package from PyPI, no need to clone t
92
105
  }
93
106
  }
94
107
 
108
+ // For Elasticsearch with API key
109
+ {
110
+ "mcpServers": {
111
+ "elasticsearch-mcp-server": {
112
+ "command": "uvx",
113
+ "args": [
114
+ "elasticsearch-mcp-server"
115
+ ],
116
+ "env": {
117
+ "ELASTICSEARCH_HOSTS": "https://localhost:9200",
118
+ "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
119
+ }
120
+ }
121
+ }
122
+ }
123
+
95
124
  // For OpenSearch
96
125
  {
97
126
  "mcpServers": {
@@ -115,7 +144,7 @@ Using `uvx` will automatically install the package from PyPI, no need to clone t
115
144
  Using `uv` requires cloning the repository locally and specifying the path to the source code. Add the following configuration to Claude Desktop's config file `claude_desktop_config.json`.
116
145
 
117
146
  ```json
118
- // For Elasticsearch
147
+ // For Elasticsearch with username/password
119
148
  {
120
149
  "mcpServers": {
121
150
  "elasticsearch-mcp-server": {
@@ -135,6 +164,25 @@ Using `uv` requires cloning the repository locally and specifying the path to th
135
164
  }
136
165
  }
137
166
 
167
+ // For Elasticsearch with API key
168
+ {
169
+ "mcpServers": {
170
+ "elasticsearch-mcp-server": {
171
+ "command": "uv",
172
+ "args": [
173
+ "--directory",
174
+ "path/to/src/elasticsearch_mcp_server",
175
+ "run",
176
+ "elasticsearch-mcp-server"
177
+ ],
178
+ "env": {
179
+ "ELASTICSEARCH_HOSTS": "https://localhost:9200",
180
+ "ELASTICSEARCH_API_KEY": "<YOUR_ELASTICSEARCH_API_KEY>"
181
+ }
182
+ }
183
+ }
184
+ }
185
+
138
186
  // For OpenSearch
139
187
  {
140
188
  "mcpServers": {
@@ -161,11 +209,15 @@ Using `uv` requires cloning the repository locally and specifying the path to th
161
209
  ### Option 1: Using uvx
162
210
 
163
211
  ```bash
164
- # export environment variables
212
+ # export environment variables (with username/password)
165
213
  export ELASTICSEARCH_HOSTS="https://localhost:9200"
166
214
  export ELASTICSEARCH_USERNAME="elastic"
167
215
  export ELASTICSEARCH_PASSWORD="test123"
168
216
 
217
+ # OR export environment variables (with API key)
218
+ export ELASTICSEARCH_HOSTS="https://localhost:9200"
219
+ export ELASTICSEARCH_API_KEY="<YOUR_ELASTICSEARCH_API_KEY>"
220
+
169
221
  # By default, the SSE MCP server will serve on http://127.0.0.1:8000/sse
170
222
  uvx elasticsearch-mcp-server --transport sse
171
223
 
@@ -188,11 +240,15 @@ uv run src/server.py elasticsearch-mcp-server --transport sse --host 0.0.0.0 --p
188
240
  ### Option 1: Using uvx
189
241
 
190
242
  ```bash
191
- # export environment variables
243
+ # export environment variables (with username/password)
192
244
  export ELASTICSEARCH_HOSTS="https://localhost:9200"
193
245
  export ELASTICSEARCH_USERNAME="elastic"
194
246
  export ELASTICSEARCH_PASSWORD="test123"
195
247
 
248
+ # OR export environment variables (with API key)
249
+ export ELASTICSEARCH_HOSTS="https://localhost:9200"
250
+ export ELASTICSEARCH_API_KEY="<YOUR_ELASTICSEARCH_API_KEY>"
251
+
196
252
  # By default, the Streamable HTTP MCP server will serve on http://127.0.0.1:8000/mcp
197
253
  uvx elasticsearch-mcp-server --transport streamable-http
198
254
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "opensearch-mcp-server"
3
- version = "2.0.10"
3
+ version = "2.0.11"
4
4
  description = "MCP Server for interacting with Elasticsearch and OpenSearch"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -24,12 +24,14 @@ def create_search_client(engine_type: str) -> SearchClient:
24
24
  hosts = [host.strip() for host in hosts_str.split(",")]
25
25
  username = os.environ.get(f"{prefix}_USERNAME")
26
26
  password = os.environ.get(f"{prefix}_PASSWORD")
27
+ api_key = os.environ.get(f"{prefix}_API_KEY")
27
28
  verify_certs = os.environ.get(f"{prefix}_VERIFY_CERTS", "false").lower() == "true"
28
29
 
29
30
  config = {
30
31
  "hosts": hosts,
31
32
  "username": username,
32
33
  "password": password,
34
+ "api_key": api_key,
33
35
  "verify_certs": verify_certs
34
36
  }
35
37
 
@@ -24,6 +24,7 @@ class SearchClientBase(ABC):
24
24
  hosts = config.get("hosts")
25
25
  username = config.get("username")
26
26
  password = config.get("password")
27
+ api_key = config.get("api_key")
27
28
  verify_certs = config.get("verify_certs", False)
28
29
 
29
30
  # Disable insecure request warnings if verify_certs is False
@@ -39,8 +40,8 @@ class SearchClientBase(ABC):
39
40
 
40
41
  # Initialize client based on engine type
41
42
  if engine_type == "elasticsearch":
42
- # Get auth parameters based on elasticsearch package version
43
- auth_params = self._get_elasticsearch_auth_params(username, password)
43
+ # Get auth parameters based on elasticsearch package version and authentication method
44
+ auth_params = self._get_elasticsearch_auth_params(username, password, api_key)
44
45
 
45
46
  self.client = Elasticsearch(
46
47
  hosts=hosts,
@@ -64,20 +65,26 @@ class SearchClientBase(ABC):
64
65
  base_url=base_url,
65
66
  username=username,
66
67
  password=password,
68
+ api_key=api_key,
67
69
  verify_certs=verify_certs,
68
70
  )
69
71
 
70
- def _get_elasticsearch_auth_params(self, username: Optional[str], password: Optional[str]) -> Dict:
72
+ def _get_elasticsearch_auth_params(self, username: Optional[str], password: Optional[str], api_key: Optional[str]) -> Dict:
71
73
  """
72
74
  Get authentication parameters for Elasticsearch client based on package version.
73
75
 
74
76
  Args:
75
77
  username: Username for authentication
76
78
  password: Password for authentication
79
+ api_key: API key for authentication
77
80
 
78
81
  Returns:
79
82
  Dictionary with appropriate auth parameters for the ES version
80
83
  """
84
+ # API key takes precedence over username/password
85
+ if api_key:
86
+ return {"api_key": api_key}
87
+
81
88
  if not username or not password:
82
89
  return {}
83
90
 
@@ -97,20 +104,28 @@ class SearchClientBase(ABC):
97
104
  return {"basic_auth": (username, password)}
98
105
 
99
106
  class GeneralRestClient:
100
- def __init__(self, base_url: Optional[str], username: Optional[str], password: Optional[str], verify_certs: bool):
107
+ def __init__(self, base_url: Optional[str], username: Optional[str], password: Optional[str], api_key: Optional[str], verify_certs: bool):
101
108
  self.base_url = base_url.rstrip("/") if base_url else ""
102
109
  self.auth = (username, password) if username and password else None
110
+ self.api_key = api_key
103
111
  self.verify_certs = verify_certs
104
112
 
105
113
  def request(self, method, path, params=None, body=None):
106
114
  url = f"{self.base_url}/{path.lstrip('/')}"
115
+ headers = {}
116
+
117
+ # Add API key to Authorization header if provided
118
+ if self.api_key:
119
+ headers["Authorization"] = f"ApiKey {self.api_key}"
120
+
107
121
  with httpx.Client(verify=self.verify_certs) as client:
108
122
  resp = client.request(
109
123
  method=method.upper(),
110
124
  url=url,
111
125
  params=params,
112
126
  json=body,
113
- auth=self.auth
127
+ auth=self.auth if not self.api_key else None, # Use basic auth only if no API key
128
+ headers=headers
114
129
  )
115
130
  resp.raise_for_status()
116
131
  ct = resp.headers.get("content-type", "")
@@ -0,0 +1 @@
1
+ __version__ = "2.0.11"