From b1c3677f909bb70d9318c6ee99ed1b03f55c9906 Mon Sep 17 00:00:00 2001 From: Jeremias Pretto Date: Tue, 23 Mar 2021 15:44:44 -0300 Subject: [PATCH] 2.3 compatibility --- .docker/intelmq-full-dev/merge_BOTS.py | 15 ++++++++++----- .docker/intelmq-full-dev/update.sh | 11 +++++++---- DEVELOP-GUIDE.md | 2 +- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/.docker/intelmq-full-dev/merge_BOTS.py b/.docker/intelmq-full-dev/merge_BOTS.py index 095d4bd..f56e6de 100644 --- a/.docker/intelmq-full-dev/merge_BOTS.py +++ b/.docker/intelmq-full-dev/merge_BOTS.py @@ -1,14 +1,18 @@ import json from jsonmerge import merge +import argparse from collections import OrderedDict -file1="/opt/dev/mybots/BOTS" -file2="/opt/intelmq/intelmq/bots/BOTS" +parser = argparse.ArgumentParser(description='Merge two json.') +parser.add_argument('input_file_1', type=str, help='input_file_1') +parser.add_argument('input_file_2', type=str, help='input_file_2') +parser.add_argument('output_file', type=str, help='output_file') +args = parser.parse_args() -with open(file1, 'r') as f: +with open(args.input_file_1, 'r') as f: j1 = json.load(f) -with open(file2, 'r') as f: +with open(args.input_file_2, 'r') as f: j2 = json.load(f) def sortOD(od): @@ -26,8 +30,9 @@ merged = sortOD(merge(j1,j2)) desired_order_list = ['Collector', 'Parser', 'Expert', 'Output'] reordered_dict = {k: merged[k] for k in desired_order_list} +# add other keys reordered_dict.update({k: merged[k] for k in merged.keys() - desired_order_list}) -with open(file2, 'w') as f: +with open(args.output_file, 'w') as f: json.dump(reordered_dict, f, indent=4) diff --git a/.docker/intelmq-full-dev/update.sh b/.docker/intelmq-full-dev/update.sh index a46dc6a..b3a0061 100755 --- a/.docker/intelmq-full-dev/update.sh +++ b/.docker/intelmq-full-dev/update.sh @@ -3,15 +3,18 @@ echo "Installing requirements for bots in dev repository" for file in $(find /opt/dev/mybots -name "*REQUIREMENTS.txt"); do pip3 install -r $file; done +# Backup Original BOTS +cp /opt/intelmq/intelmq/bots/BOTS /opt/intelmq/intelmq/bots/BOTS.bk + echo "Merge your BOTS file with BOTS" -python3 /opt/dev/merge_BOTS.py +python3 /opt/dev/merge_BOTS.py "/opt/dev/mybots/BOTS" "/opt/intelmq/intelmq/bots/BOTS" "/opt/intelmq/intelmq/bots/BOTS" +cp /opt/intelmq/intelmq/bots/BOTS /opt/intelmq/etc/BOTS echo "Copying BOTS" cp -a /opt/dev/mybots/bots/* /opt/intelmq/intelmq/bots/ -cp /opt/intelmq/intelmq/bots/BOTS /opt/intelmq/etc/BOTS - echo "Installing new BOTS" cd /opt/intelmq && pip3 install -e . --user && python3 setup.py install --user - +# Restore original BOTS +mv /opt/intelmq/intelmq/bots/BOTS.bk /opt/intelmq/intelmq/bots/BOTS diff --git a/DEVELOP-GUIDE.md b/DEVELOP-GUIDE.md index 1f57e5f..8c1fd52 100644 --- a/DEVELOP-GUIDE.md +++ b/DEVELOP-GUIDE.md @@ -40,6 +40,6 @@ Just clone your bots git to ./mybots and run the container For example, using https://github.com/CERTUNLP/intelmq-bots: -1. `git clone https://github.com/CERTUNLP/intelmq-bots mybots` +1. `git clone https://github.com/CERTUNLP/intelmq-bots mybots -b 2.3` 0. `docker-compose -f docker-compose-dev.yml up`