File tree Expand file tree Collapse file tree 3 files changed +30
-2
lines changed
Expand file tree Collapse file tree 3 files changed +30
-2
lines changed Original file line number Diff line number Diff 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]
100100AGENT_ES_USERNAME? =elastic
101101AGENT_ES_PASSWORD? =changeme
102102AGENT_DOCKERFILE_NAME? =Dockerfile.agent
Original file line number Diff line number Diff line change 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+
68from 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" ]
Original file line number Diff line number Diff 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
4058async def test_try_update_with_basic_auth_auth_data ():
4159 hosts = ["https://localhost:9200" ]
You can’t perform that action at this time.
0 commit comments