import tarfile import os files = { "Dockerfile": """FROM python:3.12-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python3", "exporter/metrics_exporter.py"] """, "requirements.txt": """prometheus_client==0.20.0 """, "exporter/metrics_exporter.py": """import time import sqlite3 from prometheus_client import start_http_server, Counter WEAK_ENCRYPTION_COUNTER = Counter( 'orbital_weak_encryption_streams_total', 'Total number of weak or plaintext orbital telemetry streams', ['file_name', 'encryption_status'] ) def poll_database(): conn = sqlite3.connect("orbital_forensics.db") cursor = conn.cursor() cursor.execute("SELECT file_name, encryption_status FROM itar_file_transfers WHERE encryption_status = 'Plaintext'") rows = cursor.fetchall() for file_name, encryption_status in rows: WEAK_ENCRYPTION_COUNTER.labels(file_name=file_name, encryption_status=encryption_status).inc() conn.close() if __name__ == "__main__": start_http_server(9101) while True: try: poll_database() except Exception as e: pass time.sleep(2) """, "tests/test_telemetry_pipeline.py": """import time import sqlite3 import urllib.request import unittest DB_PATH = "orbital_forensics.db" METRICS_URL = "http://localhost:9101/metrics" class TestTelemetryPipeline(unittest.TestCase): def setUp(self): self.conn = sqlite3.connect(DB_PATH) cursor = self.conn.cursor() cursor.execute(''' CREATE TABLE IF NOT EXISTS itar_file_transfers ( id INTEGER PRIMARY KEY AUTOINCREMENT, file_name TEXT, encryption_status TEXT, ground_station_id TEXT, status TEXT ) ''') cursor.execute(''' INSERT INTO itar_file_transfers (file_name, encryption_status, ground_station_id, status) VALUES ('starlink_blueprint_v4.enc', 'Plaintext', 'GS-US-WEST-1', 'PENDING') ''') self.conn.commit() def test_prometheus_metric_increment(self): time.sleep(3) req = urllib.request.urlopen(METRICS_URL) metrics_output = req.read().decode('utf-8') self.assertIn("orbital_weak_encryption_streams_total", metrics_output) self.assertIn('file_name="starlink_blueprint_v4.enc"', metrics_output) self.assertIn('encryption_status="Plaintext"', metrics_output) def tearDown(self): cursor = self.conn.cursor() cursor.execute("DELETE FROM itar_file_transfers WHERE file_name = 'starlink_blueprint_v4.enc'") self.conn.commit() self.conn.close() if __name__ == "__main__": unittest.main() """, ".github/workflows/deploy.yml": """name: Telemetry CI/CD & Container Build on: push: branches: [ main ] pull_request: branches: [ main ] jobs: test: name: Run Telemetry Pipeline Integration Tests runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v5 with: python-version: '3.12' - run: pip install prometheus_client - run: python3 exporter/metrics_exporter.py & - run: python3 -m unittest tests/test_telemetry_pipeline.py """ } archive_name = "spacex-orbital-forensics-repo-v9.tar.gz" with tarfile.open(archive_name, "w:gz") as tar: for path, content in files.items(): os.makedirs(os.path.dirname(path), exist_ok=True) if os.path.dirname(path) else None with open(path, "w") as f: f.write(content) tar.add(path) print(f"Archive created: {archive_name}")