fix(dashboard): profile-scope Channels endpoints and seed per-profile .env (#44792)
Two halves of the same community report (dashboard Profile Builder): 1. A fresh dashboard/CLI-created profile got no .env file unless cloned, so it silently inherited API keys and messaging tokens from the shell environment / root install. create_profile() now seeds a placeholder .env (0600) for non-clone profiles, matching the SOUL.md seeding. 2. The Channels endpoints (/api/messaging/platforms GET/PUT/test) were not profile-scoped: they read/wrote the dashboard process's own .env via load_env()/save_env_value() regardless of the global profile switcher. They now accept the standard optional profile param (body beats query on the PUT, matching other scoped writes) and run inside _profile_scope(). When scoped, the payload no longer falls back to os.environ or load_gateway_config()'s env-override layer — both carry the ROOT install's credentials and would misreport them as the profile's. /api/messaging/platforms added to PROFILE_SCOPED_PREFIXES so the sidebar switcher scopes the Channels page automatically.
This commit is contained in:
@@ -835,6 +835,25 @@ def create_profile(
|
||||
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||
shutil.copy2(src, dst)
|
||||
|
||||
# Seed an empty .env so the profile has its own credentials file from
|
||||
# day one. Without it, profile-scoped env writes (dashboard Channels /
|
||||
# Keys pages, `hermes -p <name> auth add`) had no file until first
|
||||
# write, and the profile silently inherited API keys from the shell
|
||||
# environment — users reasonably read that as "the new profile reads
|
||||
# the root .env". Skipped when --clone/--clone-all already copied one.
|
||||
env_path = profile_dir / ".env"
|
||||
if not env_path.exists():
|
||||
try:
|
||||
env_path.write_text(
|
||||
"# Per-profile secrets for this Hermes profile.\n"
|
||||
"# API keys and tokens set here override the shell environment.\n"
|
||||
"# Behavioral settings belong in config.yaml, not here.\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
os.chmod(str(env_path), 0o600)
|
||||
except OSError:
|
||||
pass # best-effort — save_env_value creates the file on demand
|
||||
|
||||
# Seed a default SOUL.md so the user has a file to customize immediately.
|
||||
# Skipped when the profile already has one (from --clone / --clone-all).
|
||||
soul_path = profile_dir / "SOUL.md"
|
||||
|
||||
Reference in New Issue
Block a user