Skip to content

Commit 6573875

Browse files
IntelMQ Docker adaptions
IntelMQCTL docker ready Read enviroment variables Tests read env. vars. to run in docker containers Fixed typo in test.py Signed-off-by: Sebastian Waldbauer <[email protected]>
1 parent 4351b1e commit 6573875

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

intelmq/bin/intelmqctl.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,14 @@ def load_defaults_configuration(self, silent=False):
10161016
for option, value in config.items():
10171017
setattr(self.parameters, option, value)
10181018

1019+
# TODO: Rewrite variables with env. variables ( CURRENT IMPLEMENTATION NOT FINAL )
1020+
# "destination_pipeline_host": "127.0.0.1",
1021+
# "source_pipeline_host": "127.0.0.1",
1022+
if os.getenv('INTELMQ_IS_DOCKER', None):
1023+
pipeline_host = os.getenv('INTELMQ_PIPELINE_HOST')
1024+
setattr(self.parameters, 'destination_pipeline_host', pipeline_host)
1025+
setattr(self.parameters, 'source_pipeline_host', pipeline_host)
1026+
10191027
def run(self):
10201028
results = None
10211029
args = self.parser.parse_args()

intelmq/lib/bot.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,18 @@ def __load_defaults_configuration(self):
697697

698698
self.parameters.log_processed_messages_seconds = timedelta(seconds=self.parameters.log_processed_messages_seconds)
699699

700+
# TODO: Rewrite variables with env. variables ( CURRENT IMPLEMENTATION NOT FINAL )
701+
if os.getenv('INTELMQ_IS_DOCKER', None):
702+
pipeline_driver = os.getenv('INTELMQ_PIPELINE_DRIVER', None)
703+
if pipeline_driver:
704+
setattr(self.parameters, 'destination_pipeline_broker', pipeline_driver)
705+
setattr(self.parameters, 'source_pipeline_broker', pipeline_driver)
706+
707+
pipeline_host = os.getenv('INTELMQ_PIPELINE_HOST', None)
708+
if pipeline_host:
709+
setattr(self.parameters, 'destination_pipeline_host', pipeline_host)
710+
setattr(self.parameters, 'source_pipeline_host', pipeline_host)
711+
700712
def __load_runtime_configuration(self):
701713
self.logger.debug("Loading runtime configuration from %r.", RUNTIME_CONF_FILE)
702714
config = utils.load_configuration(RUNTIME_CONF_FILE)
@@ -719,6 +731,12 @@ def __load_runtime_configuration(self):
719731
self.logger.handlers = [] # remove all existing handlers
720732
self.__init_logger()
721733

734+
# TODO: Rework
735+
if os.getenv('INTELMQ_IS_DOCKER', None):
736+
redis_cache_host = os.getenv('INTELMQ_REDIS_CACHE_HOST', None)
737+
if redis_cache_host:
738+
setattr(self.parameters, 'redis_cache_host', redis_cache_host)
739+
722740
def __init_logger(self):
723741
"""
724742
Initialize the logger.

intelmq/lib/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"retry_delay": 0,
3333
"error_retry_delay": 0,
3434
"error_max_retries": 0,
35-
"redis_cache_host": "localhost",
35+
"redis_cache_host": os.getenv('INTELMQ_PIPELINE_HOST', 'localhost'),
3636
"redis_cache_port": 6379,
3737
"redis_cache_db": 4,
3838
"redis_cache_ttl": 10,

intelmq/tests/bots/outputs/redis/test_output.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class TestRedisOutputBot(test.BotTestCase, unittest.TestCase):
4141
def set_bot(cls):
4242
cls.bot_reference = RedisOutputBot
4343
cls.default_input_message = EXAMPLE_EVENT
44-
cls.sysconfig = {"redis_server_ip": "127.0.0.1",
44+
cls.sysconfig = {"redis_server_ip": os.getenv('INTELMQ_PIPELINE_HOST', 'localhost'),
4545
"redis_server_port": 6379,
4646
"redis_db": 4,
4747
"redis_queue": "test-redis-output-queue",

intelmq/tests/bots/outputs/redis/test_output_as_hierarchical_json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class TestRedisOutputBot(test.BotTestCase, unittest.TestCase):
8080
def set_bot(cls):
8181
cls.bot_reference = RedisOutputBot
8282
cls.default_input_message = EXAMPLE_EVENT
83-
cls.sysconfig = {"redis_server_ip": "127.0.0.1",
83+
cls.sysconfig = {"redis_server_ip": os.getenv('INTELMQ_PIPELINE_HOST', 'localhost'),
8484
"redis_server_port": 6379,
8585
"redis_db": 4,
8686
"redis_queue": "test-redis-output-queue",

intelmq/tests/lib/test_pipeline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ class TestRedis(unittest.TestCase):
143143
def setUp(self):
144144
params = Parameters()
145145
params.broker = 'Redis'
146+
setattr(params, 'source_pipeline_host', os.getenv('INTELMQ_PIPELINE_HOST', 'localhost'))
146147
setattr(params, 'source_pipeline_password', os.getenv('INTELMQ_TEST_REDIS_PASSWORD'))
147148
setattr(params, 'source_pipeline_db', 4)
149+
setattr(params, 'destination_pipeline_host', os.getenv('INTELMQ_PIPELINE_HOST', 'localhost'))
148150
setattr(params, 'destination_pipeline_password', os.getenv('INTELMQ_TEST_REDIS_PASSWORD'))
149151
setattr(params, 'destination_pipeline_db', 4)
150152
logger = logging.getLogger('foo')

0 commit comments

Comments
 (0)