Skip to content

Commit ce5a4c1

Browse files
Minor fixes for agent component (#2839)
1 parent e6f8650 commit ce5a4c1

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ docker-push:
9696

9797
## Agent Docker Zone
9898
# Only use it for local testing, that's it
99-
AGENT_ES_HOSTS?=http://127.0.0.1:9200
99+
AGENT_ES_HOSTS?=[http://127.0.0.1:9200]
100100
AGENT_ES_USERNAME?=elastic
101101
AGENT_ES_PASSWORD?=changeme
102102
AGENT_DOCKERFILE_NAME?=Dockerfile.agent

connectors/agent/config.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# or more contributor license agreements. Licensed under the Elastic License 2.0;
44
# you may not use this file except in compliance with the Elastic License 2.0.
55
#
6+
import base64
7+
68
from connectors.config import add_defaults
79

810

@@ -24,6 +26,9 @@ def __init__(self):
2426
"""
2527
self._default_config = {
2628
"_force_allow_native": True,
29+
"service": {
30+
"_use_native_connector_api_keys": False,
31+
},
2732
"native_service_types": [
2833
"azure_blob_storage",
2934
"box",
@@ -74,7 +79,12 @@ def try_update(self, source):
7479
}
7580

7681
if source.fields.get("api_key"):
77-
es_creds["api_key"] = source["api_key"]
82+
api_key = source["api_key"]
83+
# if beats_logstash_format we need to base64 the key
84+
if ":" in api_key:
85+
api_key = base64.b64encode(api_key.encode()).decode()
86+
87+
es_creds["api_key"] = api_key
7888
elif source.fields.get("username") and source.fields.get("password"):
7989
es_creds["username"] = source["username"]
8090
es_creds["password"] = source["password"]

tests/agent/test_agent_config.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,24 @@ async def test_try_update_with_api_key_auth_data():
3636
assert config_wrapper.get()["elasticsearch"]["api_key"] == api_key
3737

3838

39+
@pytest.mark.asyncio
40+
async def test_try_update_with_non_encoded_api_key_auth_data():
41+
hosts = ["https://localhost:9200"]
42+
api_key = "something:else"
43+
encoded = "c29tZXRoaW5nOmVsc2U="
44+
45+
config_wrapper = ConnectorsAgentConfigurationWrapper()
46+
source_mock = MagicMock()
47+
fields_container = {"hosts": hosts, "api_key": api_key}
48+
49+
source_mock.fields = fields_container
50+
source_mock.__getitem__.side_effect = fields_container.__getitem__
51+
52+
assert config_wrapper.try_update(source_mock) is True
53+
assert config_wrapper.get()["elasticsearch"]["host"] == hosts[0]
54+
assert config_wrapper.get()["elasticsearch"]["api_key"] == encoded
55+
56+
3957
@pytest.mark.asyncio
4058
async def test_try_update_with_basic_auth_auth_data():
4159
hosts = ["https://localhost:9200"]

0 commit comments

Comments
 (0)