Skip to content

armgit / strix

Public Imported from GitHub
0

Open-source AI penetration testing tool to find and fix your app’s vulnerabilities.

Added .env variable override through --config param

FeedClogger4ab9af6e47cd
diff --git a/strix/config/config.py b/strix/config/config.py
index 4c67e4a4..08057cd4 100644
--- a/strix/config/config.py
+++ b/strix/config/config.py
@@ -163,6 +163,14 @@ class Config:
return cls.save({"env": merged})
+ @classmethod
+ def override(cls, key: str, value: str) -> None:
+ """Override a configuration variable dynamically."""
+ if hasattr(cls, key):
+ setattr(cls, key, value)
+ else:
+ os.environ[key] = value
+
def apply_saved_config() -> dict[str, str]:
return Config.apply_saved()
diff --git a/strix/interface/main.py b/strix/interface/main.py
index e2c89b8a..3b36e596 100644
--- a/strix/interface/main.py
+++ b/strix/interface/main.py
@@ -5,6 +5,7 @@ Strix Agent Interface
import argparse
import asyncio
+import json
import logging
import shutil
import sys
@@ -356,6 +357,12 @@ Examples:
),
)
+ parser.add_argument(
+ "--config",
+ type=str,
+ help="Path to the configuration file (.json)",
+ )
+
args = parser.parse_args()
if args.instruction and args.instruction_file:
@@ -500,12 +507,30 @@ def pull_docker_image() -> None:
console.print()
+def load_config_file(config_path: str):
+ if config_path.endswith(".json"):
+ try:
+ with open(config_path, "r", encoding="utf-8") as f:
+ config_data = json.load(f)
+ for key, value in config_data.items():
+ Config.override(key, str(value)) # Use Config class to override variables
+ except (json.JSONDecodeError, OSError) as e:
+ print(f"Error loading JSON config file: {e}")
+ sys.exit(1)
+ else:
+ print("Unsupported config file format. Use .json.")
+ sys.exit(1)
+
+
def main() -> None:
if sys.platform == "win32":
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
args = parse_arguments()
+ if args.config:
+ load_config_file(args.config)
+
check_docker_installed()
pull_docker_image()