dev fix, ip controls

This commit is contained in:
JiriUhlir
2026-06-15 11:08:31 +02:00
parent bf4796d153
commit a948324b2e
5 changed files with 310 additions and 1 deletions
+90
View File
@@ -408,6 +408,96 @@ def delete_app_variable(variable_id: int, app_id: str):
con.close()
def get_app_ip_access_rules(app_id: str):
run_migrations()
con = get_connection()
rows = con.execute(
"""
SELECT id, app_id, ip_cidr, methods, description,
COALESCE(is_enabled, 1) AS is_enabled, created_at, updated_at
FROM app_ip_access_rules
WHERE app_id = ?
ORDER BY id
""",
(app_id,),
).fetchall()
con.close()
return [dict(row) for row in rows]
def get_app_ip_access_rule(rule_id: int, app_id: str):
run_migrations()
con = get_connection()
row = con.execute(
"""
SELECT id, app_id, ip_cidr, methods, description,
COALESCE(is_enabled, 1) AS is_enabled, created_at, updated_at
FROM app_ip_access_rules
WHERE id = ? AND app_id = ?
""",
(rule_id, app_id),
).fetchone()
con.close()
return dict(row) if row else None
def create_app_ip_access_rule(app_id: str, ip_cidr: str, methods: str, description: str, is_enabled: bool):
run_migrations()
con = get_connection()
con.execute(
"""
INSERT INTO app_ip_access_rules (app_id, ip_cidr, methods, description, is_enabled, created_at, updated_at)
VALUES (?, ?, ?, ?, ?, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
""",
(app_id, ip_cidr, methods, description, 1 if is_enabled else 0),
)
con.commit()
con.close()
def update_app_ip_access_rule(rule_id: int, app_id: str, ip_cidr: str, methods: str, description: str, is_enabled: bool):
run_migrations()
con = get_connection()
con.execute(
"""
UPDATE app_ip_access_rules
SET ip_cidr = ?,
methods = ?,
description = ?,
is_enabled = ?,
updated_at = CURRENT_TIMESTAMP
WHERE id = ? AND app_id = ?
""",
(ip_cidr, methods, description, 1 if is_enabled else 0, rule_id, app_id),
)
con.commit()
con.close()
def delete_app_ip_access_rule(rule_id: int, app_id: str):
run_migrations()
con = get_connection()
con.execute(
"""
DELETE FROM app_ip_access_rules
WHERE id = ? AND app_id = ?
""",
(rule_id, app_id),
)
con.commit()
con.close()
def update_app_resources(app_id: str, memory: str, cpus: str):
run_migrations()
con = get_connection()
+16
View File
@@ -267,5 +267,21 @@ def run_migrations():
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_events_created ON alert_events(created_at)")
con.execute("CREATE INDEX IF NOT EXISTS idx_alert_events_job_id ON alert_events(job_id)")
con.execute(
"""
CREATE TABLE IF NOT EXISTS app_ip_access_rules (
id INTEGER PRIMARY KEY AUTOINCREMENT,
app_id TEXT NOT NULL,
ip_cidr TEXT NOT NULL,
methods TEXT NOT NULL DEFAULT 'WRITE',
description TEXT,
is_enabled INTEGER NOT NULL DEFAULT 1,
created_at TEXT DEFAULT CURRENT_TIMESTAMP,
updated_at TEXT DEFAULT CURRENT_TIMESTAMP
)
"""
)
con.execute("CREATE INDEX IF NOT EXISTS idx_app_ip_access_rules_app_id ON app_ip_access_rules(app_id)")
con.commit()
con.close()