mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2026-04-10 04:01:28 -07:00
Coderabbit fixes:
- Mac - Flask debug - Threaded flask - propagate token in GET requests - enhance spec docs - normalize MAC x2 - mcp disablement redundant private attribute - run all tests imports
This commit is contained in:
@@ -361,6 +361,42 @@ def setting_value_to_python_type(set_type, set_value):
|
||||
return value
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------------
|
||||
# Environment helper
|
||||
def get_env_setting_value(key, default=None):
|
||||
"""Return a typed value from environment variable if present.
|
||||
|
||||
- Parses booleans (1/0, true/false, yes/no, on/off).
|
||||
- Tries to parse ints and JSON literals where sensible.
|
||||
- Returns `default` when env var is not set.
|
||||
"""
|
||||
val = os.environ.get(key)
|
||||
if val is None:
|
||||
return default
|
||||
|
||||
v = val.strip()
|
||||
# Booleans
|
||||
low = v.lower()
|
||||
if low in ("1", "true", "yes", "on"):
|
||||
return True
|
||||
if low in ("0", "false", "no", "off"):
|
||||
return False
|
||||
|
||||
# Integer
|
||||
try:
|
||||
if re.fullmatch(r"-?\d+", v):
|
||||
return int(v)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# JSON-like (list/object/true/false/null/number)
|
||||
try:
|
||||
return json.loads(v)
|
||||
except Exception:
|
||||
# Fallback to raw string
|
||||
return v
|
||||
|
||||
|
||||
# -------------------------------------------------------------------------------
|
||||
def updateSubnets(scan_subnets):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user