MCPcopy Create free account
hub / github.com/CScorza/IntelOSINT / _bootstrap_tokens

Function _bootstrap_tokens

IntelOSINT.py:1942–1967  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1940
1941
1942def _bootstrap_tokens():
1943 env_path = Path(__file__).resolve().parent / ".env"
1944 env_values = _read_env_file_values(env_path)
1945
1946 admin_token = (os.environ.get("INTELOSINT_ADMIN_TOKEN") or env_values.get("INTELOSINT_ADMIN_TOKEN") or "").strip()
1947 if not admin_token:
1948 admin_token = os.urandom(32).hex()
1949 elif len(admin_token) < 24:
1950 admin_token = admin_token + os.urandom(16).hex()
1951
1952 cred_key = (os.environ.get("INTELOSINT_CRED_KEY") or env_values.get("INTELOSINT_CRED_KEY") or "").strip()
1953 if not _is_valid_fernet_key(cred_key):
1954 if Fernet is None:
1955 raise RuntimeError("Dipendenza cryptography non disponibile: impossibile gestire INTELOSINT_CRED_KEY.")
1956 cred_key = Fernet.generate_key().decode("utf-8")
1957
1958 os.environ["INTELOSINT_ADMIN_TOKEN"] = admin_token
1959 os.environ["INTELOSINT_CRED_KEY"] = cred_key
1960 env_values["INTELOSINT_ADMIN_TOKEN"] = admin_token
1961 env_values["INTELOSINT_CRED_KEY"] = cred_key
1962
1963 try:
1964 env_lines = [f"{k}={v}" for k, v in env_values.items()]
1965 env_path.write_text("\n".join(env_lines) + "\n", encoding="utf-8")
1966 except Exception:
1967 print(f"[!] Impossibile scrivere o aggiornare il file {env_path}.")
1968
1969
1970_load_local_env_file()

Callers 1

IntelOSINT.pyFile · 0.85

Calls 2

_read_env_file_valuesFunction · 0.85
_is_valid_fernet_keyFunction · 0.85

Tested by

no test coverage detected