-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_permanent_token.py
More file actions
executable file
·51 lines (44 loc) · 1.45 KB
/
generate_permanent_token.py
File metadata and controls
executable file
·51 lines (44 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python3
"""Generate a long-lived JWT token for Kafka Connect"""
from datetime import datetime, timedelta
from jose import jwt
import os
import sys
# Configuration
SECRET_KEY = os.getenv("SECRET_KEY", "your-secret-key-here-change-in-production-min-32-chars")
ALGORITHM = "HS256"
USERNAME = "admin"
def create_permanent_token():
"""Create a token that expires in 10 years"""
expire = datetime.utcnow() + timedelta(days=3650) # 10 years
to_encode = {
"sub": USERNAME,
"exp": expire
}
token = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
print("=" * 80)
print("🔑 Long-Lived JWT Token Generated")
print("=" * 80)
print()
print(f"Username: {USERNAME}")
print(f"Expires: {expire.strftime('%Y-%m-%d %H:%M:%S UTC')} (10 years)")
print()
print("Token:")
print("-" * 80)
print(token)
print("-" * 80)
print()
print("Use this token in your Kafka Connect configuration:")
print()
print(f' "http.request.headers": "Authorization: Bearer {token}"')
print()
print("⚠️ Keep this token secure! It's valid for 10 years.")
print()
return token
if __name__ == "__main__":
token = create_permanent_token()
# Optionally save to file
if len(sys.argv) > 1 and sys.argv[1] == "--save":
with open("kafka_connect_token.txt", "w") as f:
f.write(token)
print("✓ Token saved to kafka_connect_token.txt")