update
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Prepare a local PMS bridge without printing credentials or touching business databases."""
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import secrets
|
||||
import sys
|
||||
|
||||
PLATFORM_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(PLATFORM_ROOT))
|
||||
|
||||
from app.core.config import get_settings # noqa: E402
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--pms-root", required=True, type=Path)
|
||||
parser.add_argument("--base-url", default="http://127.0.0.1:8000/api/v1/work-assistant")
|
||||
args = parser.parse_args()
|
||||
pms_root = args.pms_root.resolve()
|
||||
if not (pms_root / "ruoyi-admin" / "pom.xml").is_file():
|
||||
parser.error("--pms-root must be the management system repository")
|
||||
os.chdir(PLATFORM_ROOT)
|
||||
key = get_settings().work_assistant_shared_secret or ""
|
||||
if len(key) < 32:
|
||||
key = secrets.token_urlsafe(48)
|
||||
env_path = PLATFORM_ROOT / ".env"
|
||||
content = env_path.read_text(encoding="utf-8") if env_path.exists() else ""
|
||||
import re
|
||||
content = re.sub(r"(?m)^\s*WORK_ASSISTANT_SHARED_SECRET\s*=.*(?:\r?\n|$)", "", content)
|
||||
env_path.write_text(content.rstrip() + "\nWORK_ASSISTANT_SHARED_SECRET=" + key + "\n", encoding="utf-8")
|
||||
config = pms_root / ".work-assistant.properties"
|
||||
content = "assistant.base-url=" + args.base_url + "\nassistant.shared-secret=" + key + "\n"
|
||||
# Properties use ASCII; no real credential is ever committed or printed.
|
||||
config.write_text(content, encoding="ascii")
|
||||
print("Local assistant bridge configured. Credentials are stored only in ignored local files.")
|
||||
print("No business database migration is required.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user