You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
658 B
25 lines
658 B
#!/usr/bin/env python3 |
|
"""Generate agent bearer token and SQL to insert into agent_tokens.""" |
|
|
|
import hashlib |
|
import secrets |
|
import sys |
|
|
|
|
|
def main() -> None: |
|
name = sys.argv[1] if len(sys.argv) > 1 else "GPO-Production" |
|
token = secrets.token_urlsafe(32) |
|
token_hash = hashlib.sha256(token.encode()).hexdigest() |
|
|
|
print(f"Token (simpan aman, hanya ditampilkan sekali):\n{token}\n") |
|
print("SQL insert:") |
|
print( |
|
f"INSERT INTO agent_tokens (name, token_hash, is_active) " |
|
f"VALUES ('{name}', '{token_hash}', true);" |
|
) |
|
print("\n.env:") |
|
print(f"AGENT_BEARER_TOKEN={token}") |
|
|
|
|
|
if __name__ == "__main__": |
|
main()
|
|
|