Files
2026-10-29 10:55:49 +03:00

33 lines
916 B
Python
Executable File

#!/usr/bin/env python3
from __future__ import annotations
import os
import secrets
import sys
from pathlib import Path
def main() -> int:
target = Path(__file__).resolve().with_name(".env")
values = {
"STARPOST_DB_PASSWORD": secrets.token_urlsafe(48),
"STARPOST_SECRET_KEY": secrets.token_urlsafe(48),
"STARPOST_WAREHOUSE_CALLBACK_TOKEN": secrets.token_urlsafe(48),
}
try:
descriptor = os.open(target, os.O_WRONLY | os.O_CREAT | os.O_EXCL, 0o600)
except FileExistsError:
print(f"refusing to overwrite existing {target}", file=sys.stderr)
return 1
with os.fdopen(descriptor, "w", encoding="utf-8") as output:
for key, value in values.items():
output.write(f"{key}={value}\n")
os.chmod(target, 0o600)
print(f"created {target} with mode 0600")
return 0
if __name__ == "__main__":
raise SystemExit(main())