|
1 | 1 | """Config endpoint — CLAUDE.md, ROUTINES.md, ROADMAP.md, .env, commands, Makefile.""" |
2 | 2 |
|
3 | 3 | import re |
4 | | -from flask import Blueprint, jsonify, request, Response, abort |
5 | | -from flask_login import login_required |
| 4 | +from flask import Blueprint, jsonify, Response, abort |
6 | 5 | from routes._helpers import WORKSPACE, safe_read |
7 | 6 |
|
8 | 7 | bp = Blueprint("config", __name__) |
@@ -74,68 +73,6 @@ def list_commands(): |
74 | 73 | return jsonify(commands) |
75 | 74 |
|
76 | 75 |
|
77 | | -@bp.route("/api/config/env") |
78 | | -@login_required |
79 | | -def get_env(): |
80 | | - """Read .env file as structured key-value pairs.""" |
81 | | - content = safe_read(WORKSPACE / ".env") |
82 | | - if content is None: |
83 | | - return jsonify({"entries": [], "raw": ""}) |
84 | | - |
85 | | - entries = [] |
86 | | - for line in content.splitlines(): |
87 | | - stripped = line.strip() |
88 | | - if not stripped or stripped.startswith("#"): |
89 | | - entries.append({"type": "comment", "value": line}) |
90 | | - elif "=" in stripped: |
91 | | - key, _, val = stripped.partition("=") |
92 | | - entries.append({"type": "var", "key": key.strip(), "value": val.strip()}) |
93 | | - else: |
94 | | - entries.append({"type": "comment", "value": line}) |
95 | | - |
96 | | - return jsonify({"entries": entries, "raw": content}) |
97 | | - |
98 | | - |
99 | | -@bp.route("/api/config/env", methods=["PUT"]) |
100 | | -@login_required |
101 | | -def update_env(): |
102 | | - """Update .env file. Accepts {entries: [...]} or {raw: "..."}.""" |
103 | | - from models import has_permission, audit |
104 | | - from flask_login import current_user |
105 | | - |
106 | | - if not has_permission(current_user.role, "config", "manage"): |
107 | | - abort(403) |
108 | | - |
109 | | - data = request.get_json() |
110 | | - env_path = WORKSPACE / ".env" |
111 | | - |
112 | | - if "raw" in data: |
113 | | - # Raw text mode |
114 | | - env_path.write_text(data["raw"]) |
115 | | - elif "entries" in data: |
116 | | - # Structured mode |
117 | | - lines = [] |
118 | | - for entry in data["entries"]: |
119 | | - if entry.get("type") == "comment": |
120 | | - lines.append(entry.get("value", "")) |
121 | | - else: |
122 | | - key = entry.get("key", "") |
123 | | - val = entry.get("value", "") |
124 | | - if key: |
125 | | - lines.append(f"{key}={val}") |
126 | | - env_path.write_text("\n".join(lines) + "\n") |
127 | | - |
128 | | - # Reload dotenv in current process |
129 | | - try: |
130 | | - from dotenv import load_dotenv |
131 | | - load_dotenv(env_path, override=True) |
132 | | - except Exception: |
133 | | - pass |
134 | | - |
135 | | - audit(current_user, "env_updated", "config", "Updated .env file") |
136 | | - return jsonify({"status": "saved"}) |
137 | | - |
138 | | - |
139 | 76 | @bp.route("/api/config/makefile") |
140 | 77 | def parse_makefile(): |
141 | 78 | content = safe_read(WORKSPACE / "Makefile") |
|
0 commit comments