mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 11:15:24 +03:00
fix(cli): save prompted API keys to an owner-only .env
- the key prompt created .env with the default umask, typically readable by other local users - create it 0600 and tighten an existing file before writing the key; a read-only file is still updated
This commit is contained in:
@@ -643,7 +643,11 @@ def ensure_api_key(provider: str) -> str | None:
|
||||
return None
|
||||
|
||||
env_path = find_dotenv(usecwd=True) or str(Path.cwd() / ".env")
|
||||
Path(env_path).touch(exist_ok=True)
|
||||
# The file holds credentials, so make it owner-only before writing: create
|
||||
# it 0600 when absent, and tighten an existing one (set_key keeps the mode).
|
||||
if not os.path.exists(env_path):
|
||||
os.close(os.open(env_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o600))
|
||||
os.chmod(env_path, 0o600)
|
||||
set_key(env_path, env_var, key)
|
||||
os.environ[env_var] = key
|
||||
console.print(f"[green]Saved {env_var} to {env_path}[/green]")
|
||||
|
||||
Reference in New Issue
Block a user