From ec88268d89196a5d185d3e5536355d67e5372fe7 Mon Sep 17 00:00:00 2001 From: Jean GOUDY Date: Fri, 5 Jul 2024 11:43:56 +0200 Subject: [PATCH] feat(check-intake-keys): verify intake keys --- .github/workflows/build-docker-image.yaml | 2 +- CHANGELOG.md | 4 +++ docker-compose/docker-compose.yml | 2 +- entrypoint.sh | 2 -- generate_config.py | 43 +++++++++++++++++------ 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/.github/workflows/build-docker-image.yaml b/.github/workflows/build-docker-image.yaml index 6b36844..a372812 100644 --- a/.github/workflows/build-docker-image.yaml +++ b/.github/workflows/build-docker-image.yaml @@ -32,4 +32,4 @@ jobs: push: true tags: | ghcr.io/sekoia-io/sekoiaio-docker-concentrator:latest - ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5 + ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5.1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 788b2b9..5b8cf04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes with sekoiaio concentrator will be documented in this file. +## [2.5.1] + +- Check the format of Intake keys. + ## [2.5] - Added the support of multi-region diff --git a/docker-compose/docker-compose.yml b/docker-compose/docker-compose.yml index d2f3f1a..16d27b9 100644 --- a/docker-compose/docker-compose.yml +++ b/docker-compose/docker-compose.yml @@ -2,7 +2,7 @@ # version: "3.9" services: rsyslog: - image: ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5 + image: ghcr.io/sekoia-io/sekoiaio-docker-concentrator:2.5.1 environment: - MEMORY_MESSAGES=2000000 - DISK_SPACE=180g diff --git a/entrypoint.sh b/entrypoint.sh index a9d91ac..51b4219 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -2,8 +2,6 @@ echo "Starting Entrypoint" echo "" -echo "These Intakes have been set up" -echo "-----------------------------" # Create rsyslog.conf envsubst '${DISK_SPACE} ${MEMORY_MESSAGES}' /etc/rsyslog.conf diff --git a/generate_config.py b/generate_config.py index e6f67d3..e27b610 100644 --- a/generate_config.py +++ b/generate_config.py @@ -1,8 +1,16 @@ #!/usr/bin/env python +import os +import re + import yaml from jinja2 import Environment, FileSystemLoader -import os + + +def is_intake_key(intake_key: str) -> re.Match | bool: + pattern = "^[a-zA-Z0-9]{16}" + return re.search(pattern, intake_key) + # Open input config file with open("intakes.yaml", "r") as fyaml: @@ -22,25 +30,40 @@ else: endpoint = "intake.sekoia.io" -i=1 +i = 1 +to_print = [] +to_print.append("These Intakes have been set up") +to_print.append("-----------------------------") + # Generate one file per intake for item in data.get("intakes", []): - print("Intake name: " + str(item["name"].lower())) - print("Protocol: " + str(item["protocol"])) - print("Port: " + str(item["port"])) - print("Intake key: " + str(item["intake_key"])) - print("") + if not is_intake_key(item["intake_key"]): + print( + f"ERROR: The Intake Key provided for Intake Name {item['name'].lower()} is incorrect. Exiting..." + ) + exit(0) + + to_print.append("Intake name: " + str(item["name"].lower())) + to_print.append("Protocol: " + str(item["protocol"])) + to_print.append("Port: " + str(item["port"])) + to_print.append("Intake key: " + str(item["intake_key"])) + to_print.append("") item["endpoint"] = endpoint config = template.render(item) filename = f"/etc/rsyslog.d/{i}_{item['name'].lower()}.conf" # Écrire le contenu généré dans le fichier with open(filename, "w") as f: f.write(config) - i=i+1 + i = i + 1 # Check additional conf -XTENDED_CONF="/extended_conf/" +XTENDED_CONF = "/extended_conf/" if os.path.exists(XTENDED_CONF): for file in os.listdir(XTENDED_CONF): if file.endswith(".conf"): - print("Detected an additonal intake defined in file {}".format(file)) \ No newline at end of file + to_print.append( + "Detected an additonal intake defined in file {}".format(file) + ) + +for line in to_print: + print(line)